zod 4.6.3 → 4.6.5
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 +1 -1
- package/src/v4/classic/schemas.ts +11 -5
- package/src/v4/classic/tests/assignability.test.ts +1 -0
- package/src/v4/classic/tests/instance-footprint.test.ts +22 -0
- package/src/v4/classic/tests/number.test.ts +39 -0
- package/src/v4/classic/tests/properties.test.ts +19 -0
- package/src/v4/classic/tests/string.test.ts +70 -1
- package/src/v4/classic/tests/to-json-schema.test.ts +87 -35
- package/src/v4/core/api.ts +17 -22
- package/src/v4/core/compile.ts +27 -6
- package/src/v4/core/core.ts +1 -3
- package/src/v4/core/json-schema-processors.ts +9 -13
- package/src/v4/core/regexes.ts +4 -0
- package/src/v4/core/schemas.ts +35 -11
- package/src/v4/core/tests/compile-differential.test.ts +35 -0
- package/src/v4/core/tests/compile.test.ts +177 -0
- package/src/v4/core/tests/url-no-canparse.test.ts +118 -16
- package/src/v4/core/versions.ts +1 -1
- package/src/v4/locales/ar.ts +1 -0
- package/src/v4/locales/az.ts +1 -0
- package/src/v4/locales/be.ts +1 -0
- package/src/v4/locales/bg.ts +1 -0
- package/src/v4/locales/bn.ts +1 -0
- package/src/v4/locales/ca.ts +1 -0
- package/src/v4/locales/ckb.ts +1 -0
- package/src/v4/locales/cs.ts +1 -0
- package/src/v4/locales/da.ts +1 -0
- package/src/v4/locales/de.ts +1 -0
- package/src/v4/locales/el.ts +1 -0
- package/src/v4/locales/en.ts +1 -0
- package/src/v4/locales/eo.ts +1 -0
- package/src/v4/locales/es.ts +1 -0
- package/src/v4/locales/fa.ts +1 -0
- package/src/v4/locales/fi.ts +1 -0
- package/src/v4/locales/fr-CA.ts +1 -0
- package/src/v4/locales/fr.ts +1 -0
- package/src/v4/locales/gu.ts +1 -0
- package/src/v4/locales/he.ts +1 -0
- package/src/v4/locales/hi.ts +1 -0
- package/src/v4/locales/hr.ts +1 -0
- package/src/v4/locales/hu.ts +1 -0
- package/src/v4/locales/hy.ts +1 -0
- package/src/v4/locales/id.ts +1 -0
- package/src/v4/locales/is.ts +1 -0
- package/src/v4/locales/it.ts +1 -0
- package/src/v4/locales/ja.ts +1 -0
- package/src/v4/locales/ka.ts +1 -0
- package/src/v4/locales/km.ts +1 -0
- package/src/v4/locales/kn.ts +1 -0
- package/src/v4/locales/ko.ts +1 -0
- package/src/v4/locales/lt.ts +1 -0
- package/src/v4/locales/mk.ts +1 -0
- package/src/v4/locales/ms.ts +1 -0
- package/src/v4/locales/ne.ts +1 -0
- package/src/v4/locales/nl.ts +1 -0
- package/src/v4/locales/nn.ts +1 -0
- package/src/v4/locales/no.ts +1 -0
- package/src/v4/locales/ota.ts +1 -0
- package/src/v4/locales/pl.ts +1 -0
- package/src/v4/locales/ps.ts +1 -0
- package/src/v4/locales/pt-BR.ts +1 -0
- package/src/v4/locales/pt.ts +1 -0
- package/src/v4/locales/ro.ts +1 -0
- package/src/v4/locales/ru.ts +1 -0
- package/src/v4/locales/sk.ts +1 -0
- package/src/v4/locales/sl.ts +1 -0
- package/src/v4/locales/sv.ts +1 -0
- package/src/v4/locales/ta.ts +1 -0
- package/src/v4/locales/tg.ts +1 -0
- package/src/v4/locales/th.ts +1 -0
- package/src/v4/locales/tk.ts +1 -0
- package/src/v4/locales/tr.ts +1 -0
- package/src/v4/locales/uk.ts +1 -0
- package/src/v4/locales/ur.ts +1 -0
- package/src/v4/locales/uz.ts +1 -0
- package/src/v4/locales/vi.ts +1 -0
- package/src/v4/locales/yo.ts +1 -0
- package/src/v4/locales/zh-CN.ts +1 -0
- package/src/v4/locales/zh-TW.ts +1 -0
- package/src/v4/mini/schemas.ts +12 -4
- package/src/v4/mini/tests/index.test.ts +56 -0
- package/src/v4/mini/tests/string.test.ts +7 -0
- package/v4/classic/schemas.cjs +9 -4
- package/v4/classic/schemas.d.cts +4 -1
- package/v4/classic/schemas.d.ts +4 -1
- package/v4/classic/schemas.js +8 -4
- package/v4/core/api.cjs +9 -20
- package/v4/core/api.d.cts +6 -2
- package/v4/core/api.d.ts +6 -2
- package/v4/core/api.js +9 -20
- package/v4/core/compile.cjs +7 -6
- package/v4/core/compile.js +8 -7
- package/v4/core/core.cjs +1 -1
- package/v4/core/core.js +1 -1
- package/v4/core/json-schema-processors.cjs +7 -10
- package/v4/core/json-schema-processors.js +7 -10
- package/v4/core/regexes.cjs +4 -2
- package/v4/core/regexes.d.cts +1 -0
- package/v4/core/regexes.d.ts +1 -0
- package/v4/core/regexes.js +2 -0
- package/v4/core/schemas.cjs +32 -11
- package/v4/core/schemas.d.cts +5 -3
- package/v4/core/schemas.d.ts +5 -3
- package/v4/core/schemas.js +30 -11
- package/v4/core/versions.cjs +1 -1
- package/v4/core/versions.js +1 -1
- package/v4/locales/ar.cjs +1 -0
- package/v4/locales/ar.js +1 -0
- package/v4/locales/az.cjs +1 -0
- package/v4/locales/az.js +1 -0
- package/v4/locales/be.cjs +1 -0
- package/v4/locales/be.js +1 -0
- package/v4/locales/bg.cjs +1 -0
- package/v4/locales/bg.js +1 -0
- package/v4/locales/bn.cjs +1 -0
- package/v4/locales/bn.js +1 -0
- package/v4/locales/ca.cjs +1 -0
- package/v4/locales/ca.js +1 -0
- package/v4/locales/ckb.cjs +1 -0
- package/v4/locales/ckb.js +1 -0
- package/v4/locales/cs.cjs +1 -0
- package/v4/locales/cs.js +1 -0
- package/v4/locales/da.cjs +1 -0
- package/v4/locales/da.js +1 -0
- package/v4/locales/de.cjs +1 -0
- package/v4/locales/de.js +1 -0
- package/v4/locales/el.cjs +1 -0
- package/v4/locales/el.js +1 -0
- package/v4/locales/en.cjs +1 -0
- package/v4/locales/en.js +1 -0
- package/v4/locales/eo.cjs +1 -0
- package/v4/locales/eo.js +1 -0
- package/v4/locales/es.cjs +1 -0
- package/v4/locales/es.js +1 -0
- package/v4/locales/fa.cjs +1 -0
- package/v4/locales/fa.js +1 -0
- package/v4/locales/fi.cjs +1 -0
- package/v4/locales/fi.js +1 -0
- package/v4/locales/fr-CA.cjs +1 -0
- package/v4/locales/fr-CA.js +1 -0
- package/v4/locales/fr.cjs +1 -0
- package/v4/locales/fr.js +1 -0
- package/v4/locales/gu.cjs +1 -0
- package/v4/locales/gu.js +1 -0
- package/v4/locales/he.cjs +1 -0
- package/v4/locales/he.js +1 -0
- package/v4/locales/hi.cjs +1 -0
- package/v4/locales/hi.js +1 -0
- package/v4/locales/hr.cjs +1 -0
- package/v4/locales/hr.js +1 -0
- package/v4/locales/hu.cjs +1 -0
- package/v4/locales/hu.js +1 -0
- package/v4/locales/hy.cjs +1 -0
- package/v4/locales/hy.js +1 -0
- package/v4/locales/id.cjs +1 -0
- package/v4/locales/id.js +1 -0
- package/v4/locales/is.cjs +1 -0
- package/v4/locales/is.js +1 -0
- package/v4/locales/it.cjs +1 -0
- package/v4/locales/it.js +1 -0
- package/v4/locales/ja.cjs +1 -0
- package/v4/locales/ja.js +1 -0
- package/v4/locales/ka.cjs +1 -0
- package/v4/locales/ka.js +1 -0
- package/v4/locales/km.cjs +1 -0
- package/v4/locales/km.js +1 -0
- package/v4/locales/kn.cjs +1 -0
- package/v4/locales/kn.js +1 -0
- package/v4/locales/ko.cjs +1 -0
- package/v4/locales/ko.js +1 -0
- package/v4/locales/lt.cjs +1 -0
- package/v4/locales/lt.js +1 -0
- package/v4/locales/mk.cjs +1 -0
- package/v4/locales/mk.js +1 -0
- package/v4/locales/ms.cjs +1 -0
- package/v4/locales/ms.js +1 -0
- package/v4/locales/ne.cjs +1 -0
- package/v4/locales/ne.js +1 -0
- package/v4/locales/nl.cjs +1 -0
- package/v4/locales/nl.js +1 -0
- package/v4/locales/nn.cjs +1 -0
- package/v4/locales/nn.js +1 -0
- package/v4/locales/no.cjs +1 -0
- package/v4/locales/no.js +1 -0
- package/v4/locales/ota.cjs +1 -0
- package/v4/locales/ota.js +1 -0
- package/v4/locales/pl.cjs +1 -0
- package/v4/locales/pl.js +1 -0
- package/v4/locales/ps.cjs +1 -0
- package/v4/locales/ps.js +1 -0
- package/v4/locales/pt-BR.cjs +1 -0
- package/v4/locales/pt-BR.js +1 -0
- package/v4/locales/pt.cjs +1 -0
- package/v4/locales/pt.js +1 -0
- package/v4/locales/ro.cjs +1 -0
- package/v4/locales/ro.js +1 -0
- package/v4/locales/ru.cjs +1 -0
- package/v4/locales/ru.js +1 -0
- package/v4/locales/sk.cjs +1 -0
- package/v4/locales/sk.js +1 -0
- package/v4/locales/sl.cjs +1 -0
- package/v4/locales/sl.js +1 -0
- package/v4/locales/sv.cjs +1 -0
- package/v4/locales/sv.js +1 -0
- package/v4/locales/ta.cjs +1 -0
- package/v4/locales/ta.js +1 -0
- package/v4/locales/tg.cjs +1 -0
- package/v4/locales/tg.js +1 -0
- package/v4/locales/th.cjs +1 -0
- package/v4/locales/th.js +1 -0
- package/v4/locales/tk.cjs +1 -0
- package/v4/locales/tk.js +1 -0
- package/v4/locales/tr.cjs +1 -0
- package/v4/locales/tr.js +1 -0
- package/v4/locales/uk.cjs +1 -0
- package/v4/locales/uk.js +1 -0
- package/v4/locales/ur.cjs +1 -0
- package/v4/locales/ur.js +1 -0
- package/v4/locales/uz.cjs +1 -0
- package/v4/locales/uz.js +1 -0
- package/v4/locales/vi.cjs +1 -0
- package/v4/locales/vi.js +1 -0
- package/v4/locales/yo.cjs +1 -0
- package/v4/locales/yo.js +1 -0
- package/v4/locales/zh-CN.cjs +1 -0
- package/v4/locales/zh-CN.js +1 -0
- package/v4/locales/zh-TW.cjs +1 -0
- package/v4/locales/zh-TW.js +1 -0
- package/v4/mini/schemas.cjs +10 -4
- package/v4/mini/schemas.d.cts +1 -0
- package/v4/mini/schemas.d.ts +1 -0
- package/v4/mini/schemas.js +9 -4
package/src/v4/locales/hr.ts
CHANGED
package/src/v4/locales/hu.ts
CHANGED
package/src/v4/locales/hy.ts
CHANGED
package/src/v4/locales/id.ts
CHANGED
package/src/v4/locales/is.ts
CHANGED
package/src/v4/locales/it.ts
CHANGED
package/src/v4/locales/ja.ts
CHANGED
package/src/v4/locales/ka.ts
CHANGED
package/src/v4/locales/km.ts
CHANGED
package/src/v4/locales/kn.ts
CHANGED
package/src/v4/locales/ko.ts
CHANGED
package/src/v4/locales/lt.ts
CHANGED
|
@@ -146,6 +146,7 @@ const error: () => errors.$ZodErrorMap = () => {
|
|
|
146
146
|
json_string: "JSON eilutė",
|
|
147
147
|
e164: "E.164 numeris",
|
|
148
148
|
credit_card: "kredito kortelės numeris",
|
|
149
|
+
currency_code: "valiutos kodas",
|
|
149
150
|
iban: "IBAN",
|
|
150
151
|
jwt: "JWT",
|
|
151
152
|
template_literal: "įvestis",
|
package/src/v4/locales/mk.ts
CHANGED
package/src/v4/locales/ms.ts
CHANGED
package/src/v4/locales/ne.ts
CHANGED
package/src/v4/locales/nl.ts
CHANGED
package/src/v4/locales/nn.ts
CHANGED
package/src/v4/locales/no.ts
CHANGED
package/src/v4/locales/ota.ts
CHANGED
package/src/v4/locales/pl.ts
CHANGED
package/src/v4/locales/ps.ts
CHANGED
package/src/v4/locales/pt-BR.ts
CHANGED
|
@@ -47,6 +47,7 @@ const error: () => errors.$ZodErrorMap = () => {
|
|
|
47
47
|
json_string: "o texto JSON",
|
|
48
48
|
e164: "o número E.164",
|
|
49
49
|
credit_card: "o número de cartão de crédito",
|
|
50
|
+
currency_code: "o código de moeda",
|
|
50
51
|
iban: "o IBAN",
|
|
51
52
|
jwt: "o JWT",
|
|
52
53
|
template_literal: "a entrada",
|
package/src/v4/locales/pt.ts
CHANGED
|
@@ -47,6 +47,7 @@ const error: () => errors.$ZodErrorMap = () => {
|
|
|
47
47
|
json_string: "o texto JSON",
|
|
48
48
|
e164: "o número E.164",
|
|
49
49
|
credit_card: "o número de cartão de crédito",
|
|
50
|
+
currency_code: "o código de moeda",
|
|
50
51
|
iban: "o IBAN",
|
|
51
52
|
jwt: "o JWT",
|
|
52
53
|
template_literal: "a entrada",
|
package/src/v4/locales/ro.ts
CHANGED
package/src/v4/locales/ru.ts
CHANGED
package/src/v4/locales/sk.ts
CHANGED
package/src/v4/locales/sl.ts
CHANGED
package/src/v4/locales/sv.ts
CHANGED
package/src/v4/locales/ta.ts
CHANGED
package/src/v4/locales/tg.ts
CHANGED
package/src/v4/locales/th.ts
CHANGED
|
@@ -46,6 +46,7 @@ const error: () => errors.$ZodErrorMap = () => {
|
|
|
46
46
|
json_string: "ข้อความแบบ JSON",
|
|
47
47
|
e164: "เบอร์โทรศัพท์ระหว่างประเทศ (E.164)",
|
|
48
48
|
credit_card: "หมายเลขบัตรเครดิต",
|
|
49
|
+
currency_code: "รหัสสกุลเงิน",
|
|
49
50
|
iban: "IBAN",
|
|
50
51
|
jwt: "โทเคน JWT",
|
|
51
52
|
template_literal: "ข้อมูลที่ป้อน",
|
package/src/v4/locales/tk.ts
CHANGED
package/src/v4/locales/tr.ts
CHANGED
package/src/v4/locales/uk.ts
CHANGED
package/src/v4/locales/ur.ts
CHANGED
package/src/v4/locales/uz.ts
CHANGED
package/src/v4/locales/vi.ts
CHANGED
package/src/v4/locales/yo.ts
CHANGED
package/src/v4/locales/zh-CN.ts
CHANGED
package/src/v4/locales/zh-TW.ts
CHANGED
package/src/v4/mini/schemas.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as core from "../core/index.js";
|
|
2
2
|
import type { $ZodBigIntFormats } from "../core/index.js";
|
|
3
|
+
import * as regexes from "../core/regexes.js";
|
|
3
4
|
import * as util from "../core/util.js";
|
|
4
5
|
import * as parse from "./parse.js";
|
|
5
6
|
|
|
@@ -224,8 +225,8 @@ export function url(params?: string | core.$ZodURLParams): ZodMiniURL {
|
|
|
224
225
|
// @__NO_SIDE_EFFECTS__
|
|
225
226
|
export function httpUrl(params?: string | Omit<core.$ZodURLParams, "protocol" | "hostname">): ZodMiniURL {
|
|
226
227
|
return core._url(ZodMiniURL, {
|
|
227
|
-
protocol:
|
|
228
|
-
hostname:
|
|
228
|
+
protocol: regexes.httpProtocol,
|
|
229
|
+
hostname: regexes.domain,
|
|
229
230
|
...util.normalizeParams(params),
|
|
230
231
|
});
|
|
231
232
|
}
|
|
@@ -563,12 +564,19 @@ export function stringFormat<Format extends string>(
|
|
|
563
564
|
|
|
564
565
|
// @__NO_SIDE_EFFECTS__
|
|
565
566
|
export function hostname(_params?: string | core.$ZodStringFormatParams): ZodMiniCustomStringFormat<"hostname"> {
|
|
566
|
-
return core._stringFormat(ZodMiniCustomStringFormat, "hostname",
|
|
567
|
+
return core._stringFormat(ZodMiniCustomStringFormat, "hostname", regexes.hostname, _params) as any;
|
|
567
568
|
}
|
|
568
569
|
|
|
569
570
|
// @__NO_SIDE_EFFECTS__
|
|
570
571
|
export function hex(_params?: string | core.$ZodStringFormatParams): ZodMiniCustomStringFormat<"hex"> {
|
|
571
|
-
return core._stringFormat(ZodMiniCustomStringFormat, "hex",
|
|
572
|
+
return core._stringFormat(ZodMiniCustomStringFormat, "hex", regexes.hex, _params) as any;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// @__NO_SIDE_EFFECTS__
|
|
576
|
+
export function currencyCode(
|
|
577
|
+
_params?: string | core.$ZodStringFormatParams
|
|
578
|
+
): ZodMiniCustomStringFormat<"currency_code"> {
|
|
579
|
+
return core._stringFormat(ZodMiniCustomStringFormat, "currency_code", regexes.currencyCode, _params) as any;
|
|
572
580
|
}
|
|
573
581
|
|
|
574
582
|
// @__NO_SIDE_EFFECTS__
|
|
@@ -2,6 +2,62 @@ import { expect, expectTypeOf, test } from "vitest";
|
|
|
2
2
|
import * as z from "zod/mini";
|
|
3
3
|
import type { util } from "zod/v4/core";
|
|
4
4
|
|
|
5
|
+
test("factory checks", () => {
|
|
6
|
+
const string = z.string({ checks: [z.minLength(1), z.maxLength(3)] as const });
|
|
7
|
+
const number = z.number({ checks: [z.minimum(1), z.maximum(3)] as const });
|
|
8
|
+
expectTypeOf<z.output<typeof string>>().toEqualTypeOf<string>();
|
|
9
|
+
expectTypeOf<z.output<typeof number>>().toEqualTypeOf<number>();
|
|
10
|
+
for (const [schema, valid, invalid] of [
|
|
11
|
+
[string, "ab", ""],
|
|
12
|
+
[number, 2, 4],
|
|
13
|
+
] as const) {
|
|
14
|
+
expect(z.validate(schema, valid)).toBe(true);
|
|
15
|
+
expect(z.validate(schema, invalid)).toBe(false);
|
|
16
|
+
expect(schema._zod.parent).toBeUndefined();
|
|
17
|
+
expect(z.validate(z.compile(schema), valid)).toBe(true);
|
|
18
|
+
expect(z.validate(z.compile(schema), invalid)).toBe(false);
|
|
19
|
+
}
|
|
20
|
+
// @ts-expect-error numeric checks cannot validate strings
|
|
21
|
+
z.string({ checks: [z.minimum(1)] });
|
|
22
|
+
// @ts-expect-error length checks cannot validate numbers
|
|
23
|
+
z.number({ checks: [z.minLength(1)] });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("factory checks snapshot caller arrays", () => {
|
|
27
|
+
for (const factory of [z.string, z.coerce.string]) {
|
|
28
|
+
const checks = [z.minLength(1)];
|
|
29
|
+
const schema = factory({ checks });
|
|
30
|
+
let reads = 0;
|
|
31
|
+
factory({
|
|
32
|
+
get checks() {
|
|
33
|
+
if (++reads > 1) throw new Error("checks read twice");
|
|
34
|
+
return checks;
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
expect(reads).toBe(1);
|
|
38
|
+
checks.push(z.minLength(10));
|
|
39
|
+
expect(z.validate(schema, "long")).toBe(true);
|
|
40
|
+
expect(z.validate(z.compile(schema), "long")).toBe(true);
|
|
41
|
+
expect(z.toJSONSchema(schema).minLength).toBe(1);
|
|
42
|
+
}
|
|
43
|
+
for (const factory of [z.number, z.coerce.number]) {
|
|
44
|
+
const checks = [z.minimum(1)];
|
|
45
|
+
const schema = factory({ checks });
|
|
46
|
+
let reads = 0;
|
|
47
|
+
factory({
|
|
48
|
+
get checks() {
|
|
49
|
+
if (++reads > 1) throw new Error("checks read twice");
|
|
50
|
+
return checks;
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
expect(reads).toBe(1);
|
|
54
|
+
checks.push(z.minimum(10));
|
|
55
|
+
expect(z.validate(schema, 3)).toBe(true);
|
|
56
|
+
expect(z.validate(z.compile(schema), 3)).toBe(true);
|
|
57
|
+
expect(z.toJSONSchema(schema).minimum).toBe(1);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
5
61
|
test("z.boolean", () => {
|
|
6
62
|
const a = z.boolean();
|
|
7
63
|
expect(z.parse(a, true)).toEqual(true);
|
|
@@ -387,3 +387,10 @@ test("z.hash generic format", () => {
|
|
|
387
387
|
z.ZodMiniCustomStringFormat<"sha384_base64url">
|
|
388
388
|
>();
|
|
389
389
|
});
|
|
390
|
+
|
|
391
|
+
test("z.currencyCode", () => {
|
|
392
|
+
const a = z.currencyCode();
|
|
393
|
+
expectTypeOf(a).toEqualTypeOf<z.ZodMiniCustomStringFormat<"currency_code">>();
|
|
394
|
+
expect(z.parse(a, "EUR")).toBe("EUR");
|
|
395
|
+
expect(z.safeParse(a, "eur")).toMatchObject(FAIL);
|
|
396
|
+
});
|
package/v4/classic/schemas.cjs
CHANGED
|
@@ -58,6 +58,7 @@ exports.jwt = jwt;
|
|
|
58
58
|
exports.stringFormat = stringFormat;
|
|
59
59
|
exports.hostname = hostname;
|
|
60
60
|
exports.hex = hex;
|
|
61
|
+
exports.currencyCode = currencyCode;
|
|
61
62
|
exports.hash = hash;
|
|
62
63
|
exports.number = number;
|
|
63
64
|
exports.int = int;
|
|
@@ -128,6 +129,7 @@ exports.preprocess = preprocess;
|
|
|
128
129
|
const core = __importStar(require("../core/index.cjs"));
|
|
129
130
|
const index_js_1 = require("../core/index.cjs");
|
|
130
131
|
const processors = __importStar(require("../core/json-schema-processors.cjs"));
|
|
132
|
+
const regexes = __importStar(require("../core/regexes.cjs"));
|
|
131
133
|
const to_json_schema_js_1 = require("../core/to-json-schema.cjs");
|
|
132
134
|
const en_js_1 = __importDefault(require("../locales/en.cjs"));
|
|
133
135
|
const checks = __importStar(require("./checks.cjs"));
|
|
@@ -526,8 +528,8 @@ function url(params) {
|
|
|
526
528
|
}
|
|
527
529
|
function httpUrl(params) {
|
|
528
530
|
return core._url(exports.ZodURL, {
|
|
529
|
-
protocol:
|
|
530
|
-
hostname:
|
|
531
|
+
protocol: regexes.httpProtocol,
|
|
532
|
+
hostname: regexes.domain,
|
|
531
533
|
...index_js_1.util.normalizeParams(params),
|
|
532
534
|
});
|
|
533
535
|
}
|
|
@@ -692,10 +694,13 @@ function stringFormat(format, fnOrRegex, _params = {}) {
|
|
|
692
694
|
return core._stringFormat(exports.ZodCustomStringFormat, format, fnOrRegex, _params);
|
|
693
695
|
}
|
|
694
696
|
function hostname(_params) {
|
|
695
|
-
return core._stringFormat(exports.ZodCustomStringFormat, "hostname",
|
|
697
|
+
return core._stringFormat(exports.ZodCustomStringFormat, "hostname", regexes.hostname, _params);
|
|
696
698
|
}
|
|
697
699
|
function hex(_params) {
|
|
698
|
-
return core._stringFormat(exports.ZodCustomStringFormat, "hex",
|
|
700
|
+
return core._stringFormat(exports.ZodCustomStringFormat, "hex", regexes.hex, _params);
|
|
701
|
+
}
|
|
702
|
+
function currencyCode(_params) {
|
|
703
|
+
return core._stringFormat(exports.ZodCustomStringFormat, "currency_code", regexes.currencyCode, _params);
|
|
699
704
|
}
|
|
700
705
|
function hash(alg, params) {
|
|
701
706
|
const enc = params?.enc ?? "hex";
|
package/v4/classic/schemas.d.cts
CHANGED
|
@@ -330,6 +330,7 @@ export declare const ZodCustomStringFormat: core.$constructor<ZodCustomStringFor
|
|
|
330
330
|
export declare function stringFormat<Format extends string>(format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<Format>;
|
|
331
331
|
export declare function hostname(_params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<"hostname">;
|
|
332
332
|
export declare function hex(_params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<"hex">;
|
|
333
|
+
export declare function currencyCode(_params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<"currency_code">;
|
|
333
334
|
export declare function hash<Alg extends util.HashAlgorithm, Enc extends util.HashEncoding = "hex">(alg: Alg, params?: {
|
|
334
335
|
enc?: Enc;
|
|
335
336
|
} & core.$ZodStringFormatParams): ZodCustomStringFormat<`${Alg}_${Enc}`>;
|
|
@@ -787,7 +788,9 @@ export declare const describe: typeof core.describe;
|
|
|
787
788
|
export declare const meta: typeof core.meta;
|
|
788
789
|
type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
|
|
789
790
|
export interface ZodInstanceOf<T = unknown> extends ZodCustom<T, T> {
|
|
790
|
-
properties<Shape extends
|
|
791
|
+
properties<Shape extends {
|
|
792
|
+
[k in keyof T as T[k] extends Function ? never : k]?: core.$ZodType<unknown, T[k]>;
|
|
793
|
+
}>(shape: Shape, params?: string | core.$ZodCheckPropertiesParams): ZodInstanceOf<T & core.$InferObjectInput<Shape, {}>>;
|
|
791
794
|
}
|
|
792
795
|
export declare const ZodInstanceOf: core.$constructor<ZodInstanceOf>;
|
|
793
796
|
declare function _instanceof<T extends typeof util.Class>(cls: T, params?: ZodInstanceOfParams): ZodInstanceOf<InstanceType<T>>;
|
package/v4/classic/schemas.d.ts
CHANGED
|
@@ -330,6 +330,7 @@ export declare const ZodCustomStringFormat: core.$constructor<ZodCustomStringFor
|
|
|
330
330
|
export declare function stringFormat<Format extends string>(format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<Format>;
|
|
331
331
|
export declare function hostname(_params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<"hostname">;
|
|
332
332
|
export declare function hex(_params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<"hex">;
|
|
333
|
+
export declare function currencyCode(_params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<"currency_code">;
|
|
333
334
|
export declare function hash<Alg extends util.HashAlgorithm, Enc extends util.HashEncoding = "hex">(alg: Alg, params?: {
|
|
334
335
|
enc?: Enc;
|
|
335
336
|
} & core.$ZodStringFormatParams): ZodCustomStringFormat<`${Alg}_${Enc}`>;
|
|
@@ -787,7 +788,9 @@ export declare const describe: typeof core.describe;
|
|
|
787
788
|
export declare const meta: typeof core.meta;
|
|
788
789
|
type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
|
|
789
790
|
export interface ZodInstanceOf<T = unknown> extends ZodCustom<T, T> {
|
|
790
|
-
properties<Shape extends
|
|
791
|
+
properties<Shape extends {
|
|
792
|
+
[k in keyof T as T[k] extends Function ? never : k]?: core.$ZodType<unknown, T[k]>;
|
|
793
|
+
}>(shape: Shape, params?: string | core.$ZodCheckPropertiesParams): ZodInstanceOf<T & core.$InferObjectInput<Shape, {}>>;
|
|
791
794
|
}
|
|
792
795
|
export declare const ZodInstanceOf: core.$constructor<ZodInstanceOf>;
|
|
793
796
|
declare function _instanceof<T extends typeof util.Class>(cls: T, params?: ZodInstanceOfParams): ZodInstanceOf<InstanceType<T>>;
|
package/v4/classic/schemas.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as core from "../core/index.js";
|
|
2
2
|
import { util } from "../core/index.js";
|
|
3
3
|
import * as processors from "../core/json-schema-processors.js";
|
|
4
|
+
import * as regexes from "../core/regexes.js";
|
|
4
5
|
import { createStandardJSONSchemaMethod, createToJSONSchemaMethod } from "../core/to-json-schema.js";
|
|
5
6
|
import en from "../locales/en.js";
|
|
6
7
|
import * as checks from "./checks.js";
|
|
@@ -399,8 +400,8 @@ export function url(params) {
|
|
|
399
400
|
}
|
|
400
401
|
export function httpUrl(params) {
|
|
401
402
|
return core._url(ZodURL, {
|
|
402
|
-
protocol:
|
|
403
|
-
hostname:
|
|
403
|
+
protocol: regexes.httpProtocol,
|
|
404
|
+
hostname: regexes.domain,
|
|
404
405
|
...util.normalizeParams(params),
|
|
405
406
|
});
|
|
406
407
|
}
|
|
@@ -565,10 +566,13 @@ export function stringFormat(format, fnOrRegex, _params = {}) {
|
|
|
565
566
|
return core._stringFormat(ZodCustomStringFormat, format, fnOrRegex, _params);
|
|
566
567
|
}
|
|
567
568
|
export function hostname(_params) {
|
|
568
|
-
return core._stringFormat(ZodCustomStringFormat, "hostname",
|
|
569
|
+
return core._stringFormat(ZodCustomStringFormat, "hostname", regexes.hostname, _params);
|
|
569
570
|
}
|
|
570
571
|
export function hex(_params) {
|
|
571
|
-
return core._stringFormat(ZodCustomStringFormat, "hex",
|
|
572
|
+
return core._stringFormat(ZodCustomStringFormat, "hex", regexes.hex, _params);
|
|
573
|
+
}
|
|
574
|
+
export function currencyCode(_params) {
|
|
575
|
+
return core._stringFormat(ZodCustomStringFormat, "currency_code", regexes.currencyCode, _params);
|
|
572
576
|
}
|
|
573
577
|
export function hash(alg, params) {
|
|
574
578
|
const enc = params?.enc ?? "hex";
|