[79a0317] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | exports.noCase = void 0;
|
---|
| 4 | var lower_case_1 = require("lower-case");
|
---|
| 5 | // Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
|
---|
| 6 | var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
|
---|
| 7 | // Remove all non-word characters.
|
---|
| 8 | var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
|
---|
| 9 | /**
|
---|
| 10 | * Normalize the string into something other libraries can manipulate easier.
|
---|
| 11 | */
|
---|
| 12 | function noCase(input, options) {
|
---|
| 13 | if (options === void 0) { options = {}; }
|
---|
| 14 | var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lower_case_1.lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? " " : _d;
|
---|
| 15 | var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
|
---|
| 16 | var start = 0;
|
---|
| 17 | var end = result.length;
|
---|
| 18 | // Trim the delimiter from around the output string.
|
---|
| 19 | while (result.charAt(start) === "\0")
|
---|
| 20 | start++;
|
---|
| 21 | while (result.charAt(end - 1) === "\0")
|
---|
| 22 | end--;
|
---|
| 23 | // Transform each token independently.
|
---|
| 24 | return result.slice(start, end).split("\0").map(transform).join(delimiter);
|
---|
| 25 | }
|
---|
| 26 | exports.noCase = noCase;
|
---|
| 27 | /**
|
---|
| 28 | * Replace `re` in the input string with the replacement value.
|
---|
| 29 | */
|
---|
| 30 | function replace(input, re, value) {
|
---|
| 31 | if (re instanceof RegExp)
|
---|
| 32 | return input.replace(re, value);
|
---|
| 33 | return re.reduce(function (input, re) { return input.replace(re, value); }, input);
|
---|
| 34 | }
|
---|
| 35 | //# sourceMappingURL=index.js.map |
---|