@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,324 @@
|
|
|
1
|
+
import { EOL } from 'os';
|
|
2
|
+
import { isNullish } from './common.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 function getWords(str) {
|
|
15
|
+
var _a;
|
|
16
|
+
if (isNullish(str))
|
|
17
|
+
return [];
|
|
18
|
+
// Remove non-alphanumerical characters
|
|
19
|
+
str = str.replace(/[^a-zA-Z0-9]+/g, '-');
|
|
20
|
+
str = str.replace(/^[0-9-]+/, '');
|
|
21
|
+
// Split into words
|
|
22
|
+
return (_a = str.match(/[A-Z]{2,}(?=[A-Z0-9-]|$)|[a-zA-Z][a-z]*|[0-9]+/g)) !== null && _a !== void 0 ? _a : [];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Converts a word to a given casing.
|
|
26
|
+
* @param str The word to convert.
|
|
27
|
+
* @param casing The casing to convert to.
|
|
28
|
+
* @returns The converted word.
|
|
29
|
+
* @example
|
|
30
|
+
* toCasing('fooBar', 'unchanged') // => 'fooBar'
|
|
31
|
+
* toCasing('fooBar', 'all-lower') // => 'foobar'
|
|
32
|
+
* toCasing('fooBar', 'all-upper') // => 'FOOBAR'
|
|
33
|
+
* toCasing('fooBar', 'first-upper') // => 'FooBar'
|
|
34
|
+
* toCasing('FooBar', 'first-lower') // => 'fooBar'
|
|
35
|
+
* toCasing('fooBar', 'first-upper-then-lower') // => 'Foobar'
|
|
36
|
+
* toCasing('FooBar', 'first-lower-then-upper') // => 'fOOBAR'
|
|
37
|
+
* toCasing('fooBar', 'first-upper-alternating') // => 'FoObAr'
|
|
38
|
+
* toCasing('FooBar', 'first-lower-alternating') // => 'fOoBaR'
|
|
39
|
+
*/
|
|
40
|
+
export function wordToCasing(str, casing) {
|
|
41
|
+
str !== null && str !== void 0 ? str : (str = '');
|
|
42
|
+
switch (casing) {
|
|
43
|
+
case 'unchanged':
|
|
44
|
+
return str;
|
|
45
|
+
case 'all-lower':
|
|
46
|
+
return str.toLowerCase();
|
|
47
|
+
case 'all-upper':
|
|
48
|
+
return str.toUpperCase();
|
|
49
|
+
case 'first-upper':
|
|
50
|
+
return str[0].toUpperCase() + str.slice(1);
|
|
51
|
+
case 'first-lower':
|
|
52
|
+
return str[0].toLowerCase() + str.slice(1);
|
|
53
|
+
case 'first-upper-then-lower':
|
|
54
|
+
return str[0].toUpperCase() + str.slice(1).toLowerCase();
|
|
55
|
+
case 'first-lower-then-upper':
|
|
56
|
+
return str[0].toLowerCase() + str.slice(1).toUpperCase();
|
|
57
|
+
case 'first-upper-alternating':
|
|
58
|
+
return str
|
|
59
|
+
.split('')
|
|
60
|
+
.map((c, i) => (i % 2 === 0 ? c.toUpperCase() : c.toLowerCase()))
|
|
61
|
+
.join('');
|
|
62
|
+
case 'first-lower-alternating':
|
|
63
|
+
return str
|
|
64
|
+
.split('')
|
|
65
|
+
.map((c, i) => (i % 2 === 0 ? c.toLowerCase() : c.toUpperCase()))
|
|
66
|
+
.join('');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export function toCasing(str, casing) {
|
|
70
|
+
let options;
|
|
71
|
+
let casingType;
|
|
72
|
+
if (typeof casing === 'string') {
|
|
73
|
+
casingType = casing;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
options = casing;
|
|
77
|
+
casingType = casing.casing;
|
|
78
|
+
}
|
|
79
|
+
switch (casingType) {
|
|
80
|
+
case 'camel':
|
|
81
|
+
return toCamelCase(str, options);
|
|
82
|
+
case 'pascal':
|
|
83
|
+
return toPascalCase(str, options);
|
|
84
|
+
case 'kebab':
|
|
85
|
+
return toKebabCase(str, options);
|
|
86
|
+
case 'snake':
|
|
87
|
+
return toSnakeCase(str, options);
|
|
88
|
+
case 'custom':
|
|
89
|
+
return toCustomCase(str, options);
|
|
90
|
+
default:
|
|
91
|
+
return wordToCasing(getWords(str).join(''), casingType);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function addPrefixAndSuffix(str, { prefix, suffix }) {
|
|
95
|
+
if (prefix) {
|
|
96
|
+
str = prefix + str;
|
|
97
|
+
}
|
|
98
|
+
if (suffix) {
|
|
99
|
+
str = str + suffix;
|
|
100
|
+
}
|
|
101
|
+
return str;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Converts a string to camel case.
|
|
105
|
+
* @param str The string to convert.
|
|
106
|
+
* @param options The options.
|
|
107
|
+
* @returns The converted string.
|
|
108
|
+
* @example
|
|
109
|
+
* toCamelCase('Foo bAR') // => 'fooBar'
|
|
110
|
+
* toCamelCase('Foo bAR', { keepOriginalCase: true }) // => 'fooBAR'
|
|
111
|
+
* toCamelCase('Foo bAR', { keepOriginalCase: false }) // => 'fooBar'
|
|
112
|
+
* toCamelCase('Foo bAR', { prefix: 'bar' }) // => 'barfooBar'
|
|
113
|
+
* toCamelCase('Foo bAR', { suffix: 'bar' }) // => 'fooBarbar'
|
|
114
|
+
*/
|
|
115
|
+
export function toCamelCase(str, options) {
|
|
116
|
+
const opts = Object.assign({ keepOriginalCase: false }, options);
|
|
117
|
+
const words = getWords(str);
|
|
118
|
+
const camelCase = words
|
|
119
|
+
.map((word, index) => index === 0
|
|
120
|
+
? wordToCasing(word, opts.keepOriginalCase ? 'first-lower' : 'all-lower')
|
|
121
|
+
: wordToCasing(word, opts.keepOriginalCase ? 'first-upper' : 'first-upper-then-lower'))
|
|
122
|
+
.join('');
|
|
123
|
+
return addPrefixAndSuffix(camelCase, opts);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Converts a string to pascal case.
|
|
127
|
+
* @param str The string to convert.
|
|
128
|
+
* @param options The options.
|
|
129
|
+
* @returns The converted string.
|
|
130
|
+
* @example
|
|
131
|
+
* toPascalCase('foo bAR') // => 'FooBar'
|
|
132
|
+
* toPascalCase('foo bAR', { keepOriginalCase: true }) // => 'FooBAR'
|
|
133
|
+
* toPascalCase('foo bAR', { keepOriginalCase: false }) // => 'FooBar'
|
|
134
|
+
* toPascalCase('foo bAR', { prefix: 'bar' }) // => 'barFooBar'
|
|
135
|
+
* toPascalCase('foo bAR', { suffix: 'bar' }) // => 'FooBarbar'
|
|
136
|
+
*/
|
|
137
|
+
export function toPascalCase(str, options) {
|
|
138
|
+
const opts = Object.assign({ keepOriginalCase: false }, options);
|
|
139
|
+
const words = getWords(str);
|
|
140
|
+
const pascalCase = words
|
|
141
|
+
.map((word) => wordToCasing(word, opts.keepOriginalCase ? 'first-upper' : 'first-upper-then-lower'))
|
|
142
|
+
.join('');
|
|
143
|
+
return addPrefixAndSuffix(pascalCase, opts);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Converts a string to kebab case.
|
|
147
|
+
* @param str The string to convert.
|
|
148
|
+
* @param options The options.
|
|
149
|
+
* @returns The converted string.
|
|
150
|
+
* @example
|
|
151
|
+
* toKebabCase('Foo bAR') // => 'foo-bar'
|
|
152
|
+
* toKebabCase('Foo bAR', { wordCasing: 'all-upper' }) // => 'FOO-BAR'
|
|
153
|
+
* toKebabCase('Foo bAR', { firstWordCasing: 'all-upper' }) // => 'FOO-bar'
|
|
154
|
+
* toKebabCase('Foo bAR', { casing: 'all-upper', firstWordCasing: 'all-lower' }) // => 'foo-BAR'
|
|
155
|
+
* toKebabCase('Foo bAR', { prefix: 'bar' }) // => 'barfoo-bar'
|
|
156
|
+
* toKebabCase('Foo bAR', { suffix: 'bar' }) // => 'foo-barbar'
|
|
157
|
+
*/
|
|
158
|
+
export function toKebabCase(str, options) {
|
|
159
|
+
const opts = Object.assign({ wordCasing: 'all-lower' }, options);
|
|
160
|
+
const words = getWords(str);
|
|
161
|
+
const kebabCase = words
|
|
162
|
+
.map((word, index) => { var _a; return index === 0 ? wordToCasing(word, (_a = opts.firstWordCasing) !== null && _a !== void 0 ? _a : opts.wordCasing) : wordToCasing(word, opts.wordCasing); })
|
|
163
|
+
.join('-');
|
|
164
|
+
return addPrefixAndSuffix(kebabCase, opts);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Converts a string to snake case.
|
|
168
|
+
* @param str The string to convert.
|
|
169
|
+
* @param options The options.
|
|
170
|
+
* @returns The converted string.
|
|
171
|
+
* @example
|
|
172
|
+
* toSnakeCase('Foo bAR') // => 'FOO_BAR'
|
|
173
|
+
* toSnakeCase('Foo bAR', { wordCasing: 'all-lower' }) // => 'foo_bar'
|
|
174
|
+
* toSnakeCase('Foo bAR', { firstWordCasing: 'all-lower' }) // => 'foo_BAR'
|
|
175
|
+
* toSnakeCase('Foo bAR', { casing: 'all-lower', firstWordCasing: 'all-upper' }) // => 'FOO_bar'
|
|
176
|
+
* toSnakeCase('Foo bAR', { prefix: 'bar' }) // => 'barFOO_BAR'
|
|
177
|
+
* toSnakeCase('Foo bAR', { suffix: 'bar' }) // => 'FOO_BARbar'
|
|
178
|
+
*/
|
|
179
|
+
export function toSnakeCase(str, options) {
|
|
180
|
+
const opts = Object.assign({ wordCasing: 'all-upper' }, options);
|
|
181
|
+
const words = getWords(str);
|
|
182
|
+
const snakeCase = words
|
|
183
|
+
.map((word, index) => { var _a; return index === 0 ? wordToCasing(word, (_a = opts.firstWordCasing) !== null && _a !== void 0 ? _a : opts.wordCasing) : wordToCasing(word, opts.wordCasing); })
|
|
184
|
+
.join('_');
|
|
185
|
+
return addPrefixAndSuffix(snakeCase, opts);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Converts a string to a custom case.
|
|
189
|
+
* @param str The string to convert.
|
|
190
|
+
* @param options The options.
|
|
191
|
+
* @returns The converted string.
|
|
192
|
+
* @example
|
|
193
|
+
* toCustomCase('Foo bAR', { wordCasing: 'first-upper-then-lower' }) // => 'FooBar'
|
|
194
|
+
* toCustomCase('Foo bAR', { wordCasing: 'first-upper-then-lower', wordSeparator: '~' }) // => 'Foo~Bar'
|
|
195
|
+
* toCustomCase('Foo bAR', { wordCasing: 'first-upper-then-lower', wordSeparator: '~', prefix: 'bar' }) // => 'barFoo~Bar'
|
|
196
|
+
* toCustomCase('Foo bAR', { wordCasing: 'first-upper-then-lower', wordSeparator: '~', suffix: 'bar' }) // => 'Foo~Barbar'
|
|
197
|
+
* toCustomCase('Foo bAR', { wordCasing: 'all-upper', firstWordCasing: 'all-lower' }) // => 'fooBAR'
|
|
198
|
+
* toCustomCase('Foo bAR baz', { wordCasing: (wordIndex) => (wordIndex % 2 === 0 ? 'all-upper' : 'all-lower') }) // => 'FOObarBAZ'
|
|
199
|
+
*/
|
|
200
|
+
export function toCustomCase(str, options) {
|
|
201
|
+
var _a;
|
|
202
|
+
const words = getWords(str);
|
|
203
|
+
const wordMapFn = typeof options.wordCasing === 'function'
|
|
204
|
+
? (word, index) => wordToCasing(word, options.wordCasing(index))
|
|
205
|
+
: (word, index) => {
|
|
206
|
+
var _a;
|
|
207
|
+
return index === 0
|
|
208
|
+
? wordToCasing(word, (_a = options.firstWordCasing) !== null && _a !== void 0 ? _a : options.wordCasing)
|
|
209
|
+
: wordToCasing(word, options.wordCasing);
|
|
210
|
+
};
|
|
211
|
+
const customCase = words.map(wordMapFn).join((_a = options.wordSeparator) !== null && _a !== void 0 ? _a : '');
|
|
212
|
+
return addPrefixAndSuffix(customCase, options);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Escapes a string to be used in a regular expression.
|
|
216
|
+
* @param str The string to escape.
|
|
217
|
+
*/
|
|
218
|
+
export function escapeRegExp(str) {
|
|
219
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
220
|
+
}
|
|
221
|
+
export const defaultStringBuilderOptions = {
|
|
222
|
+
newLine: EOL,
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Represents a mutable string of characters.
|
|
226
|
+
*/
|
|
227
|
+
export class StringBuilder {
|
|
228
|
+
get options() {
|
|
229
|
+
return this._options;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Initializes a new instance of the StringBuilder class.
|
|
233
|
+
* @param options The options.
|
|
234
|
+
*/
|
|
235
|
+
constructor(options) {
|
|
236
|
+
this._str = '';
|
|
237
|
+
this._options = Object.assign(Object.assign({}, defaultStringBuilderOptions), options);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Creates a new StringBuilder instance and appends the specified string to it.
|
|
241
|
+
* @param str The string to append.
|
|
242
|
+
* @param options The options.
|
|
243
|
+
* @returns A new StringBuilder instance.
|
|
244
|
+
*/
|
|
245
|
+
static fromString(str, options) {
|
|
246
|
+
const builder = new StringBuilder(options);
|
|
247
|
+
builder.append(str);
|
|
248
|
+
return builder;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Builds a string using a StringBuilder build action.
|
|
252
|
+
* @param buildAction The build action to perform on the StringBuilder instance.
|
|
253
|
+
* @param options The options for the StringBuilder instance.
|
|
254
|
+
* @returns The built string.
|
|
255
|
+
*/
|
|
256
|
+
static build(buildAction, options) {
|
|
257
|
+
const builder = new StringBuilder(options);
|
|
258
|
+
buildAction(builder);
|
|
259
|
+
return builder.toString();
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Appends one or more strings to the end of the current StringBuilder.
|
|
263
|
+
* @param value The string(s) to append.
|
|
264
|
+
* @returns The current StringBuilder.
|
|
265
|
+
*/
|
|
266
|
+
append(...value) {
|
|
267
|
+
for (const part of value) {
|
|
268
|
+
if (isNullish(part) || part.length === 0)
|
|
269
|
+
continue;
|
|
270
|
+
this._str += part;
|
|
271
|
+
}
|
|
272
|
+
return this;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Appends one or more strings to the end of the current StringBuilder, followed by a line terminator.
|
|
276
|
+
* @param value
|
|
277
|
+
* @returns
|
|
278
|
+
*/
|
|
279
|
+
appendLine(...value) {
|
|
280
|
+
return this.append(...value, this._options.newLine);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Prepends one or more strings to the beginning of the current StringBuilder.
|
|
284
|
+
* @param value The string(s) to prepend.
|
|
285
|
+
* @returns The current StringBuilder.
|
|
286
|
+
*/
|
|
287
|
+
prepend(...value) {
|
|
288
|
+
for (const part of value.reverse()) {
|
|
289
|
+
if (isNullish(part))
|
|
290
|
+
continue;
|
|
291
|
+
if (typeof part === 'function') {
|
|
292
|
+
const builder = new StringBuilder(this.options);
|
|
293
|
+
part(builder);
|
|
294
|
+
this._str = builder.toString() + this._str;
|
|
295
|
+
}
|
|
296
|
+
else if (part.length > 0) {
|
|
297
|
+
this._str = part + this._str;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return this;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Prepends one or more strings to the beginning of the current StringBuilder, followed by a line terminator.
|
|
304
|
+
* @param value The string(s) to prepend.
|
|
305
|
+
* @returns The current StringBuilder.
|
|
306
|
+
*/
|
|
307
|
+
prependLine(...value) {
|
|
308
|
+
return this.prepend(...value, this._options.newLine);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Converts the value of this instance to a string.
|
|
312
|
+
* @returns A string whose value is the same as this instance.
|
|
313
|
+
*/
|
|
314
|
+
toString() {
|
|
315
|
+
return this._str;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Removes all characters from the current StringBuilder.
|
|
319
|
+
*/
|
|
320
|
+
clear() {
|
|
321
|
+
this._str = '';
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
//# sourceMappingURL=string.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.utils.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/utils/string.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,IAAI,CAAC;AAEzB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAe3C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAqB;;IAC5C,IAAI,SAAS,CAAC,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,iDAAiD,CAAC,mCAAI,EAAE,CAAC;AAC5E,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,YAAY,CAAC,GAAqB,EAAE,MAAkB;IACpE,GAAG,aAAH,GAAG,cAAH,GAAG,IAAH,GAAG,GAAK,EAAE,EAAC;IACX,QAAQ,MAAM,EAAE;QACd,KAAK,WAAW;YACd,OAAO,GAAG,CAAC;QACb,KAAK,WAAW;YACd,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC;QAC3B,KAAK,WAAW;YACd,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC;QAC3B,KAAK,aAAa;YAChB,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC7C,KAAK,aAAa;YAChB,OAAO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../../../../../packages/core/src/lib/utils/string.utils.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a casing for a word.
|
|
3
|
+
* @example
|
|
4
|
+
* toCasing('fooBar', 'unchanged') // => 'fooBar'
|
|
5
|
+
* toCasing('fooBar', 'all-lower') // => 'foobar'
|
|
6
|
+
* toCasing('fooBar', 'all-upper') // => 'FOOBAR'
|
|
7
|
+
* toCasing('fooBar', 'first-upper') // => 'FooBar'
|
|
8
|
+
* toCasing('FooBar', 'first-lower') // => 'fooBar'
|
|
9
|
+
* toCasing('fooBar', 'first-upper-then-lower') // => 'Foobar'
|
|
10
|
+
* toCasing('FooBar', 'first-lower-then-upper') // => 'fOOBAR'
|
|
11
|
+
* toCasing('fooBar', 'first-upper-alternating') // => 'FoObAr'
|
|
12
|
+
* toCasing('FooBar', 'first-lower-alternating') // => 'fOoBaR'
|
|
13
|
+
*/
|
|
14
|
+
export type WordCasing = 'unchanged' | 'all-lower' | 'all-upper' | 'first-upper' | 'first-lower' | 'first-upper-then-lower' | 'first-lower-then-upper' | 'first-upper-alternating' | 'first-lower-alternating';
|
|
15
|
+
/**
|
|
16
|
+
* Represents a casing for a string.
|
|
17
|
+
* @example
|
|
18
|
+
* toCase('fooBar', 'unchanged') // => 'fooBar'
|
|
19
|
+
* toCase('fooBar', 'all-lower') // => 'foobar'
|
|
20
|
+
* toCase('fooBar', 'all-upper') // => 'FOOBAR'
|
|
21
|
+
* toCase('fooBar', 'first-upper') // => 'FooBar'
|
|
22
|
+
* toCase('FooBar', 'first-lower') // => 'fooBar'
|
|
23
|
+
* toCase('fooBar', 'first-upper-then-lower') // => 'Foobar'
|
|
24
|
+
* toCase('FooBar', 'first-lower-then-upper') // => 'fOOBAR'
|
|
25
|
+
* toCase('fooBar', 'first-upper-alternating') // => 'FoObAr'
|
|
26
|
+
* toCase('FooBar', 'first-lower-alternating') // => 'fOoBaR'
|
|
27
|
+
* toCase('fooBar', 'camel') // => 'fooBar'
|
|
28
|
+
* toCase('fooBar', 'pascal') // => 'FooBar'
|
|
29
|
+
* toCase('fooBar', 'kebab') // => 'foo-bar'
|
|
30
|
+
* toCase('fooBar', 'snake') // => 'foo_bar'
|
|
31
|
+
*/
|
|
32
|
+
export type StringCasing = WordCasing | 'camel' | 'pascal' | 'kebab' | 'snake' | 'custom';
|
|
33
|
+
export type StringCasingWithOptions<T extends StringCasing = StringCasing> = {
|
|
34
|
+
casing: T;
|
|
35
|
+
} & CaseOptions<T>;
|
|
36
|
+
export type CaseOptions<T extends StringCasing> = T extends 'camel' ? Partial<CamelCaseOptions> : T extends 'pascal' ? Partial<PascalCaseOptions> : T extends 'kebab' ? Partial<KebabCaseOptions> : T extends 'snake' ? Partial<SnakeCaseOptions> : T extends 'custom' ? CustomCaseOptions : never;
|
|
37
|
+
export type BaseCaseOptions = {
|
|
38
|
+
/**
|
|
39
|
+
* Specifies a prefix to add to the string.
|
|
40
|
+
* @default undefined
|
|
41
|
+
* @example
|
|
42
|
+
* toCase('foo', { prefix: 'bar' }) // => 'barfoo'
|
|
43
|
+
*/
|
|
44
|
+
prefix?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Specifies a suffix to add to the string.
|
|
47
|
+
* @default undefined
|
|
48
|
+
* @example
|
|
49
|
+
* toCase('foo', { suffix: 'bar' }) // => 'foobar'
|
|
50
|
+
*/
|
|
51
|
+
suffix?: string;
|
|
52
|
+
};
|
|
53
|
+
export type CamelCaseOptions = BaseCaseOptions & {
|
|
54
|
+
/**
|
|
55
|
+
* Controls the casing of all characters except the first one for each word.
|
|
56
|
+
*
|
|
57
|
+
* If true, all characters except the first one will remain unchanged; otherwise, all characters except the first one will be converted to lowercase.
|
|
58
|
+
*
|
|
59
|
+
* @default false
|
|
60
|
+
* @example
|
|
61
|
+
* toCamelCase('fooBAR') // => 'fooBar'
|
|
62
|
+
* toCamelCase('fooBAR', { keepOriginalCase: false }) // => 'fooBar'
|
|
63
|
+
* toCamelCase('fooBAR', { keepOriginalCase: true }) // => 'fooBAR'
|
|
64
|
+
*/
|
|
65
|
+
keepOriginalCase: boolean;
|
|
66
|
+
};
|
|
67
|
+
export type PascalCaseOptions = BaseCaseOptions & {
|
|
68
|
+
/**
|
|
69
|
+
* Controls the casing of all characters except the first one for each word.
|
|
70
|
+
*
|
|
71
|
+
* If true, all characters except the first one will remain unchanged; otherwise, all characters except the first one will be converted to lowercase.
|
|
72
|
+
*
|
|
73
|
+
* @default false
|
|
74
|
+
* @example
|
|
75
|
+
* toCamelCase('FooBAR') // => 'FooBar'
|
|
76
|
+
* toCamelCase('FooBAR', { keepOriginalCase: false }) // => 'FooBar'
|
|
77
|
+
* toCamelCase('FooBAR', { keepOriginalCase: true }) // => 'FooBAR'
|
|
78
|
+
*/
|
|
79
|
+
keepOriginalCase: boolean;
|
|
80
|
+
};
|
|
81
|
+
export type KebabCaseOptions = BaseCaseOptions & {
|
|
82
|
+
/**
|
|
83
|
+
* Specifies the casing of words.
|
|
84
|
+
* @default 'all-lower'
|
|
85
|
+
* @example
|
|
86
|
+
* toKebabCase('Foo bAR') // => 'foo-bar'
|
|
87
|
+
* toKebabCase('Foo bAR', { wordCasing: 'all-upper' }) // => 'FOO-BAR'
|
|
88
|
+
*/
|
|
89
|
+
wordCasing: WordCasing;
|
|
90
|
+
/**
|
|
91
|
+
* Specifies the casing of the first word. If undefined uses the casing option.
|
|
92
|
+
* @default undefined
|
|
93
|
+
* @example
|
|
94
|
+
* toKebabCase('Foo bAR') // => 'foo-bar'
|
|
95
|
+
* toKebabCase('Foo bAR', { firstWordCasing: 'all-upper' }) // => 'FOO-bar'
|
|
96
|
+
* toKebabCase('Foo bAR', { wordCasing: 'all-upper', firstWordCasing: 'all-lower' }) // => 'foo-BAR'
|
|
97
|
+
*/
|
|
98
|
+
firstWordCasing?: WordCasing;
|
|
99
|
+
};
|
|
100
|
+
export type SnakeCaseOptions = BaseCaseOptions & {
|
|
101
|
+
/**
|
|
102
|
+
* Specifies the casing of words.
|
|
103
|
+
* @default 'all-upper'
|
|
104
|
+
* @example
|
|
105
|
+
* toSnakeCase('Foo bAR') // => 'FOO_BAR'
|
|
106
|
+
* toSnakeCase('Foo bAR', { wordCasing: 'all-lower' }) // => 'foo_bar'
|
|
107
|
+
*/
|
|
108
|
+
wordCasing: WordCasing;
|
|
109
|
+
/**
|
|
110
|
+
* Specifies the casing of the first word. If undefined uses the casing option.
|
|
111
|
+
* @default undefined
|
|
112
|
+
* @example
|
|
113
|
+
* toSnakeCase('Foo bAR') // => 'FOO_BAR'
|
|
114
|
+
* toSnakeCase('Foo bAR', { firstWordCasing: 'all-lower' }) // => 'foo_BAR'
|
|
115
|
+
* toSnakeCase('Foo bAR', { wordCasing: 'all-lower', firstWordCasing: 'all-upper' }) // => 'FOO_bar'
|
|
116
|
+
*/
|
|
117
|
+
firstWordCasing?: WordCasing;
|
|
118
|
+
};
|
|
119
|
+
export type CustomCaseOptions = BaseCaseOptions & {
|
|
120
|
+
/**
|
|
121
|
+
* Specifies the separator between words.
|
|
122
|
+
* @default undefined
|
|
123
|
+
* @example
|
|
124
|
+
* toCustomCase('Foo bAR', { wordCasing: 'first-upper-then-lower', wordSeparator: '~' }) // => 'Foo~Bar'
|
|
125
|
+
*/
|
|
126
|
+
wordSeparator?: string;
|
|
127
|
+
} & ({
|
|
128
|
+
/**
|
|
129
|
+
* Specifies the casing of words.
|
|
130
|
+
* @example
|
|
131
|
+
* toCustomCase('Foo bAR', { wordCasing: 'first-upper-then-lower' }) // => 'FooBar'
|
|
132
|
+
*/
|
|
133
|
+
wordCasing: WordCasing;
|
|
134
|
+
/**
|
|
135
|
+
* Specifies the casing of the first word. If undefined uses the casing option.
|
|
136
|
+
* @default undefined
|
|
137
|
+
* @example
|
|
138
|
+
* toCustomCase('Foo bAR', { wordCasing: 'first-upper-then-lower', firstWordCasing: 'all-upper' }) // => 'FOOBar'
|
|
139
|
+
*/
|
|
140
|
+
firstWordCasing?: WordCasing;
|
|
141
|
+
} | {
|
|
142
|
+
/**
|
|
143
|
+
* Specifies the casing of words.
|
|
144
|
+
* @example
|
|
145
|
+
* toCustomCase('Foo bAR baz', { wordCasing: (wordIndex) => (wordIndex % 2 === 0 ? 'all-upper' : 'all-lower') }) // => 'FOObarBAZ'
|
|
146
|
+
*/
|
|
147
|
+
wordCasing: (wordIndex: number) => WordCasing;
|
|
148
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.utils.types.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/utils/string.utils.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.utils.cjs","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/utils/type.utils.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type MergeTwo<T, U> = {
|
|
2
|
+
[P in Exclude<keyof T, keyof U>]: T[P];
|
|
3
|
+
} & U;
|
|
4
|
+
export type Merge<U extends unknown[]> = U extends [infer A, ...infer R] ? MergeTwo<A, Merge<R>> : {};
|
|
5
|
+
export type OptionalProperties<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
6
|
+
export type ArrayItem<T> = T extends (infer U)[] ? U : never;
|
|
7
|
+
export type Nullable<T> = T | null | undefined;
|
|
8
|
+
export interface Constructor<T, TArgs extends any[]> extends Function {
|
|
9
|
+
new (...args: TArgs): T;
|
|
10
|
+
}
|
|
11
|
+
export type EmptyConstructor<T> = Constructor<T, []>;
|
|
12
|
+
export type FunctionNames<T> = {
|
|
13
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
|
|
14
|
+
}[keyof T];
|
|
15
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.utils.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/utils/type.utils.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@goast/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"fs-extra": "^11.1.1",
|
|
7
|
+
"node-fetch": "^2.6.11",
|
|
8
|
+
"yaml": "^2.3.1",
|
|
9
|
+
"tslib": "^2.3.0"
|
|
10
|
+
},
|
|
11
|
+
"module": "./dist/index.js",
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"require": "./dist/index.cjs",
|
|
18
|
+
"types": "./dist/index.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./utils": {
|
|
21
|
+
"import": "./dist/lib/utils/index.js",
|
|
22
|
+
"require": "./dist/lib/utils/index.cjs",
|
|
23
|
+
"types": "./dist/lib/utils/index.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
}
|
|
27
|
+
}
|