@goast/core 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/index.cjs +7 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/codegen/config.cjs +6 -0
- package/dist/lib/codegen/config.cjs.map +1 -0
- package/dist/lib/codegen/config.d.ts +6 -0
- package/dist/lib/codegen/config.js +3 -0
- package/dist/lib/codegen/config.js.map +1 -0
- package/dist/lib/codegen/endpoints-generator.cjs +31 -0
- package/dist/lib/codegen/endpoints-generator.cjs.map +1 -0
- package/dist/lib/codegen/endpoints-generator.d.ts +15 -0
- package/dist/lib/codegen/endpoints-generator.js +27 -0
- package/dist/lib/codegen/endpoints-generator.js.map +1 -0
- package/dist/lib/codegen/generator.cjs +103 -0
- package/dist/lib/codegen/generator.cjs.map +1 -0
- package/dist/lib/codegen/generator.d.ts +36 -0
- package/dist/lib/codegen/generator.js +98 -0
- package/dist/lib/codegen/generator.js.map +1 -0
- package/dist/lib/codegen/index.cjs +10 -0
- package/dist/lib/codegen/index.cjs.map +1 -0
- package/dist/lib/codegen/index.d.ts +6 -0
- package/dist/lib/codegen/index.js +7 -0
- package/dist/lib/codegen/index.js.map +1 -0
- package/dist/lib/codegen/internal-utils.cjs +10 -0
- package/dist/lib/codegen/internal-utils.cjs.map +1 -0
- package/dist/lib/codegen/internal-utils.d.ts +1 -0
- package/dist/lib/codegen/internal-utils.js +6 -0
- package/dist/lib/codegen/internal-utils.js.map +1 -0
- package/dist/lib/codegen/schemas-generator.cjs +43 -0
- package/dist/lib/codegen/schemas-generator.cjs.map +1 -0
- package/dist/lib/codegen/schemas-generator.d.ts +16 -0
- package/dist/lib/codegen/schemas-generator.js +39 -0
- package/dist/lib/codegen/schemas-generator.js.map +1 -0
- package/dist/lib/codegen/services-generator.cjs +31 -0
- package/dist/lib/codegen/services-generator.cjs.map +1 -0
- package/dist/lib/codegen/services-generator.d.ts +15 -0
- package/dist/lib/codegen/services-generator.js +27 -0
- package/dist/lib/codegen/services-generator.js.map +1 -0
- package/dist/lib/codegen/types.cjs +3 -0
- package/dist/lib/codegen/types.cjs.map +1 -0
- package/dist/lib/codegen/types.d.ts +17 -0
- package/dist/lib/codegen/types.js +2 -0
- package/dist/lib/codegen/types.js.map +1 -0
- package/dist/lib/collect/collector.cjs +116 -0
- package/dist/lib/collect/collector.cjs.map +1 -0
- package/dist/lib/collect/collector.d.ts +3 -0
- package/dist/lib/collect/collector.js +112 -0
- package/dist/lib/collect/collector.js.map +1 -0
- package/dist/lib/collect/helpers.cjs +33 -0
- package/dist/lib/collect/helpers.cjs.map +1 -0
- package/dist/lib/collect/helpers.d.ts +3 -0
- package/dist/lib/collect/helpers.js +28 -0
- package/dist/lib/collect/helpers.js.map +1 -0
- package/dist/lib/collect/index.cjs +7 -0
- package/dist/lib/collect/index.cjs.map +1 -0
- package/dist/lib/collect/index.d.ts +3 -0
- package/dist/lib/collect/index.js +4 -0
- package/dist/lib/collect/index.js.map +1 -0
- package/dist/lib/collect/types.cjs +3 -0
- package/dist/lib/collect/types.cjs.map +1 -0
- package/dist/lib/collect/types.d.ts +12 -0
- package/dist/lib/collect/types.js +2 -0
- package/dist/lib/collect/types.js.map +1 -0
- package/dist/lib/internal-utils.cjs +8 -0
- package/dist/lib/internal-utils.cjs.map +1 -0
- package/dist/lib/internal-utils.d.ts +1 -0
- package/dist/lib/internal-utils.js +4 -0
- package/dist/lib/internal-utils.js.map +1 -0
- package/dist/lib/parse/deref-proxy.cjs +46 -0
- package/dist/lib/parse/deref-proxy.cjs.map +1 -0
- package/dist/lib/parse/deref-proxy.d.ts +3 -0
- package/dist/lib/parse/deref-proxy.js +42 -0
- package/dist/lib/parse/deref-proxy.js.map +1 -0
- package/dist/lib/parse/index.cjs +7 -0
- package/dist/lib/parse/index.cjs.map +1 -0
- package/dist/lib/parse/index.d.ts +3 -0
- package/dist/lib/parse/index.js +4 -0
- package/dist/lib/parse/index.js.map +1 -0
- package/dist/lib/parse/openapi-types.cjs +3 -0
- package/dist/lib/parse/openapi-types.cjs.map +1 -0
- package/dist/lib/parse/openapi-types.d.ts +897 -0
- package/dist/lib/parse/openapi-types.js +2 -0
- package/dist/lib/parse/openapi-types.js.map +1 -0
- package/dist/lib/parse/parser.cjs +189 -0
- package/dist/lib/parse/parser.cjs.map +1 -0
- package/dist/lib/parse/parser.d.ts +16 -0
- package/dist/lib/parse/parser.js +185 -0
- package/dist/lib/parse/parser.js.map +1 -0
- package/dist/lib/parse/types.cjs +3 -0
- package/dist/lib/parse/types.cjs.map +1 -0
- package/dist/lib/parse/types.d.ts +15 -0
- package/dist/lib/parse/types.js +2 -0
- package/dist/lib/parse/types.js.map +1 -0
- package/dist/lib/transform/api-types.cjs +3 -0
- package/dist/lib/transform/api-types.cjs.map +1 -0
- package/dist/lib/transform/api-types.d.ts +186 -0
- package/dist/lib/transform/api-types.js +2 -0
- package/dist/lib/transform/api-types.js.map +1 -0
- package/dist/lib/transform/helpers.cjs +121 -0
- package/dist/lib/transform/helpers.cjs.map +1 -0
- package/dist/lib/transform/helpers.d.ts +50 -0
- package/dist/lib/transform/helpers.js +108 -0
- package/dist/lib/transform/helpers.js.map +1 -0
- package/dist/lib/transform/index.cjs +6 -0
- package/dist/lib/transform/index.cjs.map +1 -0
- package/dist/lib/transform/index.d.ts +2 -0
- package/dist/lib/transform/index.js +3 -0
- package/dist/lib/transform/index.js.map +1 -0
- package/dist/lib/transform/transform-document.cjs +33 -0
- package/dist/lib/transform/transform-document.cjs.map +1 -0
- package/dist/lib/transform/transform-document.d.ts +3 -0
- package/dist/lib/transform/transform-document.js +29 -0
- package/dist/lib/transform/transform-document.js.map +1 -0
- package/dist/lib/transform/transform-endpoint.cjs +254 -0
- package/dist/lib/transform/transform-endpoint.cjs.map +1 -0
- package/dist/lib/transform/transform-endpoint.d.ts +4 -0
- package/dist/lib/transform/transform-endpoint.js +250 -0
- package/dist/lib/transform/transform-endpoint.js.map +1 -0
- package/dist/lib/transform/transform-schema.cjs +142 -0
- package/dist/lib/transform/transform-schema.cjs.map +1 -0
- package/dist/lib/transform/transform-schema.d.ts +4 -0
- package/dist/lib/transform/transform-schema.js +138 -0
- package/dist/lib/transform/transform-schema.js.map +1 -0
- package/dist/lib/transform/transformer.cjs +44 -0
- package/dist/lib/transform/transformer.cjs.map +1 -0
- package/dist/lib/transform/transformer.d.ts +3 -0
- package/dist/lib/transform/transformer.js +40 -0
- package/dist/lib/transform/transformer.js.map +1 -0
- package/dist/lib/transform/types.cjs +3 -0
- package/dist/lib/transform/types.cjs.map +1 -0
- package/dist/lib/transform/types.d.ts +23 -0
- package/dist/lib/transform/types.js +2 -0
- package/dist/lib/transform/types.js.map +1 -0
- package/dist/lib/utils/action-provider.cjs +35 -0
- package/dist/lib/utils/action-provider.cjs.map +1 -0
- package/dist/lib/utils/action-provider.d.ts +28 -0
- package/dist/lib/utils/action-provider.js +31 -0
- package/dist/lib/utils/action-provider.js.map +1 -0
- package/dist/lib/utils/common.utils.cjs +12 -0
- package/dist/lib/utils/common.utils.cjs.map +1 -0
- package/dist/lib/utils/common.utils.d.ts +3 -0
- package/dist/lib/utils/common.utils.js +7 -0
- package/dist/lib/utils/common.utils.js.map +1 -0
- package/dist/lib/utils/condition.cjs +9 -0
- package/dist/lib/utils/condition.cjs.map +1 -0
- package/dist/lib/utils/condition.d.ts +3 -0
- package/dist/lib/utils/condition.js +5 -0
- package/dist/lib/utils/condition.js.map +1 -0
- package/dist/lib/utils/endpoint.utils.cjs +13 -0
- package/dist/lib/utils/endpoint.utils.cjs.map +1 -0
- package/dist/lib/utils/endpoint.utils.d.ts +2 -0
- package/dist/lib/utils/endpoint.utils.js +9 -0
- package/dist/lib/utils/endpoint.utils.js.map +1 -0
- package/dist/lib/utils/factory.cjs +29 -0
- package/dist/lib/utils/factory.cjs.map +1 -0
- package/dist/lib/utils/factory.d.ts +20 -0
- package/dist/lib/utils/factory.js +25 -0
- package/dist/lib/utils/factory.js.map +1 -0
- package/dist/lib/utils/generator.utils.cjs +11 -0
- package/dist/lib/utils/generator.utils.cjs.map +1 -0
- package/dist/lib/utils/generator.utils.d.ts +1 -0
- package/dist/lib/utils/generator.utils.js +7 -0
- package/dist/lib/utils/generator.utils.js.map +1 -0
- package/dist/lib/utils/index.cjs +14 -0
- package/dist/lib/utils/index.cjs.map +1 -0
- package/dist/lib/utils/index.d.ts +10 -0
- package/dist/lib/utils/index.js +11 -0
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/lib/utils/object.utils.cjs +21 -0
- package/dist/lib/utils/object.utils.cjs.map +1 -0
- package/dist/lib/utils/object.utils.d.ts +1 -0
- package/dist/lib/utils/object.utils.js +17 -0
- package/dist/lib/utils/object.utils.js.map +1 -0
- package/dist/lib/utils/schema.utils.cjs +55 -0
- package/dist/lib/utils/schema.utils.cjs.map +1 -0
- package/dist/lib/utils/schema.utils.d.ts +10 -0
- package/dist/lib/utils/schema.utils.js +50 -0
- package/dist/lib/utils/schema.utils.js.map +1 -0
- package/dist/lib/utils/source-builder.cjs +378 -0
- package/dist/lib/utils/source-builder.cjs.map +1 -0
- package/dist/lib/utils/source-builder.d.ts +216 -0
- package/dist/lib/utils/source-builder.js +374 -0
- package/dist/lib/utils/source-builder.js.map +1 -0
- package/dist/lib/utils/string.utils.cjs +337 -0
- package/dist/lib/utils/string.utils.cjs.map +1 -0
- package/dist/lib/utils/string.utils.d.ts +173 -0
- package/dist/lib/utils/string.utils.js +324 -0
- package/dist/lib/utils/string.utils.js.map +1 -0
- package/dist/lib/utils/string.utils.types.cjs +3 -0
- package/dist/lib/utils/string.utils.types.cjs.map +1 -0
- package/dist/lib/utils/string.utils.types.d.ts +148 -0
- package/dist/lib/utils/string.utils.types.js +2 -0
- package/dist/lib/utils/string.utils.types.js.map +1 -0
- package/dist/lib/utils/type.utils.cjs +3 -0
- package/dist/lib/utils/type.utils.cjs.map +1 -0
- package/dist/lib/utils/type.utils.d.ts +15 -0
- package/dist/lib/utils/type.utils.js +2 -0
- package/dist/lib/utils/type.utils.js.map +1 -0
- package/package.json +27 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StringBuilder = exports.defaultStringBuilderOptions = exports.escapeRegExp = exports.toCustomCase = exports.toSnakeCase = exports.toKebabCase = exports.toPascalCase = exports.toCamelCase = exports.toCasing = exports.wordToCasing = exports.getWords = void 0;
|
|
4
|
+
const os_1 = require("os");
|
|
5
|
+
const common_utils_1 = require("./common.utils");
|
|
6
|
+
/**
|
|
7
|
+
* Gets the words from a string. Words are separated by capital letters. Leading numbers are removed. Non-alphanumerical characters are removed and interpreted as word seperators. Multiple uppercase letters are interpreted as one word.
|
|
8
|
+
* @param str The string to get the words from.
|
|
9
|
+
* @returns The words.
|
|
10
|
+
* @example
|
|
11
|
+
* getWords('fooBar') // => ['foo', 'Bar']
|
|
12
|
+
* getWords('fooBarBaz') // => ['foo', 'Bar', 'Baz']
|
|
13
|
+
* getWords('fooBarBaz123') // => ['foo', 'Bar', 'Baz', '123']
|
|
14
|
+
* getWords('123Foo###Bar###') // => ['Foo', 'Bar']
|
|
15
|
+
* getWords('fooBARBaz') // => ['foo', 'BAR', 'Baz']
|
|
16
|
+
*/
|
|
17
|
+
function getWords(str) {
|
|
18
|
+
var _a;
|
|
19
|
+
if ((0, common_utils_1.isNullish)(str))
|
|
20
|
+
return [];
|
|
21
|
+
// Remove non-alphanumerical characters
|
|
22
|
+
str = str.replace(/[^a-zA-Z0-9]+/g, '-');
|
|
23
|
+
str = str.replace(/^[0-9-]+/, '');
|
|
24
|
+
// Split into words
|
|
25
|
+
return (_a = str.match(/[A-Z]{2,}(?=[A-Z0-9-]|$)|[a-zA-Z][a-z]*|[0-9]+/g)) !== null && _a !== void 0 ? _a : [];
|
|
26
|
+
}
|
|
27
|
+
exports.getWords = getWords;
|
|
28
|
+
/**
|
|
29
|
+
* Converts a word to a given casing.
|
|
30
|
+
* @param str The word to convert.
|
|
31
|
+
* @param casing The casing to convert to.
|
|
32
|
+
* @returns The converted word.
|
|
33
|
+
* @example
|
|
34
|
+
* toCasing('fooBar', 'unchanged') // => 'fooBar'
|
|
35
|
+
* toCasing('fooBar', 'all-lower') // => 'foobar'
|
|
36
|
+
* toCasing('fooBar', 'all-upper') // => 'FOOBAR'
|
|
37
|
+
* toCasing('fooBar', 'first-upper') // => 'FooBar'
|
|
38
|
+
* toCasing('FooBar', 'first-lower') // => 'fooBar'
|
|
39
|
+
* toCasing('fooBar', 'first-upper-then-lower') // => 'Foobar'
|
|
40
|
+
* toCasing('FooBar', 'first-lower-then-upper') // => 'fOOBAR'
|
|
41
|
+
* toCasing('fooBar', 'first-upper-alternating') // => 'FoObAr'
|
|
42
|
+
* toCasing('FooBar', 'first-lower-alternating') // => 'fOoBaR'
|
|
43
|
+
*/
|
|
44
|
+
function wordToCasing(str, casing) {
|
|
45
|
+
str !== null && str !== void 0 ? str : (str = '');
|
|
46
|
+
switch (casing) {
|
|
47
|
+
case 'unchanged':
|
|
48
|
+
return str;
|
|
49
|
+
case 'all-lower':
|
|
50
|
+
return str.toLowerCase();
|
|
51
|
+
case 'all-upper':
|
|
52
|
+
return str.toUpperCase();
|
|
53
|
+
case 'first-upper':
|
|
54
|
+
return str[0].toUpperCase() + str.slice(1);
|
|
55
|
+
case 'first-lower':
|
|
56
|
+
return str[0].toLowerCase() + str.slice(1);
|
|
57
|
+
case 'first-upper-then-lower':
|
|
58
|
+
return str[0].toUpperCase() + str.slice(1).toLowerCase();
|
|
59
|
+
case 'first-lower-then-upper':
|
|
60
|
+
return str[0].toLowerCase() + str.slice(1).toUpperCase();
|
|
61
|
+
case 'first-upper-alternating':
|
|
62
|
+
return str
|
|
63
|
+
.split('')
|
|
64
|
+
.map((c, i) => (i % 2 === 0 ? c.toUpperCase() : c.toLowerCase()))
|
|
65
|
+
.join('');
|
|
66
|
+
case 'first-lower-alternating':
|
|
67
|
+
return str
|
|
68
|
+
.split('')
|
|
69
|
+
.map((c, i) => (i % 2 === 0 ? c.toLowerCase() : c.toUpperCase()))
|
|
70
|
+
.join('');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.wordToCasing = wordToCasing;
|
|
74
|
+
function toCasing(str, casing) {
|
|
75
|
+
let options;
|
|
76
|
+
let casingType;
|
|
77
|
+
if (typeof casing === 'string') {
|
|
78
|
+
casingType = casing;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
options = casing;
|
|
82
|
+
casingType = casing.casing;
|
|
83
|
+
}
|
|
84
|
+
switch (casingType) {
|
|
85
|
+
case 'camel':
|
|
86
|
+
return toCamelCase(str, options);
|
|
87
|
+
case 'pascal':
|
|
88
|
+
return toPascalCase(str, options);
|
|
89
|
+
case 'kebab':
|
|
90
|
+
return toKebabCase(str, options);
|
|
91
|
+
case 'snake':
|
|
92
|
+
return toSnakeCase(str, options);
|
|
93
|
+
case 'custom':
|
|
94
|
+
return toCustomCase(str, options);
|
|
95
|
+
default:
|
|
96
|
+
return wordToCasing(getWords(str).join(''), casingType);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.toCasing = toCasing;
|
|
100
|
+
function addPrefixAndSuffix(str, { prefix, suffix }) {
|
|
101
|
+
if (prefix) {
|
|
102
|
+
str = prefix + str;
|
|
103
|
+
}
|
|
104
|
+
if (suffix) {
|
|
105
|
+
str = str + suffix;
|
|
106
|
+
}
|
|
107
|
+
return str;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Converts a string to camel case.
|
|
111
|
+
* @param str The string to convert.
|
|
112
|
+
* @param options The options.
|
|
113
|
+
* @returns The converted string.
|
|
114
|
+
* @example
|
|
115
|
+
* toCamelCase('Foo bAR') // => 'fooBar'
|
|
116
|
+
* toCamelCase('Foo bAR', { keepOriginalCase: true }) // => 'fooBAR'
|
|
117
|
+
* toCamelCase('Foo bAR', { keepOriginalCase: false }) // => 'fooBar'
|
|
118
|
+
* toCamelCase('Foo bAR', { prefix: 'bar' }) // => 'barfooBar'
|
|
119
|
+
* toCamelCase('Foo bAR', { suffix: 'bar' }) // => 'fooBarbar'
|
|
120
|
+
*/
|
|
121
|
+
function toCamelCase(str, options) {
|
|
122
|
+
const opts = Object.assign({ keepOriginalCase: false }, options);
|
|
123
|
+
const words = getWords(str);
|
|
124
|
+
const camelCase = words
|
|
125
|
+
.map((word, index) => index === 0
|
|
126
|
+
? wordToCasing(word, opts.keepOriginalCase ? 'first-lower' : 'all-lower')
|
|
127
|
+
: wordToCasing(word, opts.keepOriginalCase ? 'first-upper' : 'first-upper-then-lower'))
|
|
128
|
+
.join('');
|
|
129
|
+
return addPrefixAndSuffix(camelCase, opts);
|
|
130
|
+
}
|
|
131
|
+
exports.toCamelCase = toCamelCase;
|
|
132
|
+
/**
|
|
133
|
+
* Converts a string to pascal case.
|
|
134
|
+
* @param str The string to convert.
|
|
135
|
+
* @param options The options.
|
|
136
|
+
* @returns The converted string.
|
|
137
|
+
* @example
|
|
138
|
+
* toPascalCase('foo bAR') // => 'FooBar'
|
|
139
|
+
* toPascalCase('foo bAR', { keepOriginalCase: true }) // => 'FooBAR'
|
|
140
|
+
* toPascalCase('foo bAR', { keepOriginalCase: false }) // => 'FooBar'
|
|
141
|
+
* toPascalCase('foo bAR', { prefix: 'bar' }) // => 'barFooBar'
|
|
142
|
+
* toPascalCase('foo bAR', { suffix: 'bar' }) // => 'FooBarbar'
|
|
143
|
+
*/
|
|
144
|
+
function toPascalCase(str, options) {
|
|
145
|
+
const opts = Object.assign({ keepOriginalCase: false }, options);
|
|
146
|
+
const words = getWords(str);
|
|
147
|
+
const pascalCase = words
|
|
148
|
+
.map((word) => wordToCasing(word, opts.keepOriginalCase ? 'first-upper' : 'first-upper-then-lower'))
|
|
149
|
+
.join('');
|
|
150
|
+
return addPrefixAndSuffix(pascalCase, opts);
|
|
151
|
+
}
|
|
152
|
+
exports.toPascalCase = toPascalCase;
|
|
153
|
+
/**
|
|
154
|
+
* Converts a string to kebab case.
|
|
155
|
+
* @param str The string to convert.
|
|
156
|
+
* @param options The options.
|
|
157
|
+
* @returns The converted string.
|
|
158
|
+
* @example
|
|
159
|
+
* toKebabCase('Foo bAR') // => 'foo-bar'
|
|
160
|
+
* toKebabCase('Foo bAR', { wordCasing: 'all-upper' }) // => 'FOO-BAR'
|
|
161
|
+
* toKebabCase('Foo bAR', { firstWordCasing: 'all-upper' }) // => 'FOO-bar'
|
|
162
|
+
* toKebabCase('Foo bAR', { casing: 'all-upper', firstWordCasing: 'all-lower' }) // => 'foo-BAR'
|
|
163
|
+
* toKebabCase('Foo bAR', { prefix: 'bar' }) // => 'barfoo-bar'
|
|
164
|
+
* toKebabCase('Foo bAR', { suffix: 'bar' }) // => 'foo-barbar'
|
|
165
|
+
*/
|
|
166
|
+
function toKebabCase(str, options) {
|
|
167
|
+
const opts = Object.assign({ wordCasing: 'all-lower' }, options);
|
|
168
|
+
const words = getWords(str);
|
|
169
|
+
const kebabCase = words
|
|
170
|
+
.map((word, index) => { var _a; return index === 0 ? wordToCasing(word, (_a = opts.firstWordCasing) !== null && _a !== void 0 ? _a : opts.wordCasing) : wordToCasing(word, opts.wordCasing); })
|
|
171
|
+
.join('-');
|
|
172
|
+
return addPrefixAndSuffix(kebabCase, opts);
|
|
173
|
+
}
|
|
174
|
+
exports.toKebabCase = toKebabCase;
|
|
175
|
+
/**
|
|
176
|
+
* Converts a string to snake case.
|
|
177
|
+
* @param str The string to convert.
|
|
178
|
+
* @param options The options.
|
|
179
|
+
* @returns The converted string.
|
|
180
|
+
* @example
|
|
181
|
+
* toSnakeCase('Foo bAR') // => 'FOO_BAR'
|
|
182
|
+
* toSnakeCase('Foo bAR', { wordCasing: 'all-lower' }) // => 'foo_bar'
|
|
183
|
+
* toSnakeCase('Foo bAR', { firstWordCasing: 'all-lower' }) // => 'foo_BAR'
|
|
184
|
+
* toSnakeCase('Foo bAR', { casing: 'all-lower', firstWordCasing: 'all-upper' }) // => 'FOO_bar'
|
|
185
|
+
* toSnakeCase('Foo bAR', { prefix: 'bar' }) // => 'barFOO_BAR'
|
|
186
|
+
* toSnakeCase('Foo bAR', { suffix: 'bar' }) // => 'FOO_BARbar'
|
|
187
|
+
*/
|
|
188
|
+
function toSnakeCase(str, options) {
|
|
189
|
+
const opts = Object.assign({ wordCasing: 'all-upper' }, options);
|
|
190
|
+
const words = getWords(str);
|
|
191
|
+
const snakeCase = words
|
|
192
|
+
.map((word, index) => { var _a; return index === 0 ? wordToCasing(word, (_a = opts.firstWordCasing) !== null && _a !== void 0 ? _a : opts.wordCasing) : wordToCasing(word, opts.wordCasing); })
|
|
193
|
+
.join('_');
|
|
194
|
+
return addPrefixAndSuffix(snakeCase, opts);
|
|
195
|
+
}
|
|
196
|
+
exports.toSnakeCase = toSnakeCase;
|
|
197
|
+
/**
|
|
198
|
+
* Converts a string to a custom case.
|
|
199
|
+
* @param str The string to convert.
|
|
200
|
+
* @param options The options.
|
|
201
|
+
* @returns The converted string.
|
|
202
|
+
* @example
|
|
203
|
+
* toCustomCase('Foo bAR', { wordCasing: 'first-upper-then-lower' }) // => 'FooBar'
|
|
204
|
+
* toCustomCase('Foo bAR', { wordCasing: 'first-upper-then-lower', wordSeparator: '~' }) // => 'Foo~Bar'
|
|
205
|
+
* toCustomCase('Foo bAR', { wordCasing: 'first-upper-then-lower', wordSeparator: '~', prefix: 'bar' }) // => 'barFoo~Bar'
|
|
206
|
+
* toCustomCase('Foo bAR', { wordCasing: 'first-upper-then-lower', wordSeparator: '~', suffix: 'bar' }) // => 'Foo~Barbar'
|
|
207
|
+
* toCustomCase('Foo bAR', { wordCasing: 'all-upper', firstWordCasing: 'all-lower' }) // => 'fooBAR'
|
|
208
|
+
* toCustomCase('Foo bAR baz', { wordCasing: (wordIndex) => (wordIndex % 2 === 0 ? 'all-upper' : 'all-lower') }) // => 'FOObarBAZ'
|
|
209
|
+
*/
|
|
210
|
+
function toCustomCase(str, options) {
|
|
211
|
+
var _a;
|
|
212
|
+
const words = getWords(str);
|
|
213
|
+
const wordMapFn = typeof options.wordCasing === 'function'
|
|
214
|
+
? (word, index) => wordToCasing(word, options.wordCasing(index))
|
|
215
|
+
: (word, index) => {
|
|
216
|
+
var _a;
|
|
217
|
+
return index === 0
|
|
218
|
+
? wordToCasing(word, (_a = options.firstWordCasing) !== null && _a !== void 0 ? _a : options.wordCasing)
|
|
219
|
+
: wordToCasing(word, options.wordCasing);
|
|
220
|
+
};
|
|
221
|
+
const customCase = words.map(wordMapFn).join((_a = options.wordSeparator) !== null && _a !== void 0 ? _a : '');
|
|
222
|
+
return addPrefixAndSuffix(customCase, options);
|
|
223
|
+
}
|
|
224
|
+
exports.toCustomCase = toCustomCase;
|
|
225
|
+
/**
|
|
226
|
+
* Escapes a string to be used in a regular expression.
|
|
227
|
+
* @param str The string to escape.
|
|
228
|
+
*/
|
|
229
|
+
function escapeRegExp(str) {
|
|
230
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
231
|
+
}
|
|
232
|
+
exports.escapeRegExp = escapeRegExp;
|
|
233
|
+
exports.defaultStringBuilderOptions = {
|
|
234
|
+
newLine: os_1.EOL,
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Represents a mutable string of characters.
|
|
238
|
+
*/
|
|
239
|
+
class StringBuilder {
|
|
240
|
+
get options() {
|
|
241
|
+
return this._options;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Initializes a new instance of the StringBuilder class.
|
|
245
|
+
* @param options The options.
|
|
246
|
+
*/
|
|
247
|
+
constructor(options) {
|
|
248
|
+
this._str = '';
|
|
249
|
+
this._options = Object.assign(Object.assign({}, exports.defaultStringBuilderOptions), options);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Creates a new StringBuilder instance and appends the specified string to it.
|
|
253
|
+
* @param str The string to append.
|
|
254
|
+
* @param options The options.
|
|
255
|
+
* @returns A new StringBuilder instance.
|
|
256
|
+
*/
|
|
257
|
+
static fromString(str, options) {
|
|
258
|
+
const builder = new StringBuilder(options);
|
|
259
|
+
builder.append(str);
|
|
260
|
+
return builder;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Builds a string using a StringBuilder build action.
|
|
264
|
+
* @param buildAction The build action to perform on the StringBuilder instance.
|
|
265
|
+
* @param options The options for the StringBuilder instance.
|
|
266
|
+
* @returns The built string.
|
|
267
|
+
*/
|
|
268
|
+
static build(buildAction, options) {
|
|
269
|
+
const builder = new StringBuilder(options);
|
|
270
|
+
buildAction(builder);
|
|
271
|
+
return builder.toString();
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Appends one or more strings to the end of the current StringBuilder.
|
|
275
|
+
* @param value The string(s) to append.
|
|
276
|
+
* @returns The current StringBuilder.
|
|
277
|
+
*/
|
|
278
|
+
append(...value) {
|
|
279
|
+
for (const part of value) {
|
|
280
|
+
if ((0, common_utils_1.isNullish)(part) || part.length === 0)
|
|
281
|
+
continue;
|
|
282
|
+
this._str += part;
|
|
283
|
+
}
|
|
284
|
+
return this;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Appends one or more strings to the end of the current StringBuilder, followed by a line terminator.
|
|
288
|
+
* @param value
|
|
289
|
+
* @returns
|
|
290
|
+
*/
|
|
291
|
+
appendLine(...value) {
|
|
292
|
+
return this.append(...value, this._options.newLine);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Prepends one or more strings to the beginning of the current StringBuilder.
|
|
296
|
+
* @param value The string(s) to prepend.
|
|
297
|
+
* @returns The current StringBuilder.
|
|
298
|
+
*/
|
|
299
|
+
prepend(...value) {
|
|
300
|
+
for (const part of value.reverse()) {
|
|
301
|
+
if ((0, common_utils_1.isNullish)(part))
|
|
302
|
+
continue;
|
|
303
|
+
if (typeof part === 'function') {
|
|
304
|
+
const builder = new StringBuilder(this.options);
|
|
305
|
+
part(builder);
|
|
306
|
+
this._str = builder.toString() + this._str;
|
|
307
|
+
}
|
|
308
|
+
else if (part.length > 0) {
|
|
309
|
+
this._str = part + this._str;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return this;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Prepends one or more strings to the beginning of the current StringBuilder, followed by a line terminator.
|
|
316
|
+
* @param value The string(s) to prepend.
|
|
317
|
+
* @returns The current StringBuilder.
|
|
318
|
+
*/
|
|
319
|
+
prependLine(...value) {
|
|
320
|
+
return this.prepend(...value, this._options.newLine);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Converts the value of this instance to a string.
|
|
324
|
+
* @returns A string whose value is the same as this instance.
|
|
325
|
+
*/
|
|
326
|
+
toString() {
|
|
327
|
+
return this._str;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Removes all characters from the current StringBuilder.
|
|
331
|
+
*/
|
|
332
|
+
clear() {
|
|
333
|
+
this._str = '';
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
exports.StringBuilder = StringBuilder;
|
|
337
|
+
//# sourceMappingURL=string.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.utils.cjs","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/utils/string.utils.ts"],"names":[],"mappings":";;;AAAA,2BAAyB;AAEzB,iDAA2C;AAe3C;;;;;;;;;;GAUG;AACH,SAAgB,QAAQ,CAAC,GAAqB;;IAC5C,IAAI,IAAA,wBAAS,EAAC,GAAG,CAAC;QAAE,OAAO,EAAE,CAAC;IAE9B,uCAAuC;IACvC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC;IACzC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAElC,mBAAmB;IACnB,OAAO,MAAA,GAAG,CAAC,KAAK,CAAC,iD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,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC;aAC5C;iBAAM,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;aAC9B;SACF;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,GAAG,KAA8D;QAClF,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;IAED;;;OAGG;IACI,QAAQ;QACb,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACI,KAAK;QACV,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;IACjB,CAAC;CACF;AAxGD,sCAwGC"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { WordCasing, StringCasing, CamelCaseOptions, PascalCaseOptions, KebabCaseOptions, SnakeCaseOptions, CustomCaseOptions, StringCasingWithOptions } from './string.utils.types';
|
|
2
|
+
import { Nullable } from './type.utils';
|
|
3
|
+
/**
|
|
4
|
+
* Gets the words from a string. Words are separated by capital letters. Leading numbers are removed. Non-alphanumerical characters are removed and interpreted as word seperators. Multiple uppercase letters are interpreted as one word.
|
|
5
|
+
* @param str The string to get the words from.
|
|
6
|
+
* @returns The words.
|
|
7
|
+
* @example
|
|
8
|
+
* getWords('fooBar') // => ['foo', 'Bar']
|
|
9
|
+
* getWords('fooBarBaz') // => ['foo', 'Bar', 'Baz']
|
|
10
|
+
* getWords('fooBarBaz123') // => ['foo', 'Bar', 'Baz', '123']
|
|
11
|
+
* getWords('123Foo###Bar###') // => ['Foo', 'Bar']
|
|
12
|
+
* getWords('fooBARBaz') // => ['foo', 'BAR', 'Baz']
|
|
13
|
+
*/
|
|
14
|
+
export declare function getWords(str: Nullable<string>): string[];
|
|
15
|
+
/**
|
|
16
|
+
* Converts a word to a given casing.
|
|
17
|
+
* @param str The word to convert.
|
|
18
|
+
* @param casing The casing to convert to.
|
|
19
|
+
* @returns The converted word.
|
|
20
|
+
* @example
|
|
21
|
+
* toCasing('fooBar', 'unchanged') // => 'fooBar'
|
|
22
|
+
* toCasing('fooBar', 'all-lower') // => 'foobar'
|
|
23
|
+
* toCasing('fooBar', 'all-upper') // => 'FOOBAR'
|
|
24
|
+
* toCasing('fooBar', 'first-upper') // => 'FooBar'
|
|
25
|
+
* toCasing('FooBar', 'first-lower') // => 'fooBar'
|
|
26
|
+
* toCasing('fooBar', 'first-upper-then-lower') // => 'Foobar'
|
|
27
|
+
* toCasing('FooBar', 'first-lower-then-upper') // => 'fOOBAR'
|
|
28
|
+
* toCasing('fooBar', 'first-upper-alternating') // => 'FoObAr'
|
|
29
|
+
* toCasing('FooBar', 'first-lower-alternating') // => 'fOoBaR'
|
|
30
|
+
*/
|
|
31
|
+
export declare function wordToCasing(str: Nullable<string>, casing: WordCasing): string;
|
|
32
|
+
export declare function toCasing<T extends StringCasing>(str: Nullable<string>, casing: T | StringCasingWithOptions<T>): string;
|
|
33
|
+
/**
|
|
34
|
+
* Converts a string to camel case.
|
|
35
|
+
* @param str The string to convert.
|
|
36
|
+
* @param options The options.
|
|
37
|
+
* @returns The converted string.
|
|
38
|
+
* @example
|
|
39
|
+
* toCamelCase('Foo bAR') // => 'fooBar'
|
|
40
|
+
* toCamelCase('Foo bAR', { keepOriginalCase: true }) // => 'fooBAR'
|
|
41
|
+
* toCamelCase('Foo bAR', { keepOriginalCase: false }) // => 'fooBar'
|
|
42
|
+
* toCamelCase('Foo bAR', { prefix: 'bar' }) // => 'barfooBar'
|
|
43
|
+
* toCamelCase('Foo bAR', { suffix: 'bar' }) // => 'fooBarbar'
|
|
44
|
+
*/
|
|
45
|
+
export declare function toCamelCase(str: Nullable<string>, options?: Partial<CamelCaseOptions>): string;
|
|
46
|
+
/**
|
|
47
|
+
* Converts a string to pascal case.
|
|
48
|
+
* @param str The string to convert.
|
|
49
|
+
* @param options The options.
|
|
50
|
+
* @returns The converted string.
|
|
51
|
+
* @example
|
|
52
|
+
* toPascalCase('foo bAR') // => 'FooBar'
|
|
53
|
+
* toPascalCase('foo bAR', { keepOriginalCase: true }) // => 'FooBAR'
|
|
54
|
+
* toPascalCase('foo bAR', { keepOriginalCase: false }) // => 'FooBar'
|
|
55
|
+
* toPascalCase('foo bAR', { prefix: 'bar' }) // => 'barFooBar'
|
|
56
|
+
* toPascalCase('foo bAR', { suffix: 'bar' }) // => 'FooBarbar'
|
|
57
|
+
*/
|
|
58
|
+
export declare function toPascalCase(str: Nullable<string>, options?: Partial<PascalCaseOptions>): string;
|
|
59
|
+
/**
|
|
60
|
+
* Converts a string to kebab case.
|
|
61
|
+
* @param str The string to convert.
|
|
62
|
+
* @param options The options.
|
|
63
|
+
* @returns The converted string.
|
|
64
|
+
* @example
|
|
65
|
+
* toKebabCase('Foo bAR') // => 'foo-bar'
|
|
66
|
+
* toKebabCase('Foo bAR', { wordCasing: 'all-upper' }) // => 'FOO-BAR'
|
|
67
|
+
* toKebabCase('Foo bAR', { firstWordCasing: 'all-upper' }) // => 'FOO-bar'
|
|
68
|
+
* toKebabCase('Foo bAR', { casing: 'all-upper', firstWordCasing: 'all-lower' }) // => 'foo-BAR'
|
|
69
|
+
* toKebabCase('Foo bAR', { prefix: 'bar' }) // => 'barfoo-bar'
|
|
70
|
+
* toKebabCase('Foo bAR', { suffix: 'bar' }) // => 'foo-barbar'
|
|
71
|
+
*/
|
|
72
|
+
export declare function toKebabCase(str: Nullable<string>, options?: Partial<KebabCaseOptions>): string;
|
|
73
|
+
/**
|
|
74
|
+
* Converts a string to snake case.
|
|
75
|
+
* @param str The string to convert.
|
|
76
|
+
* @param options The options.
|
|
77
|
+
* @returns The converted string.
|
|
78
|
+
* @example
|
|
79
|
+
* toSnakeCase('Foo bAR') // => 'FOO_BAR'
|
|
80
|
+
* toSnakeCase('Foo bAR', { wordCasing: 'all-lower' }) // => 'foo_bar'
|
|
81
|
+
* toSnakeCase('Foo bAR', { firstWordCasing: 'all-lower' }) // => 'foo_BAR'
|
|
82
|
+
* toSnakeCase('Foo bAR', { casing: 'all-lower', firstWordCasing: 'all-upper' }) // => 'FOO_bar'
|
|
83
|
+
* toSnakeCase('Foo bAR', { prefix: 'bar' }) // => 'barFOO_BAR'
|
|
84
|
+
* toSnakeCase('Foo bAR', { suffix: 'bar' }) // => 'FOO_BARbar'
|
|
85
|
+
*/
|
|
86
|
+
export declare function toSnakeCase(str: Nullable<string>, options?: Partial<SnakeCaseOptions>): string;
|
|
87
|
+
/**
|
|
88
|
+
* Converts a string to a custom case.
|
|
89
|
+
* @param str The string to convert.
|
|
90
|
+
* @param options The options.
|
|
91
|
+
* @returns The converted string.
|
|
92
|
+
* @example
|
|
93
|
+
* toCustomCase('Foo bAR', { wordCasing: 'first-upper-then-lower' }) // => 'FooBar'
|
|
94
|
+
* toCustomCase('Foo bAR', { wordCasing: 'first-upper-then-lower', wordSeparator: '~' }) // => 'Foo~Bar'
|
|
95
|
+
* toCustomCase('Foo bAR', { wordCasing: 'first-upper-then-lower', wordSeparator: '~', prefix: 'bar' }) // => 'barFoo~Bar'
|
|
96
|
+
* toCustomCase('Foo bAR', { wordCasing: 'first-upper-then-lower', wordSeparator: '~', suffix: 'bar' }) // => 'Foo~Barbar'
|
|
97
|
+
* toCustomCase('Foo bAR', { wordCasing: 'all-upper', firstWordCasing: 'all-lower' }) // => 'fooBAR'
|
|
98
|
+
* toCustomCase('Foo bAR baz', { wordCasing: (wordIndex) => (wordIndex % 2 === 0 ? 'all-upper' : 'all-lower') }) // => 'FOObarBAZ'
|
|
99
|
+
*/
|
|
100
|
+
export declare function toCustomCase(str: Nullable<string>, options: CustomCaseOptions): string;
|
|
101
|
+
/**
|
|
102
|
+
* Escapes a string to be used in a regular expression.
|
|
103
|
+
* @param str The string to escape.
|
|
104
|
+
*/
|
|
105
|
+
export declare function escapeRegExp(str: string): string;
|
|
106
|
+
/**
|
|
107
|
+
* Options for the StringBuilder class.
|
|
108
|
+
* @default newLine = os.EOL
|
|
109
|
+
*/
|
|
110
|
+
export type StringBuilderOptions = {
|
|
111
|
+
readonly newLine: string;
|
|
112
|
+
};
|
|
113
|
+
export declare const defaultStringBuilderOptions: StringBuilderOptions;
|
|
114
|
+
/**
|
|
115
|
+
* Represents a mutable string of characters.
|
|
116
|
+
*/
|
|
117
|
+
export declare class StringBuilder {
|
|
118
|
+
private readonly _options;
|
|
119
|
+
private _str;
|
|
120
|
+
get options(): StringBuilderOptions;
|
|
121
|
+
/**
|
|
122
|
+
* Initializes a new instance of the StringBuilder class.
|
|
123
|
+
* @param options The options.
|
|
124
|
+
*/
|
|
125
|
+
constructor(options?: Partial<StringBuilderOptions>);
|
|
126
|
+
/**
|
|
127
|
+
* Creates a new StringBuilder instance and appends the specified string to it.
|
|
128
|
+
* @param str The string to append.
|
|
129
|
+
* @param options The options.
|
|
130
|
+
* @returns A new StringBuilder instance.
|
|
131
|
+
*/
|
|
132
|
+
static fromString(str: string, options?: Partial<StringBuilderOptions>): StringBuilder;
|
|
133
|
+
/**
|
|
134
|
+
* Builds a string using a StringBuilder build action.
|
|
135
|
+
* @param buildAction The build action to perform on the StringBuilder instance.
|
|
136
|
+
* @param options The options for the StringBuilder instance.
|
|
137
|
+
* @returns The built string.
|
|
138
|
+
*/
|
|
139
|
+
static build(buildAction: (builder: StringBuilder) => void, options?: Partial<StringBuilderOptions>): string;
|
|
140
|
+
/**
|
|
141
|
+
* Appends one or more strings to the end of the current StringBuilder.
|
|
142
|
+
* @param value The string(s) to append.
|
|
143
|
+
* @returns The current StringBuilder.
|
|
144
|
+
*/
|
|
145
|
+
append(...value: Nullable<string>[]): this;
|
|
146
|
+
/**
|
|
147
|
+
* Appends one or more strings to the end of the current StringBuilder, followed by a line terminator.
|
|
148
|
+
* @param value
|
|
149
|
+
* @returns
|
|
150
|
+
*/
|
|
151
|
+
appendLine(...value: Nullable<string>[]): this;
|
|
152
|
+
/**
|
|
153
|
+
* Prepends one or more strings to the beginning of the current StringBuilder.
|
|
154
|
+
* @param value The string(s) to prepend.
|
|
155
|
+
* @returns The current StringBuilder.
|
|
156
|
+
*/
|
|
157
|
+
prepend(...value: Nullable<string | ((builder: StringBuilder) => void)>[]): this;
|
|
158
|
+
/**
|
|
159
|
+
* Prepends one or more strings to the beginning of the current StringBuilder, followed by a line terminator.
|
|
160
|
+
* @param value The string(s) to prepend.
|
|
161
|
+
* @returns The current StringBuilder.
|
|
162
|
+
*/
|
|
163
|
+
prependLine(...value: Nullable<string | ((builder: StringBuilder) => void)>[]): this;
|
|
164
|
+
/**
|
|
165
|
+
* Converts the value of this instance to a string.
|
|
166
|
+
* @returns A string whose value is the same as this instance.
|
|
167
|
+
*/
|
|
168
|
+
toString(): string;
|
|
169
|
+
/**
|
|
170
|
+
* Removes all characters from the current StringBuilder.
|
|
171
|
+
*/
|
|
172
|
+
clear(): void;
|
|
173
|
+
}
|