@infra-blocks/zod-utils 0.11.1-alpha.0 → 0.12.0-alpha.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/README.md +6 -3
- package/lib/cjs/index.d.ts +5 -0
- package/lib/cjs/iso/country-code.d.ts +23 -0
- package/lib/cjs/iso/country-code.js +23 -0
- package/lib/cjs/iso/country-code.js.map +1 -0
- package/lib/cjs/iso/index.d.ts +5 -0
- package/lib/cjs/iso/index.js +2 -0
- package/lib/cjs/iso/index.js.map +1 -1
- package/lib/cjs/iso/types.d.ts +1 -0
- package/lib/esm/index.d.ts +5 -0
- package/lib/esm/iso/country-code.d.ts +23 -0
- package/lib/esm/iso/country-code.js +20 -0
- package/lib/esm/iso/country-code.js.map +1 -0
- package/lib/esm/iso/index.d.ts +5 -0
- package/lib/esm/iso/index.js +2 -0
- package/lib/esm/iso/index.js.map +1 -1
- package/lib/esm/iso/types.d.ts +1 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -194,10 +194,13 @@ The `iso` module is an extension of `zod`'s own `iso` module. All schemas return
|
|
|
194
194
|
|
|
195
195
|
```typescript
|
|
196
196
|
import { zu } from "@infra-blocks/zod-utils";
|
|
197
|
-
import type { IsoCurrencyCode } from "@infra-blocks/zod-utils/iso";
|
|
197
|
+
import type { IsoCurrencyCode, IsoAlpha3CountryCode } from "@infra-blocks/zod-utils/iso";
|
|
198
198
|
|
|
199
|
-
|
|
200
|
-
zu.iso.currencyCode().parse("
|
|
199
|
+
zu.iso.currencyCode().parse("USD");
|
|
200
|
+
zu.iso.currencyCode().parse("CAD");
|
|
201
|
+
|
|
202
|
+
zu.iso.countryCode.alpha3("USA"); // The greatest country on earth.
|
|
203
|
+
zu.iso.countryCode.alpha3("CAN"); // Its communist little brother.
|
|
201
204
|
```
|
|
202
205
|
|
|
203
206
|
### JSON
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -67,6 +67,11 @@ declare const zu: {
|
|
|
67
67
|
currencyCode: () => z.core.$ZodBranded<z.ZodEnum<{
|
|
68
68
|
[x: string]: string;
|
|
69
69
|
}>, "IsoCurrencyCode">;
|
|
70
|
+
countryCode: {
|
|
71
|
+
alpha3: () => z.core.$ZodBranded<z.ZodEnum<{
|
|
72
|
+
[x: string]: string;
|
|
73
|
+
}>, "IsoAlpha3CountryCode">;
|
|
74
|
+
};
|
|
70
75
|
};
|
|
71
76
|
json: typeof import("./json/json.js").json & {
|
|
72
77
|
array: typeof import("./json/json.js").array;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const alpha3CodeSchema: z.core.$ZodBranded<z.ZodEnum<{
|
|
3
|
+
[x: string]: string;
|
|
4
|
+
}>, "IsoAlpha3CountryCode">;
|
|
5
|
+
export type IsoAlpha3CountryCode = z.infer<typeof alpha3CodeSchema>;
|
|
6
|
+
/**
|
|
7
|
+
* Returns a zod schema that validates that the input is a string that matches
|
|
8
|
+
* an ISO 3166 alpha 3 country code.
|
|
9
|
+
*
|
|
10
|
+
* The currency code is case-sensitive and all current currency codes are
|
|
11
|
+
* all uppercase.
|
|
12
|
+
*
|
|
13
|
+
* @returns A zod schema that validates ISO alpha 3 code strings and return the {@link IsoAlpha3CountryCode}
|
|
14
|
+
* branded type as output.
|
|
15
|
+
*
|
|
16
|
+
* @see https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
|
|
17
|
+
*/
|
|
18
|
+
export declare const countryCode: {
|
|
19
|
+
alpha3: () => z.core.$ZodBranded<z.ZodEnum<{
|
|
20
|
+
[x: string]: string;
|
|
21
|
+
}>, "IsoAlpha3CountryCode">;
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.countryCode = void 0;
|
|
4
|
+
const iso_3166_1 = require("iso-3166");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const ALPHA_3_CODES = iso_3166_1.iso31661.map((entry) => entry.alpha3);
|
|
7
|
+
const alpha3CodeSchema = zod_1.z.enum(ALPHA_3_CODES).brand("IsoAlpha3CountryCode");
|
|
8
|
+
/**
|
|
9
|
+
* Returns a zod schema that validates that the input is a string that matches
|
|
10
|
+
* an ISO 3166 alpha 3 country code.
|
|
11
|
+
*
|
|
12
|
+
* The currency code is case-sensitive and all current currency codes are
|
|
13
|
+
* all uppercase.
|
|
14
|
+
*
|
|
15
|
+
* @returns A zod schema that validates ISO alpha 3 code strings and return the {@link IsoAlpha3CountryCode}
|
|
16
|
+
* branded type as output.
|
|
17
|
+
*
|
|
18
|
+
* @see https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
|
|
19
|
+
*/
|
|
20
|
+
exports.countryCode = {
|
|
21
|
+
alpha3: () => alpha3CodeSchema,
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=country-code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"country-code.js","sourceRoot":"","sources":["../../../src/iso/country-code.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AACpC,6BAAwB;AAExB,MAAM,aAAa,GAAG,mBAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAE5D,MAAM,gBAAgB,GAAG,OAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAI7E;;;;;;;;;;;GAWG;AACU,QAAA,WAAW,GAAG;IACzB,MAAM,EAAE,GAAG,EAAE,CAAC,gBAAgB;CAC/B,CAAC"}
|
package/lib/cjs/iso/index.d.ts
CHANGED
|
@@ -2,5 +2,10 @@ declare const module: {
|
|
|
2
2
|
currencyCode: () => import("zod/v4/core").$ZodBranded<import("zod").ZodEnum<{
|
|
3
3
|
[x: string]: string;
|
|
4
4
|
}>, "IsoCurrencyCode">;
|
|
5
|
+
countryCode: {
|
|
6
|
+
alpha3: () => import("zod/v4/core").$ZodBranded<import("zod").ZodEnum<{
|
|
7
|
+
[x: string]: string;
|
|
8
|
+
}>, "IsoAlpha3CountryCode">;
|
|
9
|
+
};
|
|
5
10
|
};
|
|
6
11
|
export { module as iso };
|
package/lib/cjs/iso/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.iso = void 0;
|
|
4
|
+
const country_code_js_1 = require("./country-code.js");
|
|
4
5
|
const currency_code_js_1 = require("./currency-code.js");
|
|
5
6
|
const module = {
|
|
6
7
|
currencyCode: currency_code_js_1.currencyCode,
|
|
8
|
+
countryCode: country_code_js_1.countryCode,
|
|
7
9
|
};
|
|
8
10
|
exports.iso = module;
|
|
9
11
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/iso/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/iso/index.ts"],"names":[],"mappings":";;;AAAA,yDAAkD;AAElD,MAAM,MAAM,GAAG;IACb,YAAY,EAAZ,+BAAY;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/iso/index.ts"],"names":[],"mappings":";;;AAAA,uDAAgD;AAChD,yDAAkD;AAElD,MAAM,MAAM,GAAG;IACb,YAAY,EAAZ,+BAAY;IACZ,WAAW,EAAX,6BAAW;CACZ,CAAC;AAEiB,qBAAG"}
|
package/lib/cjs/iso/types.d.ts
CHANGED
package/lib/esm/index.d.ts
CHANGED
|
@@ -67,6 +67,11 @@ declare const zu: {
|
|
|
67
67
|
currencyCode: () => z.core.$ZodBranded<z.ZodEnum<{
|
|
68
68
|
[x: string]: string;
|
|
69
69
|
}>, "IsoCurrencyCode">;
|
|
70
|
+
countryCode: {
|
|
71
|
+
alpha3: () => z.core.$ZodBranded<z.ZodEnum<{
|
|
72
|
+
[x: string]: string;
|
|
73
|
+
}>, "IsoAlpha3CountryCode">;
|
|
74
|
+
};
|
|
70
75
|
};
|
|
71
76
|
json: typeof import("./json/json.js").json & {
|
|
72
77
|
array: typeof import("./json/json.js").array;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const alpha3CodeSchema: z.core.$ZodBranded<z.ZodEnum<{
|
|
3
|
+
[x: string]: string;
|
|
4
|
+
}>, "IsoAlpha3CountryCode">;
|
|
5
|
+
export type IsoAlpha3CountryCode = z.infer<typeof alpha3CodeSchema>;
|
|
6
|
+
/**
|
|
7
|
+
* Returns a zod schema that validates that the input is a string that matches
|
|
8
|
+
* an ISO 3166 alpha 3 country code.
|
|
9
|
+
*
|
|
10
|
+
* The currency code is case-sensitive and all current currency codes are
|
|
11
|
+
* all uppercase.
|
|
12
|
+
*
|
|
13
|
+
* @returns A zod schema that validates ISO alpha 3 code strings and return the {@link IsoAlpha3CountryCode}
|
|
14
|
+
* branded type as output.
|
|
15
|
+
*
|
|
16
|
+
* @see https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
|
|
17
|
+
*/
|
|
18
|
+
export declare const countryCode: {
|
|
19
|
+
alpha3: () => z.core.$ZodBranded<z.ZodEnum<{
|
|
20
|
+
[x: string]: string;
|
|
21
|
+
}>, "IsoAlpha3CountryCode">;
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { iso31661 } from "iso-3166";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
const ALPHA_3_CODES = iso31661.map((entry) => entry.alpha3);
|
|
4
|
+
const alpha3CodeSchema = z.enum(ALPHA_3_CODES).brand("IsoAlpha3CountryCode");
|
|
5
|
+
/**
|
|
6
|
+
* Returns a zod schema that validates that the input is a string that matches
|
|
7
|
+
* an ISO 3166 alpha 3 country code.
|
|
8
|
+
*
|
|
9
|
+
* The currency code is case-sensitive and all current currency codes are
|
|
10
|
+
* all uppercase.
|
|
11
|
+
*
|
|
12
|
+
* @returns A zod schema that validates ISO alpha 3 code strings and return the {@link IsoAlpha3CountryCode}
|
|
13
|
+
* branded type as output.
|
|
14
|
+
*
|
|
15
|
+
* @see https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
|
|
16
|
+
*/
|
|
17
|
+
export const countryCode = {
|
|
18
|
+
alpha3: () => alpha3CodeSchema,
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=country-code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"country-code.js","sourceRoot":"","sources":["../../../src/iso/country-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,aAAa,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAE5D,MAAM,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAI7E;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,MAAM,EAAE,GAAG,EAAE,CAAC,gBAAgB;CAC/B,CAAC"}
|
package/lib/esm/iso/index.d.ts
CHANGED
|
@@ -2,5 +2,10 @@ declare const module: {
|
|
|
2
2
|
currencyCode: () => import("zod/v4/core").$ZodBranded<import("zod").ZodEnum<{
|
|
3
3
|
[x: string]: string;
|
|
4
4
|
}>, "IsoCurrencyCode">;
|
|
5
|
+
countryCode: {
|
|
6
|
+
alpha3: () => import("zod/v4/core").$ZodBranded<import("zod").ZodEnum<{
|
|
7
|
+
[x: string]: string;
|
|
8
|
+
}>, "IsoAlpha3CountryCode">;
|
|
9
|
+
};
|
|
5
10
|
};
|
|
6
11
|
export { module as iso };
|
package/lib/esm/iso/index.js
CHANGED
package/lib/esm/iso/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/iso/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,MAAM,GAAG;IACb,YAAY;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/iso/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,MAAM,GAAG;IACb,YAAY;IACZ,WAAW;CACZ,CAAC;AAEF,OAAO,EAAE,MAAM,IAAI,GAAG,EAAE,CAAC"}
|
package/lib/esm/iso/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infra-blocks/zod-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0-alpha.0",
|
|
4
4
|
"description": "Extensions to the zod package.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zod",
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@infra-blocks/types": "^0.24.0",
|
|
65
65
|
"currency-codes": "^2.2.0",
|
|
66
|
+
"iso-3166": "^4.4.0",
|
|
66
67
|
"zod": "^4.2.1"
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|