typia 13.2.0 → 14.0.0
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/lib/http.d.ts +3 -3
- package/lib/http.js.map +1 -1
- package/lib/http.mjs.map +1 -1
- package/lib/internal/_assertGuard.js +13 -3
- package/lib/internal/_assertGuard.js.map +1 -1
- package/lib/internal/_assertGuard.mjs +4 -2
- package/lib/internal/_assertGuard.mjs.map +1 -1
- package/lib/internal/_isFormatIdnHostname.js +5 -1
- package/lib/internal/_isFormatIdnHostname.js.map +1 -1
- package/lib/internal/_isFormatIdnHostname.mjs +1 -1
- package/lib/internal/_isFormatIdnHostname.mjs.map +1 -1
- package/lib/internal/_isFormatTime.js +19 -2
- package/lib/internal/_isFormatTime.js.map +1 -1
- package/lib/internal/_isFormatTime.mjs +9 -2
- package/lib/internal/_isFormatTime.mjs.map +1 -1
- package/lib/internal/_randomArray.js +37 -4
- package/lib/internal/_randomArray.js.map +1 -1
- package/lib/internal/_randomArray.mjs +16 -3
- package/lib/internal/_randomArray.mjs.map +1 -1
- package/lib/internal/_randomFormatByte.js +15 -12
- package/lib/internal/_randomFormatByte.js.map +1 -1
- package/lib/internal/_randomFormatByte.mjs +11 -10
- package/lib/internal/_randomFormatByte.mjs.map +1 -1
- package/lib/internal/_randomFormatDatetime.mjs +1 -1
- package/lib/internal/_randomFormatHostname.d.ts +2 -2
- package/lib/internal/_randomFormatHostname.js +2 -2
- package/lib/internal/_randomFormatHostname.mjs +2 -2
- package/lib/internal/_randomFormatHostname.mjs.map +1 -1
- package/lib/internal/_randomFormatIdnHostname.js +9 -10
- package/lib/internal/_randomFormatIdnHostname.js.map +1 -1
- package/lib/internal/_randomFormatIdnHostname.mjs +3 -4
- package/lib/internal/_randomFormatIdnHostname.mjs.map +1 -1
- package/lib/internal/_randomFormatRegex.js +4 -4
- package/lib/internal/_randomFormatRegex.js.map +1 -1
- package/lib/internal/_randomFormatRegex.mjs +1 -2
- package/lib/internal/_randomFormatRegex.mjs.map +1 -1
- package/lib/internal/_randomFormatTime.js +15 -10
- package/lib/internal/_randomFormatTime.js.map +1 -1
- package/lib/internal/_randomFormatTime.mjs +6 -3
- package/lib/internal/_randomFormatTime.mjs.map +1 -1
- package/lib/internal/_randomPattern.js +20 -3
- package/lib/internal/_randomPattern.js.map +1 -1
- package/lib/internal/_randomPattern.mjs +5 -1
- package/lib/internal/_randomPattern.mjs.map +1 -1
- package/lib/internal/_randomStringLength.js +9 -2
- package/lib/internal/_randomStringLength.js.map +1 -1
- package/lib/internal/_randomStringLength.mjs +3 -1
- package/lib/internal/_randomStringLength.mjs.map +1 -1
- package/lib/internal/private/__randomComposition.d.ts +8 -0
- package/lib/internal/private/__randomComposition.js +21 -1
- package/lib/internal/private/__randomComposition.js.map +1 -1
- package/lib/internal/private/__randomComposition.mjs +18 -1
- package/lib/internal/private/__randomComposition.mjs.map +1 -1
- package/lib/json.d.ts +2 -2
- package/lib/json.js.map +1 -1
- package/lib/json.mjs.map +1 -1
- package/lib/module.d.ts +28 -13
- package/lib/module.js.map +1 -1
- package/lib/module.mjs.map +1 -1
- package/lib/notations.d.ts +4 -4
- package/lib/notations.js.map +1 -1
- package/lib/notations.mjs.map +1 -1
- package/lib/plain.d.ts +3 -3
- package/lib/plain.js.map +1 -1
- package/lib/plain.mjs.map +1 -1
- package/lib/protobuf.d.ts +2 -2
- package/lib/protobuf.js.map +1 -1
- package/lib/protobuf.mjs.map +1 -1
- package/lib/transform.mjs +1 -1
- package/native/cmd/ttsc-typia/assert_guard_factory_contract_test.go +17 -4
- package/native/cmd/ttsc-typia/create_assert_error_factory_arity_test.go +309 -0
- package/native/cmd/ttsc-typia/dynamic_key_tags_transform_test.go +206 -0
- package/native/cmd/ttsc-typia/local_function_named_like_typia_operation_transform_test.go +185 -0
- package/native/cmd/ttsc-typia/notation_kebab_case_transform_test.go +2 -2
- package/native/cmd/ttsc-typia/project_catalog_transform_coverage_test.go +84 -85
- package/native/cmd/ttsc-typia/recursive_conditional_alias_name_transform_test.go +307 -0
- package/native/cmd/ttsc-typia/shadowed_typia_module_declaration_diagnostic_test.go +152 -0
- package/native/cmd/ttsc-typia/transform.go +2 -2
- package/native/cmd/ttsc-typia/transform_helpers_test.go +96 -18
- package/native/core/factories/FormatCheatSheet.go +2 -2
- package/native/core/factories/MetadataCommentTagFactory.go +91 -7
- package/native/core/factories/factory_utility_coverage_test.go +896 -907
- package/native/core/factories/internal/metadata/MetadataHelper.go +5 -28
- package/native/core/factories/metadata_comment_tag_factory_rejects_out_of_range_integer_test.go +124 -0
- package/native/core/programmers/AssertProgrammer.go +20 -6
- package/native/core/programmers/RandomProgrammer.go +78 -3
- package/native/core/programmers/ValidateProgrammer.go +21 -6
- package/native/core/programmers/helpers/RandomJoiner.go +8 -1
- package/native/core/programmers/iterate/check_dynamic_properties.go +177 -3
- package/native/core/programmers/iterate/check_object.go +12 -1
- package/native/core/schemas/metadata/MetadataCollection.go +47 -5
- package/native/transform/CallExpressionTransformer.go +167 -0
- package/package.json +3 -12
- package/src/http.ts +18 -4
- package/src/internal/_assertGuard.ts +13 -2
- package/src/internal/_isFormatIdnHostname.ts +5 -1
- package/src/internal/_isFormatTime.ts +19 -2
- package/src/internal/_randomArray.ts +42 -6
- package/src/internal/_randomFormatByte.ts +17 -12
- package/src/internal/_randomFormatHostname.ts +2 -2
- package/src/internal/_randomFormatIdnHostname.ts +8 -9
- package/src/internal/_randomFormatRegex.ts +4 -6
- package/src/internal/_randomFormatTime.ts +15 -10
- package/src/internal/_randomPattern.ts +18 -3
- package/src/internal/_randomStringLength.ts +9 -2
- package/src/internal/private/__randomComposition.ts +24 -0
- package/src/json.ts +16 -4
- package/src/module.ts +56 -22
- package/src/notations.ts +16 -4
- package/src/plain.ts +12 -3
- package/src/protobuf.ts +16 -4
- package/lib/executable/FileSystemIdentity.d.ts +0 -44
- package/lib/executable/FileSystemIdentity.js +0 -213
- package/lib/executable/FileSystemIdentity.js.map +0 -1
- package/lib/executable/FileSystemIdentity.mjs +0 -133
- package/lib/executable/FileSystemIdentity.mjs.map +0 -1
- package/lib/executable/TypiaGenerateWizard.d.ts +0 -9
- package/lib/executable/TypiaGenerateWizard.js +0 -852
- package/lib/executable/TypiaGenerateWizard.js.map +0 -1
- package/lib/executable/TypiaGenerateWizard.mjs +0 -618
- package/lib/executable/TypiaGenerateWizard.mjs.map +0 -1
- package/lib/executable/generate/ttsc.d.ts +0 -1
- package/lib/executable/generate/ttsc.js +0 -53
- package/lib/executable/generate/ttsc.js.map +0 -1
- package/lib/executable/generate/ttsc.mjs +0 -37
- package/lib/executable/generate/ttsc.mjs.map +0 -1
- package/lib/executable/typia.d.ts +0 -2
- package/lib/executable/typia.js +0 -84
- package/lib/executable/typia.js.map +0 -1
- package/lib/executable/typia.mjs +0 -60
- package/lib/executable/typia.mjs.map +0 -1
- package/src/executable/FileSystemIdentity.ts +0 -222
- package/src/executable/TypiaGenerateWizard.ts +0 -1133
- package/src/executable/generate/ttsc.ts +0 -70
- package/src/executable/typia.ts +0 -80
|
@@ -20,8 +20,8 @@ const pickLength = (props) => {
|
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
22
|
* Builds dot-joined hostname labels totaling exactly `length` characters, each
|
|
23
|
-
* label within 63 chars. Shared with the idn-hostname generator, which
|
|
24
|
-
*
|
|
23
|
+
* label within 63 chars. Shared with the idn-hostname generator, which realizes
|
|
24
|
+
* its length the same way since #2317 gave the two formats one structure.
|
|
25
25
|
*/
|
|
26
26
|
const _randomHostnameLabels = (length) => {
|
|
27
27
|
const parts = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatHostname.mjs","names":[],"sources":["../../src/internal/_randomFormatHostname.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport { _randomString } from \"./_randomString\";\nimport { _ILengthProps } from \"./_randomStringLength\";\n\nexport const _randomFormatHostname = (props?: _ILengthProps): string => {\n if (props?.minLength === undefined && props?.maxLength === undefined)\n return `${random(10)}.${random(3)}`;\n // A hostname is dot-joined labels of 1..63 chars whose total is capped at 253,\n // so the requested length is realized by splitting it across enough labels.\n return _randomHostnameLabels(pickLength(props));\n};\n\nconst MAX_TOTAL = 253;\nconst MAX_LABEL = 63;\n\nconst pickLength = (props: _ILengthProps): number => {\n let low: number = props.minLength === undefined ? 1 : props.minLength;\n if (low < 1) low = 1;\n const high: number =\n props.maxLength === undefined\n ? Math.min(MAX_TOTAL, low + 14)\n : Math.min(MAX_TOTAL, props.maxLength);\n if (high < low)\n throw new Error(\n \"unable to generate a random hostname satisfying both the format and the length constraints.\",\n );\n return _randomInteger({ type: \"integer\", minimum: low, maximum: high });\n};\n\n/**\n * Builds dot-joined hostname labels totaling exactly `length` characters, each\n * label within 63 chars. Shared with the idn-hostname generator, which
|
|
1
|
+
{"version":3,"file":"_randomFormatHostname.mjs","names":[],"sources":["../../src/internal/_randomFormatHostname.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport { _randomString } from \"./_randomString\";\nimport { _ILengthProps } from \"./_randomStringLength\";\n\nexport const _randomFormatHostname = (props?: _ILengthProps): string => {\n if (props?.minLength === undefined && props?.maxLength === undefined)\n return `${random(10)}.${random(3)}`;\n // A hostname is dot-joined labels of 1..63 chars whose total is capped at 253,\n // so the requested length is realized by splitting it across enough labels.\n return _randomHostnameLabels(pickLength(props));\n};\n\nconst MAX_TOTAL = 253;\nconst MAX_LABEL = 63;\n\nconst pickLength = (props: _ILengthProps): number => {\n let low: number = props.minLength === undefined ? 1 : props.minLength;\n if (low < 1) low = 1;\n const high: number =\n props.maxLength === undefined\n ? Math.min(MAX_TOTAL, low + 14)\n : Math.min(MAX_TOTAL, props.maxLength);\n if (high < low)\n throw new Error(\n \"unable to generate a random hostname satisfying both the format and the length constraints.\",\n );\n return _randomInteger({ type: \"integer\", minimum: low, maximum: high });\n};\n\n/**\n * Builds dot-joined hostname labels totaling exactly `length` characters, each\n * label within 63 chars. Shared with the idn-hostname generator, which realizes\n * its length the same way since #2317 gave the two formats one structure.\n */\nexport const _randomHostnameLabels = (length: number): string => {\n const parts: string[] = [];\n let remaining: number = length;\n while (remaining > MAX_LABEL + 1) {\n // one full label plus its joining dot\n parts.push(random(MAX_LABEL));\n remaining -= MAX_LABEL + 1;\n }\n if (remaining <= MAX_LABEL) parts.push(random(remaining));\n else {\n // remaining === MAX_LABEL + 1: two labels keep every label within 63 chars\n parts.push(random(MAX_LABEL - 1));\n parts.push(random(1));\n }\n return parts.join(\".\");\n};\n\nconst random = (length: number) =>\n _randomString({ type: \"string\", minLength: length, maxLength: length });\n"],"mappings":";;;AAIA,MAAa,yBAAyB,UAAkC;CACtE,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO,GAAG,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC;CAGlC,OAAO,sBAAsB,WAAW,KAAK,CAAC;AAChD;AAEA,MAAM,YAAY;AAClB,MAAM,YAAY;AAElB,MAAM,cAAc,UAAiC;CACnD,IAAI,MAAc,MAAM,cAAc,KAAA,IAAY,IAAI,MAAM;CAC5D,IAAI,MAAM,GAAG,MAAM;CACnB,MAAM,OACJ,MAAM,cAAc,KAAA,IAChB,KAAK,IAAI,WAAW,MAAM,EAAE,IAC5B,KAAK,IAAI,WAAW,MAAM,SAAS;CACzC,IAAI,OAAO,KACT,MAAM,IAAI,MACR,6FACF;CACF,OAAO,eAAe;EAAE,MAAM;EAAW,SAAS;EAAK,SAAS;CAAK,CAAC;AACxE;;;;;;AAOA,MAAa,yBAAyB,WAA2B;CAC/D,MAAM,QAAkB,CAAC;CACzB,IAAI,YAAoB;CACxB,OAAO,YAAY,IAAe;EAEhC,MAAM,KAAK,OAAO,SAAS,CAAC;EAC5B,aAAa;CACf;CACA,IAAI,aAAa,WAAW,MAAM,KAAK,OAAO,SAAS,CAAC;MACnD;EAEH,MAAM,KAAK,OAAO,YAAY,CAAC,CAAC;EAChC,MAAM,KAAK,OAAO,CAAC,CAAC;CACtB;CACA,OAAO,MAAM,KAAK,GAAG;AACvB;AAEA,MAAM,UAAU,WACd,cAAc;CAAE,MAAM;CAAU,WAAW;CAAQ,WAAW;AAAO,CAAC"}
|
|
@@ -7,20 +7,19 @@ const _randomString_1 = require("./_randomString");
|
|
|
7
7
|
const _randomFormatIdnHostname = (props) => {
|
|
8
8
|
if ((props === null || props === void 0 ? void 0 : props.minLength) === undefined && (props === null || props === void 0 ? void 0 : props.maxLength) === undefined)
|
|
9
9
|
return `${random(10)}.${random(3)}`;
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
return
|
|
10
|
+
// idn-hostname shares hostname's structure (a single label of 1..63 chars is
|
|
11
|
+
// valid, no dot or trailing label required), so the requested length is
|
|
12
|
+
// realized the same way: split it across dot-joined labels. #2317 dropped the
|
|
13
|
+
// mandatory dot and two-character trailing label this generator used to
|
|
14
|
+
// reserve, which is why it now realizes a length below four.
|
|
15
|
+
return (0, _randomFormatHostname_1._randomHostnameLabels)(pickLength(props));
|
|
16
16
|
};
|
|
17
17
|
exports._randomFormatIdnHostname = _randomFormatIdnHostname;
|
|
18
18
|
const MAX_TOTAL = 253;
|
|
19
|
-
const MIN_TOTAL = 4; // the shortest idn hostname, `x.yy`: label(1) + `.` + tld(2)
|
|
20
19
|
const pickLength = (props) => {
|
|
21
|
-
let low = props.minLength === undefined ?
|
|
22
|
-
if (low <
|
|
23
|
-
low =
|
|
20
|
+
let low = props.minLength === undefined ? 1 : props.minLength;
|
|
21
|
+
if (low < 1)
|
|
22
|
+
low = 1;
|
|
24
23
|
const high = props.maxLength === undefined
|
|
25
24
|
? Math.min(MAX_TOTAL, low + 14)
|
|
26
25
|
: Math.min(MAX_TOTAL, props.maxLength);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatIdnHostname.js","sourceRoot":"","sources":["../../src/internal/_randomFormatIdnHostname.ts"],"names":[],"mappings":";;;AAA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AAI,GACR,KAAK,CAAC,SAAS,KAAK,SAAS;QAC3B,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,GAAG,EAAE,CAAC;QAC/B,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IAC3C,IAAI,IAAI,GAAG,GAAG;QACZ,MAAM,IAAI,KAAK,CACb,iGAAiG,CAClG,CAAC;IACJ,OAAO,IAAA,+BAAc,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAC1E,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,EAAE,CAChC,IAAA,6BAAa,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC"}
|
|
@@ -4,13 +4,12 @@ import { _randomHostnameLabels } from "./_randomFormatHostname.mjs";
|
|
|
4
4
|
//#region src/internal/_randomFormatIdnHostname.ts
|
|
5
5
|
const _randomFormatIdnHostname = (props) => {
|
|
6
6
|
if (props?.minLength === void 0 && props?.maxLength === void 0) return `${random(10)}.${random(3)}`;
|
|
7
|
-
return
|
|
7
|
+
return _randomHostnameLabels(pickLength(props));
|
|
8
8
|
};
|
|
9
9
|
const MAX_TOTAL = 253;
|
|
10
|
-
const MIN_TOTAL = 4;
|
|
11
10
|
const pickLength = (props) => {
|
|
12
|
-
let low = props.minLength === void 0 ?
|
|
13
|
-
if (low <
|
|
11
|
+
let low = props.minLength === void 0 ? 1 : props.minLength;
|
|
12
|
+
if (low < 1) low = 1;
|
|
14
13
|
const high = props.maxLength === void 0 ? Math.min(MAX_TOTAL, low + 14) : Math.min(MAX_TOTAL, props.maxLength);
|
|
15
14
|
if (high < low) throw new Error("unable to generate a random idn hostname satisfying both the format and the length constraints.");
|
|
16
15
|
return _randomInteger({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatIdnHostname.mjs","names":[],"sources":["../../src/internal/_randomFormatIdnHostname.ts"],"sourcesContent":["import { _randomHostnameLabels } from \"./_randomFormatHostname\";\nimport { _randomInteger } from \"./_randomInteger\";\nimport { _randomString } from \"./_randomString\";\nimport { _ILengthProps } from \"./_randomStringLength\";\n\nexport const _randomFormatIdnHostname = (props?: _ILengthProps): string => {\n if (props?.minLength === undefined && props?.maxLength === undefined)\n return `${random(10)}.${random(3)}`;\n //
|
|
1
|
+
{"version":3,"file":"_randomFormatIdnHostname.mjs","names":[],"sources":["../../src/internal/_randomFormatIdnHostname.ts"],"sourcesContent":["import { _randomHostnameLabels } from \"./_randomFormatHostname\";\nimport { _randomInteger } from \"./_randomInteger\";\nimport { _randomString } from \"./_randomString\";\nimport { _ILengthProps } from \"./_randomStringLength\";\n\nexport const _randomFormatIdnHostname = (props?: _ILengthProps): string => {\n if (props?.minLength === undefined && props?.maxLength === undefined)\n return `${random(10)}.${random(3)}`;\n // idn-hostname shares hostname's structure (a single label of 1..63 chars is\n // valid, no dot or trailing label required), so the requested length is\n // realized the same way: split it across dot-joined labels. #2317 dropped the\n // mandatory dot and two-character trailing label this generator used to\n // reserve, which is why it now realizes a length below four.\n return _randomHostnameLabels(pickLength(props));\n};\n\nconst MAX_TOTAL = 253;\n\nconst pickLength = (props: _ILengthProps): number => {\n let low: number = props.minLength === undefined ? 1 : props.minLength;\n if (low < 1) low = 1;\n const high: number =\n props.maxLength === undefined\n ? Math.min(MAX_TOTAL, low + 14)\n : Math.min(MAX_TOTAL, props.maxLength);\n if (high < low)\n throw new Error(\n \"unable to generate a random idn hostname satisfying both the format and the length constraints.\",\n );\n return _randomInteger({ type: \"integer\", minimum: low, maximum: high });\n};\n\nconst random = (length: number) =>\n _randomString({ type: \"string\", minLength: length, maxLength: length });\n"],"mappings":";;;;AAKA,MAAa,4BAA4B,UAAkC;CACzE,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO,GAAG,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC;CAMlC,OAAO,sBAAsB,WAAW,KAAK,CAAC;AAChD;AAEA,MAAM,YAAY;AAElB,MAAM,cAAc,UAAiC;CACnD,IAAI,MAAc,MAAM,cAAc,KAAA,IAAY,IAAI,MAAM;CAC5D,IAAI,MAAM,GAAG,MAAM;CACnB,MAAM,OACJ,MAAM,cAAc,KAAA,IAChB,KAAK,IAAI,WAAW,MAAM,EAAE,IAC5B,KAAK,IAAI,WAAW,MAAM,SAAS;CACzC,IAAI,OAAO,KACT,MAAM,IAAI,MACR,iGACF;CACF,OAAO,eAAe;EAAE,MAAM;EAAW,SAAS;EAAK,SAAS;CAAK,CAAC;AACxE;AAEA,MAAM,UAAU,WACd,cAAc;CAAE,MAAM;CAAU,WAAW;CAAQ,WAAW;AAAO,CAAC"}
|
|
@@ -4,11 +4,12 @@ exports._randomFormatRegex = void 0;
|
|
|
4
4
|
const _randomString_1 = require("./_randomString");
|
|
5
5
|
const _randomStringLength_1 = require("./_randomStringLength");
|
|
6
6
|
const _randomFormatRegex = (props) => {
|
|
7
|
-
if ((props === null || props === void 0 ? void 0 : props.minLength) === undefined && (props === null || props === void 0 ? void 0 : props.maxLength) === undefined)
|
|
8
|
-
return FIXED;
|
|
9
7
|
// Every character `_randomString` emits is a literal in regular expression
|
|
10
8
|
// syntax, so a source of any length — including the empty source `new
|
|
11
|
-
// RegExp("")` accepts — compiles.
|
|
9
|
+
// RegExp("")` accepts — compiles. An unconstrained draw is therefore an
|
|
10
|
+
// unconstrained string, and a constrained one fixes the length first.
|
|
11
|
+
if ((props === null || props === void 0 ? void 0 : props.minLength) === undefined && (props === null || props === void 0 ? void 0 : props.maxLength) === undefined)
|
|
12
|
+
return (0, _randomString_1._randomString)({ type: "string" });
|
|
12
13
|
const length = (0, _randomStringLength_1._randomLengthPick)((0, _randomStringLength_1._randomLengthWindow)(props, { minimum: 0, spread: 16 }));
|
|
13
14
|
return (0, _randomString_1._randomString)({
|
|
14
15
|
type: "string",
|
|
@@ -17,5 +18,4 @@ const _randomFormatRegex = (props) => {
|
|
|
17
18
|
});
|
|
18
19
|
};
|
|
19
20
|
exports._randomFormatRegex = _randomFormatRegex;
|
|
20
|
-
const FIXED = "/^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)$/";
|
|
21
21
|
//# sourceMappingURL=_randomFormatRegex.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatRegex.js","sourceRoot":"","sources":["../../src/internal/_randomFormatRegex.ts"],"names":[],"mappings":";;;AAAA,mDAAgD;AAChD,+DAI+B;AAExB,MAAM,kBAAkB,GAAG,CAAC,KAAqB,EAAU,EAAE;IAClE,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS;QAClE,OAAO,
|
|
1
|
+
{"version":3,"file":"_randomFormatRegex.js","sourceRoot":"","sources":["../../src/internal/_randomFormatRegex.ts"],"names":[],"mappings":";;;AAAA,mDAAgD;AAChD,+DAI+B;AAExB,MAAM,kBAAkB,GAAG,CAAC,KAAqB,EAAU,EAAE;IAClE,2EAA2E;IAC3E,sEAAsE;IACtE,wEAAwE;IACxE,sEAAsE;IACtE,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS;QAClE,OAAO,IAAA,6BAAa,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAW,IAAA,uCAAiB,EACtC,IAAA,yCAAmB,EAAC,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CACvD,CAAC;IACF,OAAO,IAAA,6BAAa,EAAC;QACnB,IAAI,EAAE,QAAQ;QACd,SAAS,EAAE,MAAM;QACjB,SAAS,EAAE,MAAM;KAClB,CAAC,CAAC;AACL,CAAC,CAAC;AAfW,QAAA,kBAAkB,GAAlB,kBAAkB,CAe7B"}
|
|
@@ -2,7 +2,7 @@ import { _randomString } from "./_randomString.mjs";
|
|
|
2
2
|
import { _randomLengthPick, _randomLengthWindow } from "./_randomStringLength.mjs";
|
|
3
3
|
//#region src/internal/_randomFormatRegex.ts
|
|
4
4
|
const _randomFormatRegex = (props) => {
|
|
5
|
-
if (props?.minLength === void 0 && props?.maxLength === void 0) return
|
|
5
|
+
if (props?.minLength === void 0 && props?.maxLength === void 0) return _randomString({ type: "string" });
|
|
6
6
|
const length = _randomLengthPick(_randomLengthWindow(props, {
|
|
7
7
|
minimum: 0,
|
|
8
8
|
spread: 16
|
|
@@ -13,7 +13,6 @@ const _randomFormatRegex = (props) => {
|
|
|
13
13
|
maxLength: length
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
|
-
const FIXED = "/^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)$/";
|
|
17
16
|
//#endregion
|
|
18
17
|
export { _randomFormatRegex };
|
|
19
18
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatRegex.mjs","names":[],"sources":["../../src/internal/_randomFormatRegex.ts"],"sourcesContent":["import { _randomString } from \"./_randomString\";\nimport {\n _ILengthProps,\n _randomLengthPick,\n _randomLengthWindow,\n} from \"./_randomStringLength\";\n\nexport const _randomFormatRegex = (props?: _ILengthProps): string => {\n
|
|
1
|
+
{"version":3,"file":"_randomFormatRegex.mjs","names":[],"sources":["../../src/internal/_randomFormatRegex.ts"],"sourcesContent":["import { _randomString } from \"./_randomString\";\nimport {\n _ILengthProps,\n _randomLengthPick,\n _randomLengthWindow,\n} from \"./_randomStringLength\";\n\nexport const _randomFormatRegex = (props?: _ILengthProps): string => {\n // Every character `_randomString` emits is a literal in regular expression\n // syntax, so a source of any length — including the empty source `new\n // RegExp(\"\")` accepts — compiles. An unconstrained draw is therefore an\n // unconstrained string, and a constrained one fixes the length first.\n if (props?.minLength === undefined && props?.maxLength === undefined)\n return _randomString({ type: \"string\" });\n const length: number = _randomLengthPick(\n _randomLengthWindow(props, { minimum: 0, spread: 16 }),\n );\n return _randomString({\n type: \"string\",\n minLength: length,\n maxLength: length,\n });\n};\n"],"mappings":";;;AAOA,MAAa,sBAAsB,UAAkC;CAKnE,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO,cAAc,EAAE,MAAM,SAAS,CAAC;CACzC,MAAM,SAAiB,kBACrB,oBAAoB,OAAO;EAAE,SAAS;EAAG,QAAQ;CAAG,CAAC,CACvD;CACA,OAAO,cAAc;EACnB,MAAM;EACN,WAAW;EACX,WAAW;CACb,CAAC;AACH"}
|
|
@@ -9,12 +9,11 @@ const _randomFormatTime = (props) => {
|
|
|
9
9
|
if ((props === null || props === void 0 ? void 0 : props.minLength) === undefined && (props === null || props === void 0 ? void 0 : props.maxLength) === undefined)
|
|
10
10
|
return clock().substring(11);
|
|
11
11
|
// `HH:MM:SS` carries a mandatory offset — one character as `Z`, six as
|
|
12
|
-
// `+HH:MM` — and an optional fraction
|
|
13
|
-
// Together they express 9 and every length from 11
|
|
14
|
-
// gap, because a fraction needs both a dot and a digit.
|
|
12
|
+
// `+HH:MM` — and an optional fraction between them that RFC 3339 leaves
|
|
13
|
+
// open above. Together they express 9 and every length from 11 upward; 10 is
|
|
14
|
+
// the one gap, because a fraction needs both a dot and a digit.
|
|
15
15
|
const window = (0, _randomStringLength_1._randomLengthWindow)(props, {
|
|
16
16
|
minimum: CLOCK + 1,
|
|
17
|
-
maximum: CLOCK + 1 + FRACTION_MAX + OFFSET,
|
|
18
17
|
spread: 6,
|
|
19
18
|
});
|
|
20
19
|
let length = (0, _randomStringLength_1._randomLengthPick)(window);
|
|
@@ -25,17 +24,23 @@ const _randomFormatTime = (props) => {
|
|
|
25
24
|
const base = clock().substring(11, 11 + CLOCK);
|
|
26
25
|
if (length === CLOCK + 1)
|
|
27
26
|
return `${base}Z`;
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
// The `Z` form reaches every remaining length by itself, so the numeric
|
|
28
|
+
// offset is a choice rather than a fallback: it spends six characters, which
|
|
29
|
+
// leaves either nothing (14, `HH:MM:SS+HH:MM`) or a whole fraction (16 and
|
|
30
|
+
// up). At 15 only the `Z` form fits, since the offset would demand a dot
|
|
31
|
+
// with no digit after it.
|
|
32
|
+
const fraction = length - CLOCK - OFFSET - 1;
|
|
33
|
+
return (fraction === -1 || fraction >= 1) &&
|
|
34
|
+
(0, _randomInteger_1._randomInteger)({ type: "integer", minimum: 0, maximum: 1 }) === 1
|
|
35
|
+
? fraction === -1
|
|
36
|
+
? `${base}${offset()}`
|
|
37
|
+
: `${base}.${(0, __randomComposition_1.__randomDigits)(fraction)}${offset()}`
|
|
38
|
+
: `${base}.${(0, __randomComposition_1.__randomDigits)(length - CLOCK - 2)}Z`;
|
|
33
39
|
};
|
|
34
40
|
exports._randomFormatTime = _randomFormatTime;
|
|
35
41
|
const DAY = 86400000;
|
|
36
42
|
const CLOCK = "00:00:00".length;
|
|
37
43
|
const OFFSET = "+00:00".length;
|
|
38
|
-
const FRACTION_MAX = 9;
|
|
39
44
|
const offset = () => `${(0, _randomInteger_1._randomInteger)({ type: "integer", minimum: 0, maximum: 1 }) === 0 ? "+" : "-"}${pad((0, _randomInteger_1._randomInteger)({ type: "integer", minimum: 0, maximum: 23 }))}:${pad((0, _randomInteger_1._randomInteger)({ type: "integer", minimum: 0, maximum: 59 }))}`;
|
|
40
45
|
const pad = (value) => String(value).padStart(2, "0");
|
|
41
46
|
//# sourceMappingURL=_randomFormatTime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatTime.js","sourceRoot":"","sources":["../../src/internal/_randomFormatTime.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAClD,+DAK+B;AAC/B,uEAA+D;AAExD,MAAM,iBAAiB,GAAG,CAAC,KAAqB,EAAU,EAAE;IACjE,MAAM,KAAK,GAAG,GAAW,EAAE,CACzB,IAAI,IAAI,CACN,IAAA,+BAAc,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAC9D,CAAC,WAAW,EAAE,CAAC;IAClB,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS;QAClE,OAAO,KAAK,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAC/B,uEAAuE;IACvE,
|
|
1
|
+
{"version":3,"file":"_randomFormatTime.js","sourceRoot":"","sources":["../../src/internal/_randomFormatTime.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAClD,+DAK+B;AAC/B,uEAA+D;AAExD,MAAM,iBAAiB,GAAG,CAAC,KAAqB,EAAU,EAAE;IACjE,MAAM,KAAK,GAAG,GAAW,EAAE,CACzB,IAAI,IAAI,CACN,IAAA,+BAAc,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAC9D,CAAC,WAAW,EAAE,CAAC;IAClB,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS;QAClE,OAAO,KAAK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B,CAAC,CAAC,GAAG,IAAI,IAAI,IAAA,oCAAc,EAAC,QAAQ,CAAC,GAAG,MAAM,EAAE,EAAE;QACpD,CAAC,CAAC,GAAG,IAAI,IAAI,IAAA,oCAAc,EAAC,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC;AACvD,CAAC,CAAC;AAlCW,QAAA,iBAAiB,GAAjB,iBAAiB,CAkC5B;AAEF,MAAM,GAAG,GAAG,QAAU,CAAC;AACvB,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC;AAChC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;AAE/B,MAAM,MAAM,GAAG,GAAW,EAAE,CAC1B,GAAG,IAAA,+BAAc,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CACpF,IAAA,+BAAc,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAC7D,IAAI,GAAG,CAAC,IAAA,+BAAc,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC;AAE3E,MAAM,GAAG,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC"}
|
|
@@ -11,7 +11,6 @@ const _randomFormatTime = (props) => {
|
|
|
11
11
|
if (props?.minLength === void 0 && props?.maxLength === void 0) return clock().substring(11);
|
|
12
12
|
const window = _randomLengthWindow(props, {
|
|
13
13
|
minimum: CLOCK + 1,
|
|
14
|
-
maximum: CLOCK + 1 + FRACTION_MAX + OFFSET,
|
|
15
14
|
spread: 6
|
|
16
15
|
});
|
|
17
16
|
let length = _randomLengthPick(window);
|
|
@@ -19,12 +18,16 @@ const _randomFormatTime = (props) => {
|
|
|
19
18
|
if (length < window.low || length > window.high) throw new Error(_RANDOM_LENGTH_ERROR);
|
|
20
19
|
const base = clock().substring(11, 11 + CLOCK);
|
|
21
20
|
if (length === CLOCK + 1) return `${base}Z`;
|
|
22
|
-
|
|
21
|
+
const fraction = length - CLOCK - OFFSET - 1;
|
|
22
|
+
return (fraction === -1 || fraction >= 1) && _randomInteger({
|
|
23
|
+
type: "integer",
|
|
24
|
+
minimum: 0,
|
|
25
|
+
maximum: 1
|
|
26
|
+
}) === 1 ? fraction === -1 ? `${base}${offset()}` : `${base}.${__randomDigits(fraction)}${offset()}` : `${base}.${__randomDigits(length - CLOCK - 2)}Z`;
|
|
23
27
|
};
|
|
24
28
|
const DAY = 864e5;
|
|
25
29
|
const CLOCK = 8;
|
|
26
30
|
const OFFSET = 6;
|
|
27
|
-
const FRACTION_MAX = 9;
|
|
28
31
|
const offset = () => `${_randomInteger({
|
|
29
32
|
type: "integer",
|
|
30
33
|
minimum: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatTime.mjs","names":[],"sources":["../../src/internal/_randomFormatTime.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport {\n _ILengthProps,\n _RANDOM_LENGTH_ERROR,\n _randomLengthPick,\n _randomLengthWindow,\n} from \"./_randomStringLength\";\nimport { __randomDigits } from \"./private/__randomComposition\";\n\nexport const _randomFormatTime = (props?: _ILengthProps): string => {\n const clock = (): string =>\n new Date(\n _randomInteger({ type: \"integer\", minimum: 0, maximum: DAY }),\n ).toISOString();\n if (props?.minLength === undefined && props?.maxLength === undefined)\n return clock().substring(11);\n // `HH:MM:SS` carries a mandatory offset — one character as `Z`, six as\n // `+HH:MM` — and an optional fraction
|
|
1
|
+
{"version":3,"file":"_randomFormatTime.mjs","names":[],"sources":["../../src/internal/_randomFormatTime.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport {\n _ILengthProps,\n _RANDOM_LENGTH_ERROR,\n _randomLengthPick,\n _randomLengthWindow,\n} from \"./_randomStringLength\";\nimport { __randomDigits } from \"./private/__randomComposition\";\n\nexport const _randomFormatTime = (props?: _ILengthProps): string => {\n const clock = (): string =>\n new Date(\n _randomInteger({ type: \"integer\", minimum: 0, maximum: DAY }),\n ).toISOString();\n if (props?.minLength === undefined && props?.maxLength === undefined)\n return clock().substring(11);\n // `HH:MM:SS` carries a mandatory offset — one character as `Z`, six as\n // `+HH:MM` — and an optional fraction between them that RFC 3339 leaves\n // open above. Together they express 9 and every length from 11 upward; 10 is\n // the one gap, because a fraction needs both a dot and a digit.\n const window = _randomLengthWindow(props, {\n minimum: CLOCK + 1,\n spread: 6,\n });\n let length: number = _randomLengthPick(window);\n if (length === CLOCK + 2)\n length = window.high >= CLOCK + 3 ? CLOCK + 3 : CLOCK + 1;\n if (length < window.low || length > window.high)\n throw new Error(_RANDOM_LENGTH_ERROR);\n const base: string = clock().substring(11, 11 + CLOCK);\n if (length === CLOCK + 1) return `${base}Z`;\n // The `Z` form reaches every remaining length by itself, so the numeric\n // offset is a choice rather than a fallback: it spends six characters, which\n // leaves either nothing (14, `HH:MM:SS+HH:MM`) or a whole fraction (16 and\n // up). At 15 only the `Z` form fits, since the offset would demand a dot\n // with no digit after it.\n const fraction: number = length - CLOCK - OFFSET - 1;\n return (fraction === -1 || fraction >= 1) &&\n _randomInteger({ type: \"integer\", minimum: 0, maximum: 1 }) === 1\n ? fraction === -1\n ? `${base}${offset()}`\n : `${base}.${__randomDigits(fraction)}${offset()}`\n : `${base}.${__randomDigits(length - CLOCK - 2)}Z`;\n};\n\nconst DAY = 86_400_000;\nconst CLOCK = \"00:00:00\".length;\nconst OFFSET = \"+00:00\".length;\n\nconst offset = (): string =>\n `${_randomInteger({ type: \"integer\", minimum: 0, maximum: 1 }) === 0 ? \"+\" : \"-\"}${pad(\n _randomInteger({ type: \"integer\", minimum: 0, maximum: 23 }),\n )}:${pad(_randomInteger({ type: \"integer\", minimum: 0, maximum: 59 }))}`;\n\nconst pad = (value: number): string => String(value).padStart(2, \"0\");\n"],"mappings":";;;;AASA,MAAa,qBAAqB,UAAkC;CAClE,MAAM,cACJ,IAAI,KACF,eAAe;EAAE,MAAM;EAAW,SAAS;EAAG,SAAS;CAAI,CAAC,CAC9D,CAAC,CAAC,YAAY;CAChB,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO,MAAM,CAAC,CAAC,UAAU,EAAE;CAK7B,MAAM,SAAS,oBAAoB,OAAO;EACxC,SAAS,QAAQ;EACjB,QAAQ;CACV,CAAC;CACD,IAAI,SAAiB,kBAAkB,MAAM;CAC7C,IAAI,WAAW,QAAQ,GACrB,SAAS,OAAO,QAAQ,QAAQ,IAAI,QAAQ,IAAI,QAAQ;CAC1D,IAAI,SAAS,OAAO,OAAO,SAAS,OAAO,MACzC,MAAM,IAAI,MAAM,oBAAoB;CACtC,MAAM,OAAe,MAAM,CAAC,CAAC,UAAU,IAAI,KAAK,KAAK;CACrD,IAAI,WAAW,QAAQ,GAAG,OAAO,GAAG,KAAK;CAMzC,MAAM,WAAmB,SAAS,QAAQ,SAAS;CACnD,QAAQ,aAAa,MAAM,YAAY,MACrC,eAAe;EAAE,MAAM;EAAW,SAAS;EAAG,SAAS;CAAE,CAAC,MAAM,IAC9D,aAAa,KACX,GAAG,OAAO,OAAO,MACjB,GAAG,KAAK,GAAG,eAAe,QAAQ,IAAI,OAAO,MAC/C,GAAG,KAAK,GAAG,eAAe,SAAS,QAAQ,CAAC,EAAE;AACpD;AAEA,MAAM,MAAM;AACZ,MAAM,QAAQ;AACd,MAAM,SAAS;AAEf,MAAM,eACJ,GAAG,eAAe;CAAE,MAAM;CAAW,SAAS;CAAG,SAAS;AAAE,CAAC,MAAM,IAAI,MAAM,MAAM,IACjF,eAAe;CAAE,MAAM;CAAW,SAAS;CAAG,SAAS;AAAG,CAAC,CAC7D,EAAE,GAAG,IAAI,eAAe;CAAE,MAAM;CAAW,SAAS;CAAG,SAAS;AAAG,CAAC,CAAC;AAEvE,MAAM,OAAO,UAA0B,OAAO,KAAK,CAAC,CAAC,SAAS,GAAG,GAAG"}
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports._randomPattern = void 0;
|
|
7
7
|
const randexp_1 = __importDefault(require("randexp"));
|
|
8
|
+
const _stringLength_1 = require("./_stringLength");
|
|
8
9
|
const _randomPattern = (regex, props) => {
|
|
9
10
|
const r = new randexp_1.default(regex);
|
|
10
11
|
const min = props === null || props === void 0 ? void 0 : props.minLength;
|
|
@@ -16,13 +17,29 @@ const _randomPattern = (regex, props) => {
|
|
|
16
17
|
r.max = max;
|
|
17
18
|
else if (min !== undefined && min * 2 > r.max)
|
|
18
19
|
r.max = min * 2;
|
|
20
|
+
// The verification counts characters, not UTF-16 code units, because that is
|
|
21
|
+
// what `MinLength` and `MaxLength` compare against. `Pattern` compiles to a
|
|
22
|
+
// flagless `RegExp`, so a quantifier binds one code unit wherever its atom is
|
|
23
|
+
// a bare astral character: under `^😀+$` the `+` repeats the trailing low
|
|
24
|
+
// surrogate alone, and RandExp draws `\ud83d` + k * `\ude00` -- k characters
|
|
25
|
+
// in k + 1 code units. Measuring in code units accepted a two-character draw
|
|
26
|
+
// for `MinLength<3>` and handed back a value the generated validator rejects.
|
|
27
|
+
// Group the atom (`^(?:😀)+$`) and the arithmetic changes to 2k units for k
|
|
28
|
+
// characters; the two counts still differ, which is the point.
|
|
29
|
+
//
|
|
30
|
+
// The count is taken only after the pattern matches, and only when a bound
|
|
31
|
+
// exists, so an unbounded draw still walks nothing.
|
|
19
32
|
const bounded = min !== undefined || max !== undefined;
|
|
20
33
|
const limit = bounded ? 1024 : 10;
|
|
21
34
|
for (let i = 0; i < limit; ++i) {
|
|
22
35
|
const str = r.gen();
|
|
23
|
-
if (regex.test(str)
|
|
24
|
-
|
|
25
|
-
|
|
36
|
+
if (regex.test(str) === false)
|
|
37
|
+
continue;
|
|
38
|
+
if (bounded === false)
|
|
39
|
+
return str;
|
|
40
|
+
const length = (0, _stringLength_1._stringLength)(str);
|
|
41
|
+
if ((min === undefined || length >= min) &&
|
|
42
|
+
(max === undefined || length <= max))
|
|
26
43
|
return str;
|
|
27
44
|
}
|
|
28
45
|
throw new Error(bounded
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomPattern.js","sourceRoot":"","sources":["../../src/internal/_randomPattern.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;
|
|
1
|
+
{"version":3,"file":"_randomPattern.js","sourceRoot":"","sources":["../../src/internal/_randomPattern.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAG9B,mDAAgD;AAEzC,MAAM,cAAc,GAAG,CAC5B,KAAa,EACb,KAAqB,EACb,EAAE;IACV,MAAM,CAAC,GAAY,IAAI,iBAAO,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,GAAG,GAAuB,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,CAAC;IACjD,MAAM,GAAG,GAAuB,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,CAAC;IAEjD,6EAA6E;IAC7E,8EAA8E;IAC9E,6EAA6E;IAC7E,IAAI,GAAG,KAAK,SAAS;QAAE,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;SAC9B,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG;QAAE,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;IAE/D,6EAA6E;IAC7E,4EAA4E;IAC5E,8EAA8E;IAC9E,0EAA0E;IAC1E,6EAA6E;IAC7E,6EAA6E;IAC7E,8EAA8E;IAC9E,4EAA4E;IAC5E,+DAA+D;IAC/D,EAAE;IACF,2EAA2E;IAC3E,oDAAoD;IACpD,MAAM,OAAO,GAAY,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,SAAS,CAAC;IAChE,MAAM,KAAK,GAAW,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1C,KAAK,IAAI,CAAC,GAAW,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC;QACvC,MAAM,GAAG,GAAW,CAAC,CAAC,GAAG,EAAE,CAAC;QAC5B,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK;YAAE,SAAS;QACxC,IAAI,OAAO,KAAK,KAAK;YAAE,OAAO,GAAG,CAAC;QAClC,MAAM,MAAM,GAAW,IAAA,6BAAa,EAAC,GAAG,CAAC,CAAC;QAC1C,IACE,CAAC,GAAG,KAAK,SAAS,IAAI,MAAM,IAAI,GAAG,CAAC;YACpC,CAAC,GAAG,KAAK,SAAS,IAAI,MAAM,IAAI,GAAG,CAAC;YAEpC,OAAO,GAAG,CAAC;IACf,CAAC;IACD,MAAM,IAAI,KAAK,CACb,OAAO;QACL,CAAC,CAAC,kFAAkF;QACpF,CAAC,CAAC,0DAA0D,CAC/D,CAAC;AACJ,CAAC,CAAC;AA5CW,QAAA,cAAc,GAAd,cAAc,CA4CzB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _stringLength } from "./_stringLength.mjs";
|
|
1
2
|
import RandExp from "randexp";
|
|
2
3
|
//#region src/internal/_randomPattern.ts
|
|
3
4
|
const _randomPattern = (regex, props) => {
|
|
@@ -10,7 +11,10 @@ const _randomPattern = (regex, props) => {
|
|
|
10
11
|
const limit = bounded ? 1024 : 10;
|
|
11
12
|
for (let i = 0; i < limit; ++i) {
|
|
12
13
|
const str = r.gen();
|
|
13
|
-
if (regex.test(str)
|
|
14
|
+
if (regex.test(str) === false) continue;
|
|
15
|
+
if (bounded === false) return str;
|
|
16
|
+
const length = _stringLength(str);
|
|
17
|
+
if ((min === void 0 || length >= min) && (max === void 0 || length <= max)) return str;
|
|
14
18
|
}
|
|
15
19
|
throw new Error(bounded ? "unable to generate a random string matching the pattern within the length range." : "unable to generate a random string matching the pattern.");
|
|
16
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomPattern.mjs","names":[],"sources":["../../src/internal/_randomPattern.ts"],"sourcesContent":["import RandExp from \"randexp\";\n\nimport { _ILengthProps } from \"./_randomStringLength\";\n\nexport const _randomPattern = (\n regex: RegExp,\n props?: _ILengthProps,\n): string => {\n const r: RandExp = new RandExp(regex);\n const min: number | undefined = props?.minLength;\n const max: number | undefined = props?.maxLength;\n\n // RandExp expands an unbounded quantifier to `randInt(token.min, token.min +\n // r.max)`, so steering `r.max` biases the generated length toward the window.\n // There is no matching floor control, so the length is still verified below.\n if (max !== undefined) r.max = max;\n else if (min !== undefined && min * 2 > r.max) r.max = min * 2;\n\n const bounded: boolean = min !== undefined || max !== undefined;\n const limit: number = bounded ? 1024 : 10;\n for (let i: number = 0; i < limit; ++i) {\n const str: string = r.gen();\n if (
|
|
1
|
+
{"version":3,"file":"_randomPattern.mjs","names":[],"sources":["../../src/internal/_randomPattern.ts"],"sourcesContent":["import RandExp from \"randexp\";\n\nimport { _ILengthProps } from \"./_randomStringLength\";\nimport { _stringLength } from \"./_stringLength\";\n\nexport const _randomPattern = (\n regex: RegExp,\n props?: _ILengthProps,\n): string => {\n const r: RandExp = new RandExp(regex);\n const min: number | undefined = props?.minLength;\n const max: number | undefined = props?.maxLength;\n\n // RandExp expands an unbounded quantifier to `randInt(token.min, token.min +\n // r.max)`, so steering `r.max` biases the generated length toward the window.\n // There is no matching floor control, so the length is still verified below.\n if (max !== undefined) r.max = max;\n else if (min !== undefined && min * 2 > r.max) r.max = min * 2;\n\n // The verification counts characters, not UTF-16 code units, because that is\n // what `MinLength` and `MaxLength` compare against. `Pattern` compiles to a\n // flagless `RegExp`, so a quantifier binds one code unit wherever its atom is\n // a bare astral character: under `^😀+$` the `+` repeats the trailing low\n // surrogate alone, and RandExp draws `\\ud83d` + k * `\\ude00` -- k characters\n // in k + 1 code units. Measuring in code units accepted a two-character draw\n // for `MinLength<3>` and handed back a value the generated validator rejects.\n // Group the atom (`^(?:😀)+$`) and the arithmetic changes to 2k units for k\n // characters; the two counts still differ, which is the point.\n //\n // The count is taken only after the pattern matches, and only when a bound\n // exists, so an unbounded draw still walks nothing.\n const bounded: boolean = min !== undefined || max !== undefined;\n const limit: number = bounded ? 1024 : 10;\n for (let i: number = 0; i < limit; ++i) {\n const str: string = r.gen();\n if (regex.test(str) === false) continue;\n if (bounded === false) return str;\n const length: number = _stringLength(str);\n if (\n (min === undefined || length >= min) &&\n (max === undefined || length <= max)\n )\n return str;\n }\n throw new Error(\n bounded\n ? \"unable to generate a random string matching the pattern within the length range.\"\n : \"unable to generate a random string matching the pattern.\",\n );\n};\n"],"mappings":";;;AAKA,MAAa,kBACX,OACA,UACW;CACX,MAAM,IAAa,IAAI,QAAQ,KAAK;CACpC,MAAM,MAA0B,OAAO;CACvC,MAAM,MAA0B,OAAO;CAKvC,IAAI,QAAQ,KAAA,GAAW,EAAE,MAAM;MAC1B,IAAI,QAAQ,KAAA,KAAa,MAAM,IAAI,EAAE,KAAK,EAAE,MAAM,MAAM;CAc7D,MAAM,UAAmB,QAAQ,KAAA,KAAa,QAAQ,KAAA;CACtD,MAAM,QAAgB,UAAU,OAAO;CACvC,KAAK,IAAI,IAAY,GAAG,IAAI,OAAO,EAAE,GAAG;EACtC,MAAM,MAAc,EAAE,IAAI;EAC1B,IAAI,MAAM,KAAK,GAAG,MAAM,OAAO;EAC/B,IAAI,YAAY,OAAO,OAAO;EAC9B,MAAM,SAAiB,cAAc,GAAG;EACxC,KACG,QAAQ,KAAA,KAAa,UAAU,SAC/B,QAAQ,KAAA,KAAa,UAAU,MAEhC,OAAO;CACX;CACA,MAAM,IAAI,MACR,UACI,qFACA,0DACN;AACF"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports._randomFormatLength = exports._randomLengthPick = exports._randomLengthWindow = exports._randomSegmentLength = exports._RANDOM_LENGTH_ERROR = void 0;
|
|
4
4
|
const _randomInteger_1 = require("./_randomInteger");
|
|
5
5
|
const _randomString_1 = require("./_randomString");
|
|
6
|
+
const _stringLength_1 = require("./_stringLength");
|
|
6
7
|
exports._RANDOM_LENGTH_ERROR = "unable to generate a random string satisfying both the format and the length constraints.";
|
|
7
8
|
/**
|
|
8
9
|
* Builds the variable segment of a fixed-shape format string so that the total
|
|
@@ -74,8 +75,14 @@ const _randomFormatLength = (props, generate) => {
|
|
|
74
75
|
return generate();
|
|
75
76
|
for (let i = 0; i < 256; ++i) {
|
|
76
77
|
const value = generate();
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
// Characters, not UTF-16 code units: `minLength` and `maxLength` are the
|
|
79
|
+
// bounds the generated validator compares in characters. `uuid` and `date`,
|
|
80
|
+
// the only two shapes routed through here, are ASCII, so the two counts
|
|
81
|
+
// agree for them today -- this keeps one measure so a later non-ASCII
|
|
82
|
+
// format cannot reintroduce the divergence unnoticed.
|
|
83
|
+
const length = (0, _stringLength_1._stringLength)(value);
|
|
84
|
+
if ((props.minLength === undefined || length >= props.minLength) &&
|
|
85
|
+
(props.maxLength === undefined || length <= props.maxLength))
|
|
79
86
|
return value;
|
|
80
87
|
}
|
|
81
88
|
throw new Error(exports._RANDOM_LENGTH_ERROR);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomStringLength.js","sourceRoot":"","sources":["../../src/internal/_randomStringLength.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAClD,mDAAgD;AAEnC,QAAA,oBAAoB,GAC/B,2FAA2F,CAAC;AAe9F;;;;;;;;;GASG;AACI,MAAM,oBAAoB,GAAG,CAClC,KAAgC,EAChC,KAAa,EACb,QAAgB,EAChB,OAAe,EACP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ACF,IAAI,GAAG,GAAG,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,QAAA,oBAAoB,CAAC,CAAC;IACtD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;AACvB,CAAC,CAAC;AAfW,QAAA,mBAAmB,GAAnB,mBAAmB,CAe9B;AAEF,8EAA8E;AACvE,MAAM,iBAAiB,GAAG,CAAC,MAGjC,EAAU,EAAE,CACX,IAAA,+BAAc,EAAC;IACb,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,MAAM,CAAC,GAAG;IACnB,OAAO,EAAE,MAAM,CAAC,IAAI;CACrB,CAAC,CAAC;AARQ,QAAA,iBAAiB,GAAjB,iBAAiB,CAQzB;AAEL;;;;;;;;;GASG;AACI,MAAM,mBAAmB,GAAG,CACjC,KAAgC,EAChC,QAAsB,EACd,EAAE;IACV,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS;QAClE,OAAO,QAAQ,EAAE,CAAC;IACpB,KAAK,IAAI,CAAC,GAAW,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC;QACrC,MAAM,KAAK,GAAW,QAAQ,EAAE,CAAC;QACjC,IACE,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,
|
|
1
|
+
{"version":3,"file":"_randomStringLength.js","sourceRoot":"","sources":["../../src/internal/_randomStringLength.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAClD,mDAAgD;AAChD,mDAAgD;AAEnC,QAAA,oBAAoB,GAC/B,2FAA2F,CAAC;AAe9F;;;;;;;;;GASG;AACI,MAAM,oBAAoB,GAAG,CAClC,KAAgC,EAChC,KAAa,EACb,QAAgB,EAChB,OAAe,EACP,EAAE;IACV,IAAI,GAAG,GACL,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SA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5 +1,6 @@
|
|
|
1
1
|
import { _randomInteger } from "./_randomInteger.mjs";
|
|
2
2
|
import { _randomString } from "./_randomString.mjs";
|
|
3
|
+
import { _stringLength } from "./_stringLength.mjs";
|
|
3
4
|
//#region src/internal/_randomStringLength.ts
|
|
4
5
|
const _RANDOM_LENGTH_ERROR = "unable to generate a random string satisfying both the format and the length constraints.";
|
|
5
6
|
/**
|
|
@@ -69,7 +70,8 @@ const _randomFormatLength = (props, generate) => {
|
|
|
69
70
|
if (props?.minLength === void 0 && props?.maxLength === void 0) return generate();
|
|
70
71
|
for (let i = 0; i < 256; ++i) {
|
|
71
72
|
const value = generate();
|
|
72
|
-
|
|
73
|
+
const length = _stringLength(value);
|
|
74
|
+
if ((props.minLength === void 0 || length >= props.minLength) && (props.maxLength === void 0 || length <= props.maxLength)) return value;
|
|
73
75
|
}
|
|
74
76
|
throw new Error(_RANDOM_LENGTH_ERROR);
|
|
75
77
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomStringLength.mjs","names":[],"sources":["../../src/internal/_randomStringLength.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport { _randomString } from \"./_randomString\";\n\nexport const _RANDOM_LENGTH_ERROR =\n \"unable to generate a random string satisfying both the format and the length constraints.\";\n\n/**\n * Length bounds forwarded to a string format or pattern generator.\n *\n * `typia.random<T>()` passes this object to the `_randomFormat*` and\n * `_randomPattern` helpers whenever the string leaf also carries a `MinLength`\n * or `MaxLength` tag, so a constrained format or pattern is generated at a\n * length its own validator accepts (issue #2189).\n */\nexport interface _ILengthProps {\n minLength?: number;\n maxLength?: number;\n}\n\n/**\n * Builds the variable segment of a fixed-shape format string so that the total\n * length `fixed + segment.length` lands inside the requested window.\n *\n * `fixed` is the number of characters the format always contributes around the\n * segment, `fallback` is the segment length used when the leaf is unconstrained\n * on that side, and `minimum` is the smallest segment the format still\n * validates with. Throws when the window cannot be satisfied by this format's\n * shape (e.g. `Format<\"email\"> & MaxLength<3>`).\n */\nexport const _randomSegmentLength = (\n props: _ILengthProps | undefined,\n fixed: number,\n fallback: number,\n minimum: number,\n): string => {\n let low: number =\n props?.minLength === undefined ? minimum : props.minLength - fixed;\n if (low < minimum) low = minimum;\n // With only a lower bound, spread the segment across `fallback` extra\n // characters so the generated length varies, mirroring `_randomString`.\n const high: number =\n props?.maxLength === undefined ? low + fallback : props.maxLength - fixed;\n if (high < low || high < minimum) throw new Error(_RANDOM_LENGTH_ERROR);\n return _randomString({ type: \"string\", minLength: low, maxLength: high });\n};\n\n/**\n * Intersects the requested length window with the lengths a format's grammar\n * can express, and draws one of them.\n *\n * `minimum` and `maximum` are the shortest and longest values the format admits\n * — omit `maximum` when the grammar is open above — and `spread` is how far\n * past the floor an unbounded request may reach, so an open side still varies\n * the way `_randomString` does. The caller draws from the returned window and\n * applies whatever step its grammar has (base64 lengths are multiples of four,\n * a fractional second needs at least one digit).\n *\n * Throws only when the window and the grammar do not overlap at all. That is\n * the distinction the retry driver below cannot make: it redraws one shape, so\n * it gives up on every length that shape never emits even when the format\n * itself accepts one (issue #2284).\n */\nexport const _randomLengthWindow = (\n props: _ILengthProps | undefined,\n format: { minimum: number; maximum?: number; spread?: number },\n): { low: number; high: number } => {\n const ceiling: number = format.maximum ?? Number.MAX_SAFE_INTEGER;\n const low: number = Math.max(\n props?.minLength ?? format.minimum,\n format.minimum,\n );\n const high: number = Math.min(\n props?.maxLength ?? low + (format.spread ?? 0),\n ceiling,\n );\n if (low > high) throw new Error(_RANDOM_LENGTH_ERROR);\n return { low, high };\n};\n\n/** Draws a length inside a window produced by {@link _randomLengthWindow}. */\nexport const _randomLengthPick = (window: {\n low: number;\n high: number;\n}): number =>\n _randomInteger({\n type: \"integer\",\n minimum: window.low,\n maximum: window.high,\n });\n\n/**\n * Wraps a fixed-length format generator (uuid, date) with the requested length\n * window.\n *\n * Use it only where the grammar admits exactly one length, so a window that\n * excludes it is genuinely unsatisfiable. A format that can express more than\n * one length must build its value at a length drawn from\n * {@link _randomLengthWindow} instead; redrawing one shape cannot reach a length\n * that shape never emits.\n */\nexport const _randomFormatLength = (\n props: _ILengthProps | undefined,\n generate: () => string,\n): string => {\n if (props?.minLength === undefined && props?.maxLength === undefined)\n return generate();\n for (let i: number = 0; i < 256; ++i) {\n const value: string = generate();\n if (\n (props.minLength === undefined ||
|
|
1
|
+
{"version":3,"file":"_randomStringLength.mjs","names":[],"sources":["../../src/internal/_randomStringLength.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport { _randomString } from \"./_randomString\";\nimport { _stringLength } from \"./_stringLength\";\n\nexport const _RANDOM_LENGTH_ERROR =\n \"unable to generate a random string satisfying both the format and the length constraints.\";\n\n/**\n * Length bounds forwarded to a string format or pattern generator.\n *\n * `typia.random<T>()` passes this object to the `_randomFormat*` and\n * `_randomPattern` helpers whenever the string leaf also carries a `MinLength`\n * or `MaxLength` tag, so a constrained format or pattern is generated at a\n * length its own validator accepts (issue #2189).\n */\nexport interface _ILengthProps {\n minLength?: number;\n maxLength?: number;\n}\n\n/**\n * Builds the variable segment of a fixed-shape format string so that the total\n * length `fixed + segment.length` lands inside the requested window.\n *\n * `fixed` is the number of characters the format always contributes around the\n * segment, `fallback` is the segment length used when the leaf is unconstrained\n * on that side, and `minimum` is the smallest segment the format still\n * validates with. Throws when the window cannot be satisfied by this format's\n * shape (e.g. `Format<\"email\"> & MaxLength<3>`).\n */\nexport const _randomSegmentLength = (\n props: _ILengthProps | undefined,\n fixed: number,\n fallback: number,\n minimum: number,\n): string => {\n let low: number =\n props?.minLength === undefined ? minimum : props.minLength - fixed;\n if (low < minimum) low = minimum;\n // With only a lower bound, spread the segment across `fallback` extra\n // characters so the generated length varies, mirroring `_randomString`.\n const high: number =\n props?.maxLength === undefined ? low + fallback : props.maxLength - fixed;\n if (high < low || high < minimum) throw new Error(_RANDOM_LENGTH_ERROR);\n return _randomString({ type: \"string\", minLength: low, maxLength: high });\n};\n\n/**\n * Intersects the requested length window with the lengths a format's grammar\n * can express, and draws one of them.\n *\n * `minimum` and `maximum` are the shortest and longest values the format admits\n * — omit `maximum` when the grammar is open above — and `spread` is how far\n * past the floor an unbounded request may reach, so an open side still varies\n * the way `_randomString` does. The caller draws from the returned window and\n * applies whatever step its grammar has (base64 lengths are multiples of four,\n * a fractional second needs at least one digit).\n *\n * Throws only when the window and the grammar do not overlap at all. That is\n * the distinction the retry driver below cannot make: it redraws one shape, so\n * it gives up on every length that shape never emits even when the format\n * itself accepts one (issue #2284).\n */\nexport const _randomLengthWindow = (\n props: _ILengthProps | undefined,\n format: { minimum: number; maximum?: number; spread?: number },\n): { low: number; high: number } => {\n const ceiling: number = format.maximum ?? Number.MAX_SAFE_INTEGER;\n const low: number = Math.max(\n props?.minLength ?? format.minimum,\n format.minimum,\n );\n const high: number = Math.min(\n props?.maxLength ?? low + (format.spread ?? 0),\n ceiling,\n );\n if (low > high) throw new Error(_RANDOM_LENGTH_ERROR);\n return { low, high };\n};\n\n/** Draws a length inside a window produced by {@link _randomLengthWindow}. */\nexport const _randomLengthPick = (window: {\n low: number;\n high: number;\n}): number =>\n _randomInteger({\n type: \"integer\",\n minimum: window.low,\n maximum: window.high,\n });\n\n/**\n * Wraps a fixed-length format generator (uuid, date) with the requested length\n * window.\n *\n * Use it only where the grammar admits exactly one length, so a window that\n * excludes it is genuinely unsatisfiable. A format that can express more than\n * one length must build its value at a length drawn from\n * {@link _randomLengthWindow} instead; redrawing one shape cannot reach a length\n * that shape never emits.\n */\nexport const _randomFormatLength = (\n props: _ILengthProps | undefined,\n generate: () => string,\n): string => {\n if (props?.minLength === undefined && props?.maxLength === undefined)\n return generate();\n for (let i: number = 0; i < 256; ++i) {\n const value: string = generate();\n // Characters, not UTF-16 code units: `minLength` and `maxLength` are the\n // bounds the generated validator compares in characters. `uuid` and `date`,\n // the only two shapes routed through here, are ASCII, so the two counts\n // agree for them today -- this keeps one measure so a later non-ASCII\n // format cannot reintroduce the divergence unnoticed.\n const length: number = _stringLength(value);\n if (\n (props.minLength === undefined || length >= props.minLength) &&\n (props.maxLength === undefined || length <= props.maxLength)\n )\n return value;\n }\n throw new Error(_RANDOM_LENGTH_ERROR);\n};\n"],"mappings":";;;;AAIA,MAAa,uBACX;;;;;;;;;;;AAyBF,MAAa,wBACX,OACA,OACA,UACA,YACW;CACX,IAAI,MACF,OAAO,cAAc,KAAA,IAAY,UAAU,MAAM,YAAY;CAC/D,IAAI,MAAM,SAAS,MAAM;CAGzB,MAAM,OACJ,OAAO,cAAc,KAAA,IAAY,MAAM,WAAW,MAAM,YAAY;CACtE,IAAI,OAAO,OAAO,OAAO,SAAS,MAAM,IAAI,MAAM,oBAAoB;CACtE,OAAO,cAAc;EAAE,MAAM;EAAU,WAAW;EAAK,WAAW;CAAK,CAAC;AAC1E;;;;;;;;;;;;;;;;;AAkBA,MAAa,uBACX,OACA,WACkC;CAClC,MAAM,UAAkB,OAAO,WAAW,OAAO;CACjD,MAAM,MAAc,KAAK,IACvB,OAAO,aAAa,OAAO,SAC3B,OAAO,OACT;CACA,MAAM,OAAe,KAAK,IACxB,OAAO,aAAa,OAAO,OAAO,UAAU,IAC5C,OACF;CACA,IAAI,MAAM,MAAM,MAAM,IAAI,MAAM,oBAAoB;CACpD,OAAO;EAAE;EAAK;CAAK;AACrB;;AAGA,MAAa,qBAAqB,WAIhC,eAAe;CACb,MAAM;CACN,SAAS,OAAO;CAChB,SAAS,OAAO;AAClB,CAAC;;;;;;;;;;;AAYH,MAAa,uBACX,OACA,aACW;CACX,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO,SAAS;CAClB,KAAK,IAAI,IAAY,GAAG,IAAI,KAAK,EAAE,GAAG;EACpC,MAAM,QAAgB,SAAS;EAM/B,MAAM,SAAiB,cAAc,KAAK;EAC1C,KACG,MAAM,cAAc,KAAA,KAAa,UAAU,MAAM,eACjD,MAAM,cAAc,KAAA,KAAa,UAAU,MAAM,YAElD,OAAO;CACX;CACA,MAAM,IAAI,MAAM,oBAAoB;AACtC"}
|
|
@@ -17,6 +17,14 @@ export declare const __randomComposition: (props: {
|
|
|
17
17
|
minimum: number;
|
|
18
18
|
maximum: number;
|
|
19
19
|
}) => number[];
|
|
20
|
+
/**
|
|
21
|
+
* Draws `length` characters of the base64 alphabet.
|
|
22
|
+
*
|
|
23
|
+
* The caller passes a multiple of four, which `format: "byte"` accepts without
|
|
24
|
+
* padding; every character below is in the alphabet its validator spells out,
|
|
25
|
+
* so the result needs no encoding step.
|
|
26
|
+
*/
|
|
27
|
+
export declare const __randomBase64: (length: number) => string;
|
|
20
28
|
/** Draws `length` decimal digits, leading zeros included. */
|
|
21
29
|
export declare const __randomDigits: (length: number) => string;
|
|
22
30
|
/** Draws a decimal number of exactly `length` digits without a leading zero. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.__randomNumeric = exports.__randomDigits = exports.__randomComposition = void 0;
|
|
3
|
+
exports.__randomNumeric = exports.__randomDigits = exports.__randomBase64 = exports.__randomComposition = void 0;
|
|
4
4
|
const _randomInteger_1 = require("../_randomInteger");
|
|
5
5
|
/**
|
|
6
6
|
* Splits `total` into `count` parts, each inside `[minimum, maximum]`.
|
|
@@ -31,6 +31,26 @@ const __randomComposition = (props) => {
|
|
|
31
31
|
return parts;
|
|
32
32
|
};
|
|
33
33
|
exports.__randomComposition = __randomComposition;
|
|
34
|
+
/**
|
|
35
|
+
* Draws `length` characters of the base64 alphabet.
|
|
36
|
+
*
|
|
37
|
+
* The caller passes a multiple of four, which `format: "byte"` accepts without
|
|
38
|
+
* padding; every character below is in the alphabet its validator spells out,
|
|
39
|
+
* so the result needs no encoding step.
|
|
40
|
+
*/
|
|
41
|
+
const __randomBase64 = (length) => {
|
|
42
|
+
let text = "";
|
|
43
|
+
for (let i = 0; i < length; ++i)
|
|
44
|
+
text +=
|
|
45
|
+
BASE64[(0, _randomInteger_1._randomInteger)({
|
|
46
|
+
type: "integer",
|
|
47
|
+
minimum: 0,
|
|
48
|
+
maximum: BASE64.length - 1,
|
|
49
|
+
})];
|
|
50
|
+
return text;
|
|
51
|
+
};
|
|
52
|
+
exports.__randomBase64 = __randomBase64;
|
|
53
|
+
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
34
54
|
/** Draws `length` decimal digits, leading zeros included. */
|
|
35
55
|
const __randomDigits = (length) => {
|
|
36
56
|
let text = "";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"__randomComposition.js","sourceRoot":"","sources":["../../../src/internal/private/__randomComposition.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AAEnD;;;;;;;;;;;;GAYG;AACI,MAAM,mBAAmB,GAAG,CAAC,KAKnC,EAAY,EAAE;IACb,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,SAAS,GAAW,KAAK,CAAC,KAAK,CAAC;IACpC,KAAK,IAAI,CAAC,GAAW,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,GAAW,KAAK,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC;QACzC,MAAM,KAAK,GAAW,IAAA,+BAAc,EAAC;YACnC,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,GAAG,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC;YAClE,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,GAAG,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC;SACnE,CAAC,CAAC;QACH,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClB,SAAS,IAAI,KAAK,CAAC;IACrB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CA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,EAAE,EAAE,CAAC;QACrC,IAAI,IAAI,MAAM,CAAC,IAAA,+BAAc,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9E,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AALW,QAAA,cAAc,GAAd,cAAc,CAKzB;AAEF,gFAAgF;AACzE,MAAM,eAAe,GAAG,CAAC,MAAc,EAAU,EAAE,CACxD,MAAM,IAAI,CAAC;IACT,CAAC,CAAC,MAAM,CAAC,IAAA,+BAAc,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IACrE,CAAC,CAAC,MAAM,CAAC,IAAA,+BAAc,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;QACnE,IAAA,QAAA,cAAc,EAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAJpB,QAAA,eAAe,GAAf,eAAe,CAIK"}
|
|
@@ -28,6 +28,23 @@ const __randomComposition = (props) => {
|
|
|
28
28
|
}
|
|
29
29
|
return parts;
|
|
30
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Draws `length` characters of the base64 alphabet.
|
|
33
|
+
*
|
|
34
|
+
* The caller passes a multiple of four, which `format: "byte"` accepts without
|
|
35
|
+
* padding; every character below is in the alphabet its validator spells out,
|
|
36
|
+
* so the result needs no encoding step.
|
|
37
|
+
*/
|
|
38
|
+
const __randomBase64 = (length) => {
|
|
39
|
+
let text = "";
|
|
40
|
+
for (let i = 0; i < length; ++i) text += BASE64[_randomInteger({
|
|
41
|
+
type: "integer",
|
|
42
|
+
minimum: 0,
|
|
43
|
+
maximum: BASE64.length - 1
|
|
44
|
+
})];
|
|
45
|
+
return text;
|
|
46
|
+
};
|
|
47
|
+
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
31
48
|
/** Draws `length` decimal digits, leading zeros included. */
|
|
32
49
|
const __randomDigits = (length) => {
|
|
33
50
|
let text = "";
|
|
@@ -49,6 +66,6 @@ const __randomNumeric = (length) => length <= 1 ? String(_randomInteger({
|
|
|
49
66
|
maximum: 9
|
|
50
67
|
})) + __randomDigits(length - 1);
|
|
51
68
|
//#endregion
|
|
52
|
-
export { __randomComposition, __randomDigits, __randomNumeric };
|
|
69
|
+
export { __randomBase64, __randomComposition, __randomDigits, __randomNumeric };
|
|
53
70
|
|
|
54
71
|
//# sourceMappingURL=__randomComposition.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"__randomComposition.mjs","names":[],"sources":["../../../src/internal/private/__randomComposition.ts"],"sourcesContent":["import { _randomInteger } from \"../_randomInteger\";\n\n/**\n * Splits `total` into `count` parts, each inside `[minimum, maximum]`.\n *\n * Used where a format's length is the sum of its segments — an IPv4 octet spans\n * one to three digits, an IPv6 group one to four — so a requested total length\n * is realized by choosing how many characters each segment contributes instead\n * of redrawing whole addresses and hoping one lands in the window (issue\n * #2284).\n *\n * The caller guarantees `count * minimum <= total <= count * maximum`; each\n * part is drawn from the range that still leaves the remaining parts\n * satisfiable.\n */\nexport const __randomComposition = (props: {\n total: number;\n count: number;\n minimum: number;\n maximum: number;\n}): number[] => {\n const parts: number[] = [];\n let remaining: number = props.total;\n for (let i: number = 0; i < props.count; ++i) {\n const rest: number = props.count - i - 1;\n const value: number = _randomInteger({\n type: \"integer\",\n minimum: Math.max(props.minimum, remaining - rest * props.maximum),\n maximum: Math.min(props.maximum, remaining - rest * props.minimum),\n });\n parts.push(value);\n remaining -= value;\n }\n return parts;\n};\n\n/** Draws `length` decimal digits, leading zeros included. */\nexport const __randomDigits = (length: number): string => {\n let text: string = \"\";\n for (let i: number = 0; i < length; ++i)\n text += String(_randomInteger({ type: \"integer\", minimum: 0, maximum: 9 }));\n return text;\n};\n\n/** Draws a decimal number of exactly `length` digits without a leading zero. */\nexport const __randomNumeric = (length: number): string =>\n length <= 1\n ? String(_randomInteger({ type: \"integer\", minimum: 0, maximum: 9 }))\n : String(_randomInteger({ type: \"integer\", minimum: 1, maximum: 9 })) +\n __randomDigits(length - 1);\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,uBAAuB,UAKpB;CACd,MAAM,QAAkB,CAAC;CACzB,IAAI,YAAoB,MAAM;CAC9B,KAAK,IAAI,IAAY,GAAG,IAAI,MAAM,OAAO,EAAE,GAAG;EAC5C,MAAM,OAAe,MAAM,QAAQ,IAAI;EACvC,MAAM,QAAgB,eAAe;GACnC,MAAM;GACN,SAAS,KAAK,IAAI,MAAM,SAAS,YAAY,OAAO,MAAM,OAAO;GACjE,SAAS,KAAK,IAAI,MAAM,SAAS,YAAY,OAAO,MAAM,OAAO;EACnE,CAAC;EACD,MAAM,KAAK,KAAK;EAChB,aAAa;CACf;CACA,OAAO;AACT;;
|
|
1
|
+
{"version":3,"file":"__randomComposition.mjs","names":[],"sources":["../../../src/internal/private/__randomComposition.ts"],"sourcesContent":["import { _randomInteger } from \"../_randomInteger\";\n\n/**\n * Splits `total` into `count` parts, each inside `[minimum, maximum]`.\n *\n * Used where a format's length is the sum of its segments — an IPv4 octet spans\n * one to three digits, an IPv6 group one to four — so a requested total length\n * is realized by choosing how many characters each segment contributes instead\n * of redrawing whole addresses and hoping one lands in the window (issue\n * #2284).\n *\n * The caller guarantees `count * minimum <= total <= count * maximum`; each\n * part is drawn from the range that still leaves the remaining parts\n * satisfiable.\n */\nexport const __randomComposition = (props: {\n total: number;\n count: number;\n minimum: number;\n maximum: number;\n}): number[] => {\n const parts: number[] = [];\n let remaining: number = props.total;\n for (let i: number = 0; i < props.count; ++i) {\n const rest: number = props.count - i - 1;\n const value: number = _randomInteger({\n type: \"integer\",\n minimum: Math.max(props.minimum, remaining - rest * props.maximum),\n maximum: Math.min(props.maximum, remaining - rest * props.minimum),\n });\n parts.push(value);\n remaining -= value;\n }\n return parts;\n};\n\n/**\n * Draws `length` characters of the base64 alphabet.\n *\n * The caller passes a multiple of four, which `format: \"byte\"` accepts without\n * padding; every character below is in the alphabet its validator spells out,\n * so the result needs no encoding step.\n */\nexport const __randomBase64 = (length: number): string => {\n let text: string = \"\";\n for (let i: number = 0; i < length; ++i)\n text +=\n BASE64[\n _randomInteger({\n type: \"integer\",\n minimum: 0,\n maximum: BASE64.length - 1,\n })\n ];\n return text;\n};\n\nconst BASE64 =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n\n/** Draws `length` decimal digits, leading zeros included. */\nexport const __randomDigits = (length: number): string => {\n let text: string = \"\";\n for (let i: number = 0; i < length; ++i)\n text += String(_randomInteger({ type: \"integer\", minimum: 0, maximum: 9 }));\n return text;\n};\n\n/** Draws a decimal number of exactly `length` digits without a leading zero. */\nexport const __randomNumeric = (length: number): string =>\n length <= 1\n ? String(_randomInteger({ type: \"integer\", minimum: 0, maximum: 9 }))\n : String(_randomInteger({ type: \"integer\", minimum: 1, maximum: 9 })) +\n __randomDigits(length - 1);\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,uBAAuB,UAKpB;CACd,MAAM,QAAkB,CAAC;CACzB,IAAI,YAAoB,MAAM;CAC9B,KAAK,IAAI,IAAY,GAAG,IAAI,MAAM,OAAO,EAAE,GAAG;EAC5C,MAAM,OAAe,MAAM,QAAQ,IAAI;EACvC,MAAM,QAAgB,eAAe;GACnC,MAAM;GACN,SAAS,KAAK,IAAI,MAAM,SAAS,YAAY,OAAO,MAAM,OAAO;GACjE,SAAS,KAAK,IAAI,MAAM,SAAS,YAAY,OAAO,MAAM,OAAO;EACnE,CAAC;EACD,MAAM,KAAK,KAAK;EAChB,aAAa;CACf;CACA,OAAO;AACT;;;;;;;;AASA,MAAa,kBAAkB,WAA2B;CACxD,IAAI,OAAe;CACnB,KAAK,IAAI,IAAY,GAAG,IAAI,QAAQ,EAAE,GACpC,QACE,OACE,eAAe;EACb,MAAM;EACN,SAAS;EACT,SAAS,OAAO,SAAS;CAC3B,CAAC;CAEP,OAAO;AACT;AAEA,MAAM,SACJ;;AAGF,MAAa,kBAAkB,WAA2B;CACxD,IAAI,OAAe;CACnB,KAAK,IAAI,IAAY,GAAG,IAAI,QAAQ,EAAE,GACpC,QAAQ,OAAO,eAAe;EAAE,MAAM;EAAW,SAAS;EAAG,SAAS;CAAE,CAAC,CAAC;CAC5E,OAAO;AACT;;AAGA,MAAa,mBAAmB,WAC9B,UAAU,IACN,OAAO,eAAe;CAAE,MAAM;CAAW,SAAS;CAAG,SAAS;AAAE,CAAC,CAAC,IAClE,OAAO,eAAe;CAAE,MAAM;CAAW,SAAS;CAAG,SAAS;AAAE,CAAC,CAAC,IAClE,eAAe,SAAS,CAAC"}
|
package/lib/json.d.ts
CHANGED
|
@@ -302,7 +302,7 @@ export declare function createAssertParse(errorFactory?: undefined | ((props: Ty
|
|
|
302
302
|
* {@link TypeGuardError.IProps}
|
|
303
303
|
* @returns Reusable parser function
|
|
304
304
|
*/
|
|
305
|
-
export declare function createAssertParse<T>(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): (input: string) => Primitive<T>;
|
|
305
|
+
export declare function createAssertParse<T>(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): (input: string, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)) => Primitive<T>;
|
|
306
306
|
/**
|
|
307
307
|
* Creates reusable {@link validateParse} function.
|
|
308
308
|
*
|
|
@@ -343,7 +343,7 @@ export declare function createAssertStringify(errorFactory?: undefined | ((props
|
|
|
343
343
|
* {@link TypeGuardError.IProps}
|
|
344
344
|
* @returns Reusable stringify function
|
|
345
345
|
*/
|
|
346
|
-
export declare function createAssertStringify<T>(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): (input: unknown) => string;
|
|
346
|
+
export declare function createAssertStringify<T>(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): (input: unknown, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)) => string;
|
|
347
347
|
/**
|
|
348
348
|
* Creates reusable {@link isStringify} function.
|
|
349
349
|
*
|
package/lib/json.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AASA,gGAA6F;AAoC7F,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,aAAa,CAAC,CAAC;AAC/C,CAAC;AA2BD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,cAAc,CAAC,CAAC;AAChD,CAAC;AAuCD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,kBAAkB,CAAC,CAAC;AACpD,CAAC;AAsCD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,kBAAkB,CAAC,CAAC;AACpD,CAAC;AA0BD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,cAAc,CAAC,CAAC;AAChD,CAAC;AA2BD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,oBAAoB,CAAC,CAAC;AACtD,CAAC;AAuBD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,gBAAgB,CAAC,CAAC;AAClD,CAAC;AAoDD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,sBAAsB,CAAC,CAAC;AACxD,CAAC;AAwCD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,kBAAkB,CAAC,CAAC;AACpD,CAAC;AA0CD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,wBAAwB,CAAC,CAAC;AAC1D,CAAC;AAoBD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,oBAAoB,CAAC,CAAC;AACtD,CAAC;
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":";;;;;;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