All files / to-case to-no-case.ts

100% Statements 65/65
92.3% Branches 12/13
100% Functions 3/3
100% Lines 65/65

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 661x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 284x 284x 156x 284x 284x 284x 284x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 103x 103x 328x 103x 103x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 49x 49x 100x 49x 49x 1x 1x  
/**
 * Credits: @ianstormtaylor
 * @link {https://github.com/ianstormtaylor/to-no-case}
 * Test whether a string is camel-case.
 */
 
var hasSpace = /\s/;
var hasSeparator = /(_|-|\.|:)/;
var hasCamel = /([a-z][A-Z]|[A-Z][a-z])/;
 
/**
 * Remove any starting case from a `string`, like camel or snake, but keep
 * spaces and punctuation that may be important otherwise.
 *
 * @param {String} string
 * @return {String}
 */
 
function toNoCase(string) {
  if (hasSpace.test(string)) return string.toLowerCase();
  if (hasSeparator.test(string))
    return (unseparate(string) || string).toLowerCase();
  if (hasCamel.test(string)) return uncamelize(string).toLowerCase();
  return string.toLowerCase();
}
 
/**
 * Separator splitter.
 */
 
var separatorSplitter = /[\W_]+(.|$)/g;
 
/**
 * Un-separate a `string`.
 *
 * @param {String} string
 * @return {String}
 */
 
function unseparate(string) {
  return string.replace(separatorSplitter, function (m, next) {
    return next ? " " + next : "";
  });
}
 
/**
 * Camelcase splitter.
 */
 
var camelSplitter = /(.)([A-Z]+)/g;
 
/**
 * Un-camelcase a `string`.
 *
 * @param {String} string
 * @return {String}
 */
 
function uncamelize(string) {
  return string.replace(camelSplitter, function (m, previous, uppers) {
    return previous + " " + uppers.toLowerCase().split("").join(" ");
  });
}
 
export default toNoCase;