1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | function camelCase(str, firstCapital) {
|
9 | if (firstCapital === void 0) { firstCapital = false; }
|
10 | return str.replace(/^([A-Z])|[\s-_](\w)/g, function (match, p1, p2, offset) {
|
11 | if (firstCapital === true && offset === 0)
|
12 | return p1;
|
13 | if (p2)
|
14 | return p2.toUpperCase();
|
15 | return p1.toLowerCase();
|
16 | });
|
17 | }
|
18 | exports.camelCase = camelCase;
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | function snakeCase(str) {
|
25 | return str.replace(/(?:([a-z])([A-Z]))|(?:((?!^)[A-Z])([a-z]))/g, "$1_$3$2$4").toLowerCase();
|
26 | }
|
27 | exports.snakeCase = snakeCase;
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | function titleCase(str) {
|
34 | return str.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
|
35 | }
|
36 | exports.titleCase = titleCase;
|
37 |
|
38 |
|
39 |
|
40 | function abbreviate(str, abbrLettersCount) {
|
41 | if (abbrLettersCount === void 0) { abbrLettersCount = 1; }
|
42 | var words = str.replace(/([a-z\xE0-\xFF])([A-Z\xC0\xDF])/g, "$1 $2").split(" ");
|
43 | return words.reduce(function (res, word) {
|
44 | res += word.substr(0, abbrLettersCount);
|
45 | return res;
|
46 | }, "");
|
47 | }
|
48 | exports.abbreviate = abbreviate;
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | function shorten(input, options) {
|
72 | if (options === void 0) { options = {}; }
|
73 | var _a = options.segmentLength, segmentLength = _a === void 0 ? 4 : _a, _b = options.separator, separator = _b === void 0 ? "__" : _b, _c = options.termLength, termLength = _c === void 0 ? 2 : _c;
|
74 | var segments = input.split(separator);
|
75 | var shortSegments = segments.reduce(function (acc, val) {
|
76 |
|
77 | var segmentTerms = val.replace(/([a-z\xE0-\xFF])([A-Z\xC0-\xDF])/g, "$1 $2").split(" ");
|
78 |
|
79 | var length = segmentTerms.length > 1 ? termLength : segmentLength;
|
80 | var shortSegment = segmentTerms.map(function (term) { return term.substr(0, length); }).join("");
|
81 | acc.push(shortSegment);
|
82 | return acc;
|
83 | }, []);
|
84 | return shortSegments.join(separator);
|
85 | }
|
86 | exports.shorten = shorten;
|
87 |
|
88 |
|