@kubb/plugin-faker 5.1.9 → 5.1.10
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 +20 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -22
- package/dist/index.js.map +1 -1
- package/kubb-extension.json +30 -0
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -12,12 +12,23 @@ import { buildParams, enumTypeName, pluginTsName } from "@kubb/plugin-ts";
|
|
|
12
12
|
*
|
|
13
13
|
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
14
14
|
*/
|
|
15
|
-
function
|
|
15
|
+
function convert(text, pascal) {
|
|
16
16
|
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
17
17
|
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
18
18
|
return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
|
|
19
19
|
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
20
20
|
}
|
|
21
|
+
const cache = /* @__PURE__ */ new Map();
|
|
22
|
+
const cacheLimit = 1e4;
|
|
23
|
+
function toCamelOrPascal(text, pascal) {
|
|
24
|
+
const key = `${pascal ? "P" : "c"}${text}`;
|
|
25
|
+
const cached = cache.get(key);
|
|
26
|
+
if (cached !== void 0) return cached;
|
|
27
|
+
const result = convert(text, pascal);
|
|
28
|
+
if (cache.size >= cacheLimit) cache.clear();
|
|
29
|
+
cache.set(key, result);
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
21
32
|
/**
|
|
22
33
|
* Converts `text` to camelCase.
|
|
23
34
|
*
|
|
@@ -220,29 +231,16 @@ function stringify(value) {
|
|
|
220
231
|
return `'${JSON.stringify(trimQuotes(value.toString())).slice(1, -1).replace(/\\"/g, "\"").replace(/'/g, "\\'")}'`;
|
|
221
232
|
}
|
|
222
233
|
/**
|
|
223
|
-
* Escapes
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
* @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
|
|
234
|
+
* Escapes an `@` at the start of a line, so a multi-line description can't start a new JSDoc tag.
|
|
235
|
+
* Editors render `\@` as `@` in hovers.
|
|
227
236
|
*
|
|
228
237
|
* @example
|
|
229
238
|
* ```ts
|
|
230
|
-
*
|
|
239
|
+
* jsDocEscape('intro\n@example value') // 'intro\n\\@example value'
|
|
231
240
|
* ```
|
|
232
241
|
*/
|
|
233
|
-
function
|
|
234
|
-
return `${input}`.replace(
|
|
235
|
-
switch (character) {
|
|
236
|
-
case "\"":
|
|
237
|
-
case "'":
|
|
238
|
-
case "\\": return `\\${character}`;
|
|
239
|
-
case "\n": return "\\n";
|
|
240
|
-
case "\r": return "\\r";
|
|
241
|
-
case "\u2028": return "\\u2028";
|
|
242
|
-
case "\u2029": return "\\u2029";
|
|
243
|
-
default: return "";
|
|
244
|
-
}
|
|
245
|
-
});
|
|
242
|
+
function jsDocEscape(input) {
|
|
243
|
+
return `${input}`.replace(/^(\s*)@/gm, "$1\\@");
|
|
246
244
|
}
|
|
247
245
|
/**
|
|
248
246
|
* Converts a pattern string into a `new RegExp(...)` constructor call or a regex literal string.
|
|
@@ -520,7 +518,7 @@ function Faker({ node, description, name, typeName, printer, canOverride, typeMo
|
|
|
520
518
|
children: /* @__PURE__ */ jsx(Function, {
|
|
521
519
|
export: true,
|
|
522
520
|
name,
|
|
523
|
-
JSDoc: { comments: description ? [`@description ${
|
|
521
|
+
JSDoc: { comments: description ? [`@description ${jsDocEscape(description)}`] : [] },
|
|
524
522
|
params: canOverride ? paramsSignature : void 0,
|
|
525
523
|
returnType: returnType ?? void 0,
|
|
526
524
|
children: `return ${returnExpression}`
|
|
@@ -550,7 +548,7 @@ return {
|
|
|
550
548
|
children: /* @__PURE__ */ jsx(Function, {
|
|
551
549
|
export: true,
|
|
552
550
|
name,
|
|
553
|
-
JSDoc: { comments: description ? [`@description ${
|
|
551
|
+
JSDoc: { comments: description ? [`@description ${jsDocEscape(description)}`] : [] },
|
|
554
552
|
generics: typeMode === "schema" ? void 0 : `TData extends Partial<${typeName}> = object`,
|
|
555
553
|
params: typeMode === "schema" ? `data?: Partial<${typeName}>` : "data?: TData",
|
|
556
554
|
returnType: typeMode === "schema" ? typeName : void 0,
|
|
@@ -1398,7 +1396,7 @@ var compatibility = {
|
|
|
1398
1396
|
};
|
|
1399
1397
|
//#endregion
|
|
1400
1398
|
//#region package.json
|
|
1401
|
-
var version = "5.1.
|
|
1399
|
+
var version = "5.1.10";
|
|
1402
1400
|
//#endregion
|
|
1403
1401
|
//#region src/resolvers/resolverFaker.ts
|
|
1404
1402
|
/**
|