1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.toCamelCase = exports.toUpperFirst = exports.splitWords = exports.freeText = void 0;
|
4 |
|
5 | const freeText = (text, skipIndentation = false) => {
|
6 | if (text instanceof Array) {
|
7 | text = text.join('');
|
8 | }
|
9 |
|
10 |
|
11 | text = text.replace(/( *)==>((?:.|\n)*?)<==/g, (_match, baseIndent, content) => {
|
12 | return content
|
13 | .split('\n')
|
14 | .map(line => `${baseIndent}${line}`)
|
15 | .join('\n');
|
16 | });
|
17 | if (skipIndentation) {
|
18 | if (text.trim() === '') {
|
19 | return '';
|
20 | }
|
21 | return text;
|
22 | }
|
23 | const lines = text.split('\n');
|
24 | const minIndent = lines
|
25 | .filter(line => line.trim())
|
26 | .reduce((minIndent, line) => {
|
27 | var _a;
|
28 | const currIndent = (_a = line.match(/^ */)) === null || _a === void 0 ? void 0 : _a[0].length;
|
29 | if (currIndent == null) {
|
30 | return minIndent;
|
31 | }
|
32 | return currIndent < minIndent ? currIndent : minIndent;
|
33 | }, Infinity);
|
34 | return lines
|
35 | .map(line => line.slice(minIndent))
|
36 | .join('\n')
|
37 | .trim()
|
38 | .replace(/\n +\n/g, '\n\n');
|
39 | };
|
40 | exports.freeText = freeText;
|
41 |
|
42 | const splitWords = (str) => {
|
43 | return str.replace(/[A-Z]/, ' $&').split(/[^a-zA-Z0-9]+/);
|
44 | };
|
45 | exports.splitWords = splitWords;
|
46 |
|
47 | const toUpperFirst = (str) => {
|
48 | return str.slice(0, 1).toUpperCase() + str.slice(1).toLowerCase();
|
49 | };
|
50 | exports.toUpperFirst = toUpperFirst;
|
51 |
|
52 | const toCamelCase = (str) => {
|
53 | var _a, _b;
|
54 | const words = (0, exports.splitWords)(str);
|
55 | const first = (_b = (_a = words.shift()) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : '';
|
56 | const rest = words.map(exports.toUpperFirst);
|
57 | return [first, ...rest].join('');
|
58 | };
|
59 | exports.toCamelCase = toCamelCase;
|