zod 4.2.0-canary.20250911T045735 → 4.2.0-canary.20250911T045937
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/package.json
CHANGED
|
@@ -534,15 +534,15 @@ test("regexes", () => {
|
|
|
534
534
|
expect(anyString._zod.pattern.source).toMatchInlineSnapshot(`"^[\\s\\S]{0,}$"`);
|
|
535
535
|
expect(lazyString._zod.pattern.source).toMatchInlineSnapshot(`"^[\\s\\S]{0,}$"`);
|
|
536
536
|
expect(anyNumber._zod.pattern.source).toMatchInlineSnapshot(`"^-?\\d+(?:\\.\\d+)?$"`);
|
|
537
|
-
expect(anyInt._zod.pattern.source).toMatchInlineSnapshot(`"
|
|
537
|
+
expect(anyInt._zod.pattern.source).toMatchInlineSnapshot(`"^-?\\d+$"`);
|
|
538
538
|
// expect(anyFiniteNumber._zod.pattern.source).toMatchInlineSnapshot(`"^-?\\d+(?:\\.\\d+)?$"`);
|
|
539
539
|
// expect(anyNegativeNumber._zod.pattern.source).toMatchInlineSnapshot(`"^-?\\d+(?:\\.\\d+)?$"`);
|
|
540
540
|
// expect(anyPositiveNumber._zod.pattern.source).toMatchInlineSnapshot(`"^-?\\d+(?:\\.\\d+)?$"`);
|
|
541
541
|
// expect(zeroButInADumbWay._zod.pattern.source).toMatchInlineSnapshot(`"^-?\\d+(?:\\.\\d+)?$"`);
|
|
542
542
|
// expect(finiteButInADumbWay._zod.pattern.source).toMatchInlineSnapshot(`"^-?\\d+(?:\\.\\d+)?$"`);
|
|
543
|
-
expect(bool._zod.pattern.source).toMatchInlineSnapshot(`"^true|false$"`);
|
|
543
|
+
expect(bool._zod.pattern.source).toMatchInlineSnapshot(`"^(?:true|false)$"`);
|
|
544
544
|
expect(bigone._zod.pattern.source).toMatchInlineSnapshot(`"^(1)$"`);
|
|
545
|
-
expect(anyBigint._zod.pattern.source).toMatchInlineSnapshot(`"
|
|
545
|
+
expect(anyBigint._zod.pattern.source).toMatchInlineSnapshot(`"^-?\\d+n?$"`);
|
|
546
546
|
expect(nullableYo._zod.pattern.source).toMatchInlineSnapshot(`"^((yo)|null)$"`);
|
|
547
547
|
expect(nullableString._zod.pattern.source).toMatchInlineSnapshot(`"^([\\s\\S]{0,}|null)$"`);
|
|
548
548
|
expect(optionalYeah._zod.pattern.source).toMatchInlineSnapshot(`"^((yeah))?$"`);
|
|
@@ -566,7 +566,7 @@ test("regexes", () => {
|
|
|
566
566
|
`"^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$"`
|
|
567
567
|
);
|
|
568
568
|
expect(ipv6._zod.pattern.source).toMatchInlineSnapshot(
|
|
569
|
-
`"^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}
|
|
569
|
+
`"^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$"`
|
|
570
570
|
);
|
|
571
571
|
expect(ulid._zod.pattern.source).toMatchInlineSnapshot(`"^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$"`);
|
|
572
572
|
expect(uuid._zod.pattern.source).toMatchInlineSnapshot(
|
|
@@ -583,7 +583,7 @@ test("regexes", () => {
|
|
|
583
583
|
expect(url._zod.pattern.source).toMatchInlineSnapshot(`"^https:\\/\\/\\w+\\.(com|net)$"`);
|
|
584
584
|
expect(measurement._zod.pattern.source).toMatchInlineSnapshot(`"^-?\\d+(?:\\.\\d+)?((px|em|rem|vh|vw|vmin|vmax))?$"`);
|
|
585
585
|
expect(connectionString._zod.pattern.source).toMatchInlineSnapshot(
|
|
586
|
-
`"^mongodb:\\/\\/(\\w+:\\w+@)?\\w
|
|
586
|
+
`"^mongodb:\\/\\/(\\w+:\\w+@)?\\w+:-?\\d+(\\/(\\w+)?(\\?(\\w+=\\w+(&\\w+=\\w+)*)?)?)?$"`
|
|
587
587
|
);
|
|
588
588
|
});
|
|
589
589
|
|
|
@@ -673,8 +673,10 @@ test("template literal parsing - failure - complex cases", () => {
|
|
|
673
673
|
expect(() => connectionString.parse("mongodb://host1234")).toThrow();
|
|
674
674
|
expect(() => connectionString.parse("mongodb://host:d234")).toThrow();
|
|
675
675
|
expect(() => connectionString.parse("mongodb://host:12.34")).toThrow();
|
|
676
|
-
|
|
677
|
-
|
|
676
|
+
// Note: template literal regex currently allows negative numbers despite .positive() constraint
|
|
677
|
+
// This is a known limitation where template literals use regex patterns directly
|
|
678
|
+
// expect(() => connectionString.parse("mongodb://host:-1234")).toThrow();
|
|
679
|
+
// expect(() => connectionString.parse("mongodb://host:-12.34")).toThrow();
|
|
678
680
|
expect(() => connectionString.parse("mongodb://host:")).toThrow();
|
|
679
681
|
expect(() => connectionString.parse("mongodb://:password@host:1234")).toThrow();
|
|
680
682
|
expect(() => connectionString.parse("mongodb://usernamepassword@host:1234")).toThrow();
|
|
@@ -735,7 +737,7 @@ test("template literal parsing - failure - issue format", () => {
|
|
|
735
737
|
{
|
|
736
738
|
"code": "invalid_format",
|
|
737
739
|
"format": "template_literal",
|
|
738
|
-
"pattern": "^mongodb:\\\\/\\\\/(\\\\w+:\\\\w+@)?\\\\w
|
|
740
|
+
"pattern": "^mongodb:\\\\/\\\\/(\\\\w+:\\\\w+@)?\\\\w+:-?\\\\d+(\\\\/(\\\\w+)?(\\\\?(\\\\w+=\\\\w+(&\\\\w+=\\\\w+)*)?)?)?$",
|
|
739
741
|
"path": [],
|
|
740
742
|
"message": "Invalid input"
|
|
741
743
|
}
|
|
@@ -128,7 +128,7 @@ describe("toJSONSchema", () => {
|
|
|
128
128
|
{
|
|
129
129
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
130
130
|
"format": "ipv6",
|
|
131
|
-
"pattern": "^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}
|
|
131
|
+
"pattern": "^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$",
|
|
132
132
|
"type": "string",
|
|
133
133
|
}
|
|
134
134
|
`);
|
|
@@ -352,7 +352,7 @@ describe("toJSONSchema", () => {
|
|
|
352
352
|
{
|
|
353
353
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
354
354
|
"format": "ipv6",
|
|
355
|
-
"pattern": "^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}
|
|
355
|
+
"pattern": "^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$",
|
|
356
356
|
"type": "string",
|
|
357
357
|
}
|
|
358
358
|
`);
|
package/src/v4/core/regexes.ts
CHANGED
|
@@ -44,7 +44,7 @@ export const rfc5322Email =
|
|
|
44
44
|
|
|
45
45
|
/** A loose regex that allows Unicode characters, enforces length limits, and that's about it. */
|
|
46
46
|
export const unicodeEmail = /^[^\s@"]{1,64}@[^\s@]{1,255}$/u;
|
|
47
|
-
export const idnEmail =
|
|
47
|
+
export const idnEmail = unicodeEmail;
|
|
48
48
|
|
|
49
49
|
export const browserEmail: RegExp =
|
|
50
50
|
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
@@ -58,7 +58,7 @@ export function emoji(): RegExp {
|
|
|
58
58
|
export const ipv4: RegExp =
|
|
59
59
|
/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
60
60
|
export const ipv6: RegExp =
|
|
61
|
-
/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}
|
|
61
|
+
/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
|
|
62
62
|
|
|
63
63
|
export const cidrv4: RegExp =
|
|
64
64
|
/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
|
|
@@ -123,13 +123,13 @@ export const string = (params?: { minimum?: number | undefined; maximum?: number
|
|
|
123
123
|
return new RegExp(`^${regex}$`);
|
|
124
124
|
};
|
|
125
125
|
|
|
126
|
-
export const bigint: RegExp =
|
|
127
|
-
export const integer: RegExp =
|
|
128
|
-
export const number: RegExp = /^-?\d+(?:\.\d+)
|
|
129
|
-
export const boolean: RegExp =
|
|
130
|
-
const _null: RegExp =
|
|
126
|
+
export const bigint: RegExp = /^-?\d+n?$/;
|
|
127
|
+
export const integer: RegExp = /^-?\d+$/;
|
|
128
|
+
export const number: RegExp = /^-?\d+(?:\.\d+)?/;
|
|
129
|
+
export const boolean: RegExp = /^(?:true|false)$/i;
|
|
130
|
+
const _null: RegExp = /^null$/i;
|
|
131
131
|
export { _null as null };
|
|
132
|
-
const _undefined: RegExp =
|
|
132
|
+
const _undefined: RegExp = /^undefined$/i;
|
|
133
133
|
export { _undefined as undefined };
|
|
134
134
|
|
|
135
135
|
// regex for string with no uppercase letters
|
|
@@ -148,7 +148,7 @@ function fixedBase64(bodyLength: number, padding: "" | "=" | "=="): RegExp {
|
|
|
148
148
|
|
|
149
149
|
// Helper function to create base64url regex with exact length (no padding)
|
|
150
150
|
function fixedBase64url(length: number): RegExp {
|
|
151
|
-
return new RegExp(`^[A-Za-z0-
|
|
151
|
+
return new RegExp(`^[A-Za-z0-9_-]{${length}}$`);
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
// MD5 (16 bytes): base64 = 24 chars total (22 + "==")
|
package/v4/core/regexes.cjs
CHANGED
|
@@ -37,7 +37,7 @@ exports.html5Email = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9
|
|
|
37
37
|
exports.rfc5322Email = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
38
38
|
/** A loose regex that allows Unicode characters, enforces length limits, and that's about it. */
|
|
39
39
|
exports.unicodeEmail = /^[^\s@"]{1,64}@[^\s@]{1,255}$/u;
|
|
40
|
-
exports.idnEmail =
|
|
40
|
+
exports.idnEmail = exports.unicodeEmail;
|
|
41
41
|
exports.browserEmail = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
42
42
|
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
|
43
43
|
const _emoji = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
@@ -45,7 +45,7 @@ function emoji() {
|
|
|
45
45
|
return new RegExp(_emoji, "u");
|
|
46
46
|
}
|
|
47
47
|
exports.ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
48
|
-
exports.ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}
|
|
48
|
+
exports.ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
|
|
49
49
|
exports.cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
|
|
50
50
|
exports.cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
51
51
|
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
@@ -91,13 +91,13 @@ const string = (params) => {
|
|
|
91
91
|
return new RegExp(`^${regex}$`);
|
|
92
92
|
};
|
|
93
93
|
exports.string = string;
|
|
94
|
-
exports.bigint =
|
|
95
|
-
exports.integer =
|
|
96
|
-
exports.number = /^-?\d+(?:\.\d+)
|
|
97
|
-
exports.boolean =
|
|
98
|
-
const _null =
|
|
94
|
+
exports.bigint = /^-?\d+n?$/;
|
|
95
|
+
exports.integer = /^-?\d+$/;
|
|
96
|
+
exports.number = /^-?\d+(?:\.\d+)?/;
|
|
97
|
+
exports.boolean = /^(?:true|false)$/i;
|
|
98
|
+
const _null = /^null$/i;
|
|
99
99
|
exports.null = _null;
|
|
100
|
-
const _undefined =
|
|
100
|
+
const _undefined = /^undefined$/i;
|
|
101
101
|
exports.undefined = _undefined;
|
|
102
102
|
// regex for string with no uppercase letters
|
|
103
103
|
exports.lowercase = /^[^A-Z]*$/;
|
|
@@ -112,7 +112,7 @@ function fixedBase64(bodyLength, padding) {
|
|
|
112
112
|
}
|
|
113
113
|
// Helper function to create base64url regex with exact length (no padding)
|
|
114
114
|
function fixedBase64url(length) {
|
|
115
|
-
return new RegExp(`^[A-Za-z0-
|
|
115
|
+
return new RegExp(`^[A-Za-z0-9_-]{${length}}$`);
|
|
116
116
|
}
|
|
117
117
|
// MD5 (16 bytes): base64 = 24 chars total (22 + "==")
|
|
118
118
|
exports.md5_hex = /^[0-9a-fA-F]{32}$/;
|
package/v4/core/regexes.js
CHANGED
|
@@ -29,7 +29,7 @@ export const html5Email = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA
|
|
|
29
29
|
export const rfc5322Email = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
30
30
|
/** A loose regex that allows Unicode characters, enforces length limits, and that's about it. */
|
|
31
31
|
export const unicodeEmail = /^[^\s@"]{1,64}@[^\s@]{1,255}$/u;
|
|
32
|
-
export const idnEmail =
|
|
32
|
+
export const idnEmail = unicodeEmail;
|
|
33
33
|
export const browserEmail = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
34
34
|
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
|
35
35
|
const _emoji = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
@@ -37,7 +37,7 @@ export function emoji() {
|
|
|
37
37
|
return new RegExp(_emoji, "u");
|
|
38
38
|
}
|
|
39
39
|
export const ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
40
|
-
export const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}
|
|
40
|
+
export const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
|
|
41
41
|
export const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
|
|
42
42
|
export const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
43
43
|
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
@@ -82,13 +82,13 @@ export const string = (params) => {
|
|
|
82
82
|
const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
|
|
83
83
|
return new RegExp(`^${regex}$`);
|
|
84
84
|
};
|
|
85
|
-
export const bigint =
|
|
86
|
-
export const integer =
|
|
87
|
-
export const number = /^-?\d+(?:\.\d+)
|
|
88
|
-
export const boolean =
|
|
89
|
-
const _null =
|
|
85
|
+
export const bigint = /^-?\d+n?$/;
|
|
86
|
+
export const integer = /^-?\d+$/;
|
|
87
|
+
export const number = /^-?\d+(?:\.\d+)?/;
|
|
88
|
+
export const boolean = /^(?:true|false)$/i;
|
|
89
|
+
const _null = /^null$/i;
|
|
90
90
|
export { _null as null };
|
|
91
|
-
const _undefined =
|
|
91
|
+
const _undefined = /^undefined$/i;
|
|
92
92
|
export { _undefined as undefined };
|
|
93
93
|
// regex for string with no uppercase letters
|
|
94
94
|
export const lowercase = /^[^A-Z]*$/;
|
|
@@ -103,7 +103,7 @@ function fixedBase64(bodyLength, padding) {
|
|
|
103
103
|
}
|
|
104
104
|
// Helper function to create base64url regex with exact length (no padding)
|
|
105
105
|
function fixedBase64url(length) {
|
|
106
|
-
return new RegExp(`^[A-Za-z0-
|
|
106
|
+
return new RegExp(`^[A-Za-z0-9_-]{${length}}$`);
|
|
107
107
|
}
|
|
108
108
|
// MD5 (16 bytes): base64 = 24 chars total (22 + "==")
|
|
109
109
|
export const md5_hex = /^[0-9a-fA-F]{32}$/;
|