@intrig/plugin-sdk 0.0.1 → 0.0.2-2
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/dist/index.cjs +471 -0
- package/dist/index.d.ts +1 -7
- package/dist/index.js +420 -6
- package/package.json +1 -2
- package/README.md +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/lib/plugin-sdk.d.ts +0 -159
- package/dist/lib/plugin-sdk.d.ts.map +0 -1
- package/dist/lib/plugin-sdk.js +0 -10
- package/dist/lib/template/json-literal.d.ts +0 -5
- package/dist/lib/template/json-literal.d.ts.map +0 -1
- package/dist/lib/template/json-literal.js +0 -14
- package/dist/lib/template/md-literal.d.ts +0 -5
- package/dist/lib/template/md-literal.d.ts.map +0 -1
- package/dist/lib/template/md-literal.js +0 -14
- package/dist/lib/template/template-util.d.ts +0 -32
- package/dist/lib/template/template-util.d.ts.map +0 -1
- package/dist/lib/template/template-util.js +0 -192
- package/dist/lib/template/ts-literal.d.ts +0 -5
- package/dist/lib/template/ts-literal.d.ts.map +0 -1
- package/dist/lib/template/ts-literal.js +0 -19
- package/dist/lib/util/change-case.d.ts +0 -80
- package/dist/lib/util/change-case.d.ts.map +0 -1
- package/dist/lib/util/change-case.js +0 -208
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var prettier = require('prettier');
|
|
4
|
+
|
|
5
|
+
function _interopNamespaceDefault(e) {
|
|
6
|
+
var n = Object.create(null);
|
|
7
|
+
if (e) {
|
|
8
|
+
Object.keys(e).forEach(function (k) {
|
|
9
|
+
if (k !== 'default') {
|
|
10
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return e[k]; }
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
n.default = e;
|
|
19
|
+
return Object.freeze(n);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var prettier__namespace = /*#__PURE__*/_interopNamespaceDefault(prettier);
|
|
23
|
+
|
|
24
|
+
class StatsCounter {
|
|
25
|
+
constructor(sourceId){
|
|
26
|
+
this.sourceId = sourceId;
|
|
27
|
+
this.counters = {};
|
|
28
|
+
}
|
|
29
|
+
inc(key) {
|
|
30
|
+
this.counters[key] = (this.counters[key] || 0) + 1;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function jsonLiteral(path) {
|
|
35
|
+
return async (strings, ...values)=>{
|
|
36
|
+
const rawCode = strings.reduce((acc, str, i)=>acc + str + (values[i] || ''), '');
|
|
37
|
+
const content = await prettier__namespace.format(rawCode, {
|
|
38
|
+
parser: 'json',
|
|
39
|
+
singleQuote: true
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
path,
|
|
43
|
+
content
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getVariableName(ref) {
|
|
49
|
+
return ref.split('/').pop();
|
|
50
|
+
}
|
|
51
|
+
function getVariableImports(variables, source, prefix) {
|
|
52
|
+
return variables.map((a)=>getVariableName(a.ref)).map((ref)=>`import { ${ref} } from "${prefix}/${source}/components/schemas/${ref}.js"`).join("\n");
|
|
53
|
+
}
|
|
54
|
+
function getVariableTypes(variables) {
|
|
55
|
+
return variables.map((p)=>`${p.name}${p.in === "path" ? "" : "?"}: ${getVariableName(p.ref)}`).join("\n");
|
|
56
|
+
}
|
|
57
|
+
function isParamMandatory(variables) {
|
|
58
|
+
return variables.some((a)=>a.in === 'path');
|
|
59
|
+
}
|
|
60
|
+
function getParamExplodeExpression(variables) {
|
|
61
|
+
return [
|
|
62
|
+
...variables.filter((a)=>a.in === "path").map((a)=>a.name),
|
|
63
|
+
"...params"
|
|
64
|
+
].join(",");
|
|
65
|
+
}
|
|
66
|
+
function decodeVariables(_variables, source, prefix = "@root") {
|
|
67
|
+
const variables = _variables.filter((a)=>[
|
|
68
|
+
"path",
|
|
69
|
+
"query"
|
|
70
|
+
].includes(a.in));
|
|
71
|
+
return {
|
|
72
|
+
variableImports: getVariableImports(variables, source, prefix),
|
|
73
|
+
variableTypes: getVariableTypes(variables),
|
|
74
|
+
isParamMandatory: isParamMandatory(variables),
|
|
75
|
+
variableExplodeExpression: getParamExplodeExpression(variables)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function getDispatchParams(operationId, requestBody, isParamMandatory = false) {
|
|
79
|
+
return [
|
|
80
|
+
requestBody ? `data: RequestBody` : undefined,
|
|
81
|
+
`params: Params${isParamMandatory ? '' : ' | undefined'}`
|
|
82
|
+
].filter(Boolean).join(', ');
|
|
83
|
+
}
|
|
84
|
+
function getDispatchParamExpansion(requestBody, isParamMandatory) {
|
|
85
|
+
return [
|
|
86
|
+
requestBody && 'data',
|
|
87
|
+
`p${isParamMandatory ? '' : ' = {}'}`
|
|
88
|
+
].filter(Boolean).join(', ');
|
|
89
|
+
}
|
|
90
|
+
function extractParams(properties) {
|
|
91
|
+
const paramMandatory = isParamMandatory(properties.variables ?? []);
|
|
92
|
+
if (properties.response) {
|
|
93
|
+
if (properties.requestBody) {
|
|
94
|
+
if (paramMandatory) {
|
|
95
|
+
return {
|
|
96
|
+
shape: `BinaryFunctionHook<Params, RequestBody, Response, _ErrorType>`,
|
|
97
|
+
shapeImport: `BinaryFunctionHook`,
|
|
98
|
+
dispatchParamExpansion: `data, p`,
|
|
99
|
+
dispatchParams: "data: RequestBody, params: Params"
|
|
100
|
+
};
|
|
101
|
+
} else {
|
|
102
|
+
return {
|
|
103
|
+
shape: `BinaryFunctionHook<Params, RequestBody, Response, _ErrorType>`,
|
|
104
|
+
shapeImport: `BinaryFunctionHook`,
|
|
105
|
+
dispatchParamExpansion: `data, p = {}`,
|
|
106
|
+
dispatchParams: "data: RequestBody, params?: Params"
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
if (paramMandatory) {
|
|
111
|
+
return {
|
|
112
|
+
shape: `UnaryFunctionHook<Params, Response, _ErrorType>`,
|
|
113
|
+
shapeImport: `UnaryFunctionHook`,
|
|
114
|
+
dispatchParamExpansion: `p`,
|
|
115
|
+
dispatchParams: "params: Params"
|
|
116
|
+
};
|
|
117
|
+
} else {
|
|
118
|
+
return {
|
|
119
|
+
shape: `UnaryFunctionHook<Params, Response, _ErrorType>`,
|
|
120
|
+
shapeImport: `UnaryFunctionHook`,
|
|
121
|
+
dispatchParamExpansion: `p = {}`,
|
|
122
|
+
dispatchParams: "params?: Params"
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
if (properties.requestBody) {
|
|
128
|
+
if (paramMandatory) {
|
|
129
|
+
return {
|
|
130
|
+
shape: `BinaryProduceHook<Params, RequestBody, _ErrorType>`,
|
|
131
|
+
shapeImport: `BinaryProduceHook`,
|
|
132
|
+
dispatchParamExpansion: `data, p`,
|
|
133
|
+
dispatchParams: "data: RequestBody, params: Params"
|
|
134
|
+
};
|
|
135
|
+
} else {
|
|
136
|
+
return {
|
|
137
|
+
shape: `BinaryProduceHook<Params, RequestBody, _ErrorType>`,
|
|
138
|
+
shapeImport: `BinaryProduceHook`,
|
|
139
|
+
dispatchParamExpansion: `data, p = {}`,
|
|
140
|
+
dispatchParams: "data: RequestBody, params?: Params"
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
if (paramMandatory) {
|
|
145
|
+
return {
|
|
146
|
+
shape: `UnaryProduceHook<Params, _ErrorType>`,
|
|
147
|
+
shapeImport: `UnaryProduceHook`,
|
|
148
|
+
dispatchParamExpansion: `p`,
|
|
149
|
+
dispatchParams: "params: Params"
|
|
150
|
+
};
|
|
151
|
+
} else {
|
|
152
|
+
return {
|
|
153
|
+
shape: `UnaryProduceHook<Params, _ErrorType>`,
|
|
154
|
+
shapeImport: `UnaryProduceHook`,
|
|
155
|
+
dispatchParamExpansion: `p = {}`,
|
|
156
|
+
dispatchParams: "params?: Params"
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function decodeDispatchParams(operationId, requestBody, isParamMandatory) {
|
|
163
|
+
return {
|
|
164
|
+
dispatchParams: getDispatchParams(operationId, requestBody, isParamMandatory),
|
|
165
|
+
dispatchParamExpansion: getDispatchParamExpansion(requestBody, isParamMandatory)
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function getDataTransformer(contentType) {
|
|
169
|
+
let finalRequestBodyBlock = 'data';
|
|
170
|
+
switch(contentType){
|
|
171
|
+
case "application/json":
|
|
172
|
+
case "application/octet-stream":
|
|
173
|
+
case "text/plain":
|
|
174
|
+
finalRequestBodyBlock = `data`;
|
|
175
|
+
break;
|
|
176
|
+
case "multipart/form-data":
|
|
177
|
+
finalRequestBodyBlock = `data: (function(){
|
|
178
|
+
let formData = new FormData()
|
|
179
|
+
Object.entries(data).filter(a => !!a[1]).forEach(([key, value]) => formData.append(key, value))
|
|
180
|
+
return formData;
|
|
181
|
+
})()`;
|
|
182
|
+
break;
|
|
183
|
+
case "application/x-www-form-urlencoded":
|
|
184
|
+
finalRequestBodyBlock = `data: qs.stringify(data)`;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
return finalRequestBodyBlock;
|
|
188
|
+
}
|
|
189
|
+
const contentTypePostfixMap = {
|
|
190
|
+
'application/json': undefined,
|
|
191
|
+
'multipart/form-data': 'form',
|
|
192
|
+
'application/octet-stream': 'binary',
|
|
193
|
+
'application/x-www-form-urlencoded': 'form',
|
|
194
|
+
'application/xml': 'xml',
|
|
195
|
+
'text/plain': 'txt',
|
|
196
|
+
'text/html': 'html',
|
|
197
|
+
'text/css': 'css',
|
|
198
|
+
'text/javascript': 'js'
|
|
199
|
+
};
|
|
200
|
+
function generatePostfix(contentType, responseType) {
|
|
201
|
+
return [
|
|
202
|
+
contentType && contentTypePostfixMap[contentType] ? `$${contentTypePostfixMap[contentType]}` : undefined,
|
|
203
|
+
responseType && contentTypePostfixMap[responseType] ? `_${contentTypePostfixMap[responseType]}` : undefined
|
|
204
|
+
].filter(Boolean).join('');
|
|
205
|
+
}
|
|
206
|
+
function decodeErrorSections(errorResponses, source, prefix = '@root') {
|
|
207
|
+
const errorTypes = Array.from(new Set(Object.values(errorResponses ?? {}).map((a)=>a.response)));
|
|
208
|
+
const imports = errorTypes.map((ref)=>`import {${ref}, ${ref}Schema } from "${prefix}/${source}/components/schemas/${ref}.js"`).join('\n');
|
|
209
|
+
let schemaValidation = "z.any()";
|
|
210
|
+
switch(errorTypes.length){
|
|
211
|
+
case 0:
|
|
212
|
+
schemaValidation = "z.any()";
|
|
213
|
+
break;
|
|
214
|
+
case 1:
|
|
215
|
+
schemaValidation = `${errorTypes[0]}Schema`;
|
|
216
|
+
break;
|
|
217
|
+
default:
|
|
218
|
+
schemaValidation = `z.union([${errorTypes.map((a)=>`${a}Schema`).join(', ')}])`;
|
|
219
|
+
}
|
|
220
|
+
const s = errorTypes.join(' | ');
|
|
221
|
+
const def = `${s.trim().length ? s : 'any'}`;
|
|
222
|
+
return {
|
|
223
|
+
imports,
|
|
224
|
+
def,
|
|
225
|
+
schemaValidation
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function mdLiteral(path) {
|
|
230
|
+
return async (strings, ...values)=>{
|
|
231
|
+
let rawCode = strings.reduce((acc, str, i)=>acc + str + (values[i] || ''), '');
|
|
232
|
+
rawCode = rawCode.replace("<hint>", "<hint style='display:none'>");
|
|
233
|
+
const content = await prettier__namespace.format(rawCode, {
|
|
234
|
+
parser: 'markdown'
|
|
235
|
+
});
|
|
236
|
+
return {
|
|
237
|
+
path,
|
|
238
|
+
content
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function typescript(path) {
|
|
244
|
+
return async (strings, ...values)=>{
|
|
245
|
+
const rawCode = strings.reduce((acc, str, i)=>{
|
|
246
|
+
if (str.startsWith("*/")) str = str.slice(2);
|
|
247
|
+
const [before] = str.split("/*!");
|
|
248
|
+
return acc + before + (values?.[i] || '');
|
|
249
|
+
}, '');
|
|
250
|
+
const content = await prettier__namespace.format(rawCode, {
|
|
251
|
+
parser: 'typescript',
|
|
252
|
+
singleQuote: true
|
|
253
|
+
});
|
|
254
|
+
return {
|
|
255
|
+
path,
|
|
256
|
+
content
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Regexps involved with splitting words in various case formats.
|
|
262
|
+
const SPLIT_LOWER_UPPER_RE = /([a-z0-9])([A-Z])/g;
|
|
263
|
+
const SPLIT_UPPER_UPPER_RE = /([A-Z])([A-Z][a-z])/g;
|
|
264
|
+
// Used to iterate over the initial split result and separate numbers.
|
|
265
|
+
const SPLIT_SEPARATE_NUMBER_RE = /(\d)[a-z]|([a-zA-Z])\d/g;
|
|
266
|
+
// Regexp involved with stripping non-word characters from the result.
|
|
267
|
+
const DEFAULT_STRIP_REGEXP = /[^a-zA-Z0-9]+/g;
|
|
268
|
+
// The replacement value for splits.
|
|
269
|
+
const SPLIT_REPLACE_VALUE = "$1\0$2";
|
|
270
|
+
// The default characters to keep after transforming case.
|
|
271
|
+
const DEFAULT_PREFIX_SUFFIX_CHARACTERS = "";
|
|
272
|
+
/**
|
|
273
|
+
* Split any cased input strings into an array of words.
|
|
274
|
+
*/ function split(value) {
|
|
275
|
+
let result = value.trim();
|
|
276
|
+
result = result.replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE).replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);
|
|
277
|
+
result = result.replace(DEFAULT_STRIP_REGEXP, "\0");
|
|
278
|
+
let start = 0;
|
|
279
|
+
let end = result.length;
|
|
280
|
+
// Trim the delimiter from around the output string.
|
|
281
|
+
while(result.charAt(start) === "\0")start++;
|
|
282
|
+
if (start === end) return [];
|
|
283
|
+
while(result.charAt(end - 1) === "\0")end--;
|
|
284
|
+
return result.slice(start, end).split(/\0/g);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Split the input string into an array of words, separating numbers.
|
|
288
|
+
*/ function splitSeparateNumbers(value) {
|
|
289
|
+
const words = split(value);
|
|
290
|
+
for(let i = 0; i < words.length; i++){
|
|
291
|
+
const word = words[i];
|
|
292
|
+
const match = SPLIT_SEPARATE_NUMBER_RE.exec(word);
|
|
293
|
+
if (match) {
|
|
294
|
+
const offset = match.index + (match[1] ?? match[2]).length;
|
|
295
|
+
words.splice(i, 1, word.slice(0, offset), word.slice(offset));
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return words;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Convert a string to space separated lower case (`foo bar`).
|
|
302
|
+
*/ function noCase(input, options) {
|
|
303
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
304
|
+
return prefix + words.map(lowerFactory(options?.locale)).join(options?.delimiter ?? " ") + suffix;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Convert a string to camel case (`fooBar`).
|
|
308
|
+
*/ function camelCase(input, options) {
|
|
309
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
310
|
+
const lower = lowerFactory(options?.locale);
|
|
311
|
+
const upper = upperFactory(options?.locale);
|
|
312
|
+
const transform = options?.mergeAmbiguousCharacters ? capitalCaseTransformFactory(lower, upper) : pascalCaseTransformFactory(lower, upper);
|
|
313
|
+
return prefix + words.map((word, index)=>{
|
|
314
|
+
if (index === 0) return lower(word);
|
|
315
|
+
return transform(word, index);
|
|
316
|
+
}).join(options?.delimiter ?? "") + suffix;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Convert a string to pascal case (`FooBar`).
|
|
320
|
+
*/ function pascalCase(input, options) {
|
|
321
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
322
|
+
const lower = lowerFactory(options?.locale);
|
|
323
|
+
const upper = upperFactory(options?.locale);
|
|
324
|
+
const transform = options?.mergeAmbiguousCharacters ? capitalCaseTransformFactory(lower, upper) : pascalCaseTransformFactory(lower, upper);
|
|
325
|
+
return prefix + words.map(transform).join(options?.delimiter ?? "") + suffix;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Convert a string to pascal snake case (`Foo_Bar`).
|
|
329
|
+
*/ function pascalSnakeCase(input, options) {
|
|
330
|
+
return capitalCase(input, {
|
|
331
|
+
delimiter: "_",
|
|
332
|
+
...options
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Convert a string to capital case (`Foo Bar`).
|
|
337
|
+
*/ function capitalCase(input, options) {
|
|
338
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
339
|
+
const lower = lowerFactory(options?.locale);
|
|
340
|
+
const upper = upperFactory(options?.locale);
|
|
341
|
+
return prefix + words.map(capitalCaseTransformFactory(lower, upper)).join(options?.delimiter ?? " ") + suffix;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Convert a string to constant case (`FOO_BAR`).
|
|
345
|
+
*/ function constantCase(input, options) {
|
|
346
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
347
|
+
return prefix + words.map(upperFactory(options?.locale)).join(options?.delimiter ?? "_") + suffix;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Convert a string to dot case (`foo.bar`).
|
|
351
|
+
*/ function dotCase(input, options) {
|
|
352
|
+
return noCase(input, {
|
|
353
|
+
delimiter: ".",
|
|
354
|
+
...options
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Convert a string to kebab case (`foo-bar`).
|
|
359
|
+
*/ function kebabCase(input, options) {
|
|
360
|
+
return noCase(input, {
|
|
361
|
+
delimiter: "-",
|
|
362
|
+
...options
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Convert a string to path case (`foo/bar`).
|
|
367
|
+
*/ function pathCase(input, options) {
|
|
368
|
+
return noCase(input, {
|
|
369
|
+
delimiter: "/",
|
|
370
|
+
...options
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Convert a string to path case (`Foo bar`).
|
|
375
|
+
*/ function sentenceCase(input, options) {
|
|
376
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
377
|
+
const lower = lowerFactory(options?.locale);
|
|
378
|
+
const upper = upperFactory(options?.locale);
|
|
379
|
+
const transform = capitalCaseTransformFactory(lower, upper);
|
|
380
|
+
return prefix + words.map((word, index)=>{
|
|
381
|
+
if (index === 0) return transform(word);
|
|
382
|
+
return lower(word);
|
|
383
|
+
}).join(options?.delimiter ?? " ") + suffix;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Convert a string to snake case (`foo_bar`).
|
|
387
|
+
*/ function snakeCase(input, options) {
|
|
388
|
+
return noCase(input, {
|
|
389
|
+
delimiter: "_",
|
|
390
|
+
...options
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Convert a string to header case (`Foo-Bar`).
|
|
395
|
+
*/ function trainCase(input, options) {
|
|
396
|
+
return capitalCase(input, {
|
|
397
|
+
delimiter: "-",
|
|
398
|
+
...options
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
function lowerFactory(locale) {
|
|
402
|
+
return locale === false ? (input)=>input.toLowerCase() : (input)=>input.toLocaleLowerCase(locale);
|
|
403
|
+
}
|
|
404
|
+
function upperFactory(locale) {
|
|
405
|
+
return locale === false ? (input)=>input.toUpperCase() : (input)=>input.toLocaleUpperCase(locale);
|
|
406
|
+
}
|
|
407
|
+
function capitalCaseTransformFactory(lower, upper) {
|
|
408
|
+
return (word)=>`${upper(word[0])}${lower(word.slice(1))}`;
|
|
409
|
+
}
|
|
410
|
+
function pascalCaseTransformFactory(lower, upper) {
|
|
411
|
+
return (word, index)=>{
|
|
412
|
+
const char0 = word[0];
|
|
413
|
+
const initial = index > 0 && char0 >= "0" && char0 <= "9" ? "_" + char0 : upper(char0);
|
|
414
|
+
return initial + lower(word.slice(1));
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
function splitPrefixSuffix(input, options = {}) {
|
|
418
|
+
const splitFn = options.split ?? (options.separateNumbers ? splitSeparateNumbers : split);
|
|
419
|
+
const prefixCharacters = options.prefixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
|
|
420
|
+
const suffixCharacters = options.suffixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
|
|
421
|
+
let prefixIndex = 0;
|
|
422
|
+
let suffixIndex = input.length;
|
|
423
|
+
while(prefixIndex < input.length){
|
|
424
|
+
const char = input.charAt(prefixIndex);
|
|
425
|
+
if (!prefixCharacters.includes(char)) break;
|
|
426
|
+
prefixIndex++;
|
|
427
|
+
}
|
|
428
|
+
while(suffixIndex > prefixIndex){
|
|
429
|
+
const index = suffixIndex - 1;
|
|
430
|
+
const char = input.charAt(index);
|
|
431
|
+
if (!suffixCharacters.includes(char)) break;
|
|
432
|
+
suffixIndex = index;
|
|
433
|
+
}
|
|
434
|
+
return [
|
|
435
|
+
input.slice(0, prefixIndex),
|
|
436
|
+
splitFn(input.slice(prefixIndex, suffixIndex)),
|
|
437
|
+
input.slice(suffixIndex)
|
|
438
|
+
];
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
exports.StatsCounter = StatsCounter;
|
|
442
|
+
exports.camelCase = camelCase;
|
|
443
|
+
exports.capitalCase = capitalCase;
|
|
444
|
+
exports.constantCase = constantCase;
|
|
445
|
+
exports.decodeDispatchParams = decodeDispatchParams;
|
|
446
|
+
exports.decodeErrorSections = decodeErrorSections;
|
|
447
|
+
exports.decodeVariables = decodeVariables;
|
|
448
|
+
exports.dotCase = dotCase;
|
|
449
|
+
exports.extractParams = extractParams;
|
|
450
|
+
exports.generatePostfix = generatePostfix;
|
|
451
|
+
exports.getDataTransformer = getDataTransformer;
|
|
452
|
+
exports.getDispatchParamExpansion = getDispatchParamExpansion;
|
|
453
|
+
exports.getDispatchParams = getDispatchParams;
|
|
454
|
+
exports.getParamExplodeExpression = getParamExplodeExpression;
|
|
455
|
+
exports.getVariableImports = getVariableImports;
|
|
456
|
+
exports.getVariableName = getVariableName;
|
|
457
|
+
exports.getVariableTypes = getVariableTypes;
|
|
458
|
+
exports.isParamMandatory = isParamMandatory;
|
|
459
|
+
exports.jsonLiteral = jsonLiteral;
|
|
460
|
+
exports.kebabCase = kebabCase;
|
|
461
|
+
exports.mdLiteral = mdLiteral;
|
|
462
|
+
exports.noCase = noCase;
|
|
463
|
+
exports.pascalCase = pascalCase;
|
|
464
|
+
exports.pascalSnakeCase = pascalSnakeCase;
|
|
465
|
+
exports.pathCase = pathCase;
|
|
466
|
+
exports.sentenceCase = sentenceCase;
|
|
467
|
+
exports.snakeCase = snakeCase;
|
|
468
|
+
exports.split = split;
|
|
469
|
+
exports.splitSeparateNumbers = splitSeparateNumbers;
|
|
470
|
+
exports.trainCase = trainCase;
|
|
471
|
+
exports.typescript = typescript;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from './lib/template/json-literal.js';
|
|
3
|
-
export * from './lib/template/template-util.js';
|
|
4
|
-
export * from './lib/template/md-literal.js';
|
|
5
|
-
export * from './lib/template/ts-literal.js';
|
|
6
|
-
export * from './lib/util/change-case.js';
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
export * from "./src/index";
|