@kubb/plugin-faker 5.1.7 → 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 +21 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +304 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +22 -24
- package/dist/index.js.map +1 -1
- package/kubb-extension.json +31 -1
- package/package.json +13 -8
- package/dist/rolldown-runtime-C0LytTxp.js +0 -8
package/dist/index.cjs
CHANGED
|
@@ -16,12 +16,23 @@ let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
|
16
16
|
*
|
|
17
17
|
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
18
18
|
*/
|
|
19
|
-
function
|
|
19
|
+
function convert(text, pascal) {
|
|
20
20
|
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) => {
|
|
21
21
|
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
22
22
|
return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
|
|
23
23
|
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
24
24
|
}
|
|
25
|
+
const cache = /* @__PURE__ */ new Map();
|
|
26
|
+
const cacheLimit = 1e4;
|
|
27
|
+
function toCamelOrPascal(text, pascal) {
|
|
28
|
+
const key = `${pascal ? "P" : "c"}${text}`;
|
|
29
|
+
const cached = cache.get(key);
|
|
30
|
+
if (cached !== void 0) return cached;
|
|
31
|
+
const result = convert(text, pascal);
|
|
32
|
+
if (cache.size >= cacheLimit) cache.clear();
|
|
33
|
+
cache.set(key, result);
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
25
36
|
/**
|
|
26
37
|
* Converts `text` to camelCase.
|
|
27
38
|
*
|
|
@@ -224,29 +235,16 @@ function stringify(value) {
|
|
|
224
235
|
return `'${JSON.stringify(trimQuotes(value.toString())).slice(1, -1).replace(/\\"/g, "\"").replace(/'/g, "\\'")}'`;
|
|
225
236
|
}
|
|
226
237
|
/**
|
|
227
|
-
* Escapes
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
* @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
|
|
238
|
+
* Escapes an `@` at the start of a line, so a multi-line description can't start a new JSDoc tag.
|
|
239
|
+
* Editors render `\@` as `@` in hovers.
|
|
231
240
|
*
|
|
232
241
|
* @example
|
|
233
242
|
* ```ts
|
|
234
|
-
*
|
|
243
|
+
* jsDocEscape('intro\n@example value') // 'intro\n\\@example value'
|
|
235
244
|
* ```
|
|
236
245
|
*/
|
|
237
|
-
function
|
|
238
|
-
return `${input}`.replace(
|
|
239
|
-
switch (character) {
|
|
240
|
-
case "\"":
|
|
241
|
-
case "'":
|
|
242
|
-
case "\\": return `\\${character}`;
|
|
243
|
-
case "\n": return "\\n";
|
|
244
|
-
case "\r": return "\\r";
|
|
245
|
-
case "\u2028": return "\\u2028";
|
|
246
|
-
case "\u2029": return "\\u2029";
|
|
247
|
-
default: return "";
|
|
248
|
-
}
|
|
249
|
-
});
|
|
246
|
+
function jsDocEscape(input) {
|
|
247
|
+
return `${input}`.replace(/^(\s*)@/gm, "$1\\@");
|
|
250
248
|
}
|
|
251
249
|
/**
|
|
252
250
|
* Converts a pattern string into a `new RegExp(...)` constructor call or a regex literal string.
|
|
@@ -524,7 +522,7 @@ function Faker({ node, description, name, typeName, printer, canOverride, typeMo
|
|
|
524
522
|
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
|
|
525
523
|
export: true,
|
|
526
524
|
name,
|
|
527
|
-
JSDoc: { comments: description ? [`@description ${
|
|
525
|
+
JSDoc: { comments: description ? [`@description ${jsDocEscape(description)}`] : [] },
|
|
528
526
|
params: canOverride ? paramsSignature : void 0,
|
|
529
527
|
returnType: returnType ?? void 0,
|
|
530
528
|
children: `return ${returnExpression}`
|
|
@@ -554,7 +552,7 @@ return {
|
|
|
554
552
|
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
|
|
555
553
|
export: true,
|
|
556
554
|
name,
|
|
557
|
-
JSDoc: { comments: description ? [`@description ${
|
|
555
|
+
JSDoc: { comments: description ? [`@description ${jsDocEscape(description)}`] : [] },
|
|
558
556
|
generics: typeMode === "schema" ? void 0 : `TData extends Partial<${typeName}> = object`,
|
|
559
557
|
params: typeMode === "schema" ? `data?: Partial<${typeName}>` : "data?: TData",
|
|
560
558
|
returnType: typeMode === "schema" ? typeName : void 0,
|
|
@@ -1398,11 +1396,11 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1398
1396
|
//#region kubb-extension.json
|
|
1399
1397
|
var compatibility = {
|
|
1400
1398
|
"kubb": ">=5.8.3",
|
|
1401
|
-
"node": ">=22"
|
|
1399
|
+
"node": ">=22.12"
|
|
1402
1400
|
};
|
|
1403
1401
|
//#endregion
|
|
1404
1402
|
//#region package.json
|
|
1405
|
-
var version = "5.1.
|
|
1403
|
+
var version = "5.1.10";
|
|
1406
1404
|
//#endregion
|
|
1407
1405
|
//#region src/resolvers/resolverFaker.ts
|
|
1408
1406
|
/**
|