@infra-blocks/zod-utils 0.10.1-alpha.1 → 0.11.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 +23 -21
- package/lib/cjs/index.d.ts +5 -0
- package/lib/cjs/index.js +4 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/iso/currency-code.d.ts +21 -0
- package/lib/cjs/iso/currency-code.js +22 -0
- package/lib/cjs/iso/currency-code.js.map +1 -0
- package/lib/cjs/iso/index.d.ts +6 -0
- package/lib/cjs/iso/index.js +9 -0
- package/lib/cjs/iso/index.js.map +1 -0
- package/lib/cjs/iso/types.d.ts +1 -0
- package/lib/cjs/iso/types.js +3 -0
- package/lib/cjs/iso/types.js.map +1 -0
- package/lib/esm/index.d.ts +5 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/iso/currency-code.d.ts +21 -0
- package/lib/esm/iso/currency-code.js +18 -0
- package/lib/esm/iso/currency-code.js.map +1 -0
- package/lib/esm/iso/index.d.ts +6 -0
- package/lib/esm/iso/index.js +6 -0
- package/lib/esm/iso/index.js.map +1 -0
- package/lib/esm/iso/types.d.ts +1 -0
- package/lib/esm/iso/types.js +2 -0
- package/lib/esm/iso/types.js.map +1 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -5,10 +5,19 @@
|
|
|
5
5
|
|
|
6
6
|
This package exposes various utilities extending the [zod](https://www.npmjs.com/package/zod) package.
|
|
7
7
|
|
|
8
|
+
## Branded types
|
|
9
|
+
|
|
10
|
+
Some schemas return [branded types](https://zod.dev/api?id=branded-types) for extra type safety. When that is the case,
|
|
11
|
+
the documentation will highlight that fact. Otherwise, assume classical structural Typescript as output types.
|
|
12
|
+
|
|
13
|
+
When branding is used, the brand is a string that's the same as the name of the type. For example, the `AwsAccountId`
|
|
14
|
+
is an alias for `string & z.$brand<"AwsAccountId">`.
|
|
15
|
+
|
|
8
16
|
## API
|
|
9
17
|
|
|
10
18
|
- [aws](#aws)
|
|
11
19
|
- [geojson](#geojson)
|
|
20
|
+
- [iso](#iso)
|
|
12
21
|
- [json](#json)
|
|
13
22
|
- [csv](#csv)
|
|
14
23
|
- [typeGuard](#type-guard)
|
|
@@ -16,7 +25,7 @@ This package exposes various utilities extending the [zod](https://www.npmjs.com
|
|
|
16
25
|
|
|
17
26
|
### AWS
|
|
18
27
|
|
|
19
|
-
The `aws` module contains utilities to validate various AWS elements.
|
|
28
|
+
The `aws` module contains utilities to validate various AWS elements. All schemas return [branded types](#branded-types).
|
|
20
29
|
|
|
21
30
|
```typescript
|
|
22
31
|
import { zu } from "@infra-blocks/zod-utils";
|
|
@@ -32,25 +41,6 @@ zu.aws.partition().parse("aws");
|
|
|
32
41
|
zu.aws.region().parse("us-east-1");
|
|
33
42
|
```
|
|
34
43
|
|
|
35
|
-
#### Branded types
|
|
36
|
-
|
|
37
|
-
`aws` utilities that return primitive types are branded. Here is an example with an AWS arn:
|
|
38
|
-
|
|
39
|
-
```typescript
|
|
40
|
-
import { zu } from "@infra-blocks/zod-utils";
|
|
41
|
-
import { AwsArn } from "@infra-blocks/zod-utils/aws";
|
|
42
|
-
|
|
43
|
-
const arn = zu.aws.arn().parse("arn:aws:iam:us-east-1:123456789012:user/joe-cunt"); // The type of arn is AwsArn.
|
|
44
|
-
const splitTokensString = (x: string) => x.split(":");
|
|
45
|
-
// AwsArn is an alias for string & z.$brand<"AwsArn">. All string functionalities are still available.
|
|
46
|
-
splitTokensString(arn);
|
|
47
|
-
const splitTokensArn = (x: AwsArn) => x.split(":");
|
|
48
|
-
// Works as you'd expect.
|
|
49
|
-
splitTokensArn(arn);
|
|
50
|
-
// @ts-expect-error: string is not assignable to AwsArn
|
|
51
|
-
splitTokensArn("arn:aws:iam:us-east-1:123456789012:user/joe-cunt"); // This does not compile, as string is not assignable to AwsArn.
|
|
52
|
-
```
|
|
53
|
-
|
|
54
44
|
### GeoJson
|
|
55
45
|
|
|
56
46
|
The `geojson` module contains utilities to validate GeoJSON objects.
|
|
@@ -198,6 +188,18 @@ zu.geojson().parse({
|
|
|
198
188
|
});
|
|
199
189
|
```
|
|
200
190
|
|
|
191
|
+
### ISO
|
|
192
|
+
|
|
193
|
+
The `iso` module is an extension of `zod`'s own `iso` module. All schemas return [branded types](#branded-types).
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
import { zu } from "@infra-blocks/zod-utils";
|
|
197
|
+
import type { IsoCurrencyCode } from "@infra-blocks/zod-utils/iso";
|
|
198
|
+
|
|
199
|
+
const currency = zu.iso.currencyCode().parse("EUR");
|
|
200
|
+
zu.iso.currencyCode().parse("eur"); // BOOOOOM => currency codes are case sensitive!
|
|
201
|
+
```
|
|
202
|
+
|
|
201
203
|
### JSON
|
|
202
204
|
|
|
203
205
|
The `json` module contains utilities to validate JSON objects and stringified JSON objects.
|
|
@@ -282,7 +284,7 @@ about the rules of the type is contained within it. Example:
|
|
|
282
284
|
```typescript
|
|
283
285
|
import { z } from "zod";
|
|
284
286
|
import { zu } from "@infra-blocks/zod-utils";
|
|
285
|
-
import { expectTypeOf } from "expect-type"
|
|
287
|
+
import { expectTypeOf } from "expect-type";
|
|
286
288
|
|
|
287
289
|
export type Min5String = z.infer<typeof schema>;
|
|
288
290
|
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -63,6 +63,11 @@ declare const zu: {
|
|
|
63
63
|
polygon: typeof import("./geojson/polygon.js").polygon;
|
|
64
64
|
coordinate: typeof import("./geojson/coordinate.js").coordinate;
|
|
65
65
|
};
|
|
66
|
+
iso: {
|
|
67
|
+
currencyCode: () => z.core.$ZodBranded<z.ZodEnum<{
|
|
68
|
+
[x: string]: string;
|
|
69
|
+
}>, "IsoCurrencyCode">;
|
|
70
|
+
};
|
|
66
71
|
json: typeof import("./json/json.js").json & {
|
|
67
72
|
array: typeof import("./json/json.js").array;
|
|
68
73
|
object: typeof import("./json/json.js").object;
|
package/lib/cjs/index.js
CHANGED
|
@@ -4,7 +4,8 @@ exports.zu = void 0;
|
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const index_js_1 = require("./aws/index.js");
|
|
6
6
|
const index_js_2 = require("./geojson/index.js");
|
|
7
|
-
const index_js_3 = require("./
|
|
7
|
+
const index_js_3 = require("./iso/index.js");
|
|
8
|
+
const index_js_4 = require("./json/index.js");
|
|
8
9
|
const csvSchema = zod_1.z.string().transform((str) => str.split(","));
|
|
9
10
|
csvSchema.brand("Toto");
|
|
10
11
|
/**
|
|
@@ -67,7 +68,8 @@ function isValid(schema, value) {
|
|
|
67
68
|
const zu = {
|
|
68
69
|
aws: index_js_1.aws,
|
|
69
70
|
geojson: index_js_2.geojson,
|
|
70
|
-
|
|
71
|
+
iso: index_js_3.iso,
|
|
72
|
+
json: index_js_4.json,
|
|
71
73
|
csv,
|
|
72
74
|
stringtoInt,
|
|
73
75
|
typeGuard,
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,6BAAwB;AACxB,6CAAqC;AACrC,iDAA6C;AAC7C,8CAAuC;AAEvC,MAAM,SAAS,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAEhE,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAExB;;;;GAIG;AACH,SAAS,GAAG;IACV,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,gBAAgB,GAAG,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,OAAC,CAAC,GAAG,EAAE,EAAE;IAC7E,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAA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AG,EAAE,EAAE;IAC7E,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC;IACzC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE;CAChC,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,SAAS,WAAW;IAClB,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAS,SAAS,CAAsB,MAAS;IAC/C,OAAO,CAAC,KAAc,EAAuB,EAAE;QAC7C,OAAO,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,OAAO,CACd,MAAS,EACT,KAAc;IAEd,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACzC,CAAC;AAED,MAAM,EAAE,GAAG;IACT,GAAG,EAAH,cAAG;IACH,OAAO,EAAP,kBAAO;IACP,GAAG,EAAH,cAAG;IACH,IAAI,EAAJ,eAAI;IACJ,GAAG;IACH,WAAW;IACX,SAAS;IACT,OAAO;CACR,CAAC;AAEO,gBAAE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const currencyCodeSchema: z.core.$ZodBranded<z.ZodEnum<{
|
|
3
|
+
[x: string]: string;
|
|
4
|
+
}>, "IsoCurrencyCode">;
|
|
5
|
+
export type IsoCurrencyCode = z.infer<typeof currencyCodeSchema>;
|
|
6
|
+
/**
|
|
7
|
+
* Returns a zod schema that validates that the input is a string that matches
|
|
8
|
+
* an ISO 4217 currency 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 currency code strings and return the {@link IsoCurrencyCode}
|
|
14
|
+
* branded type as output.
|
|
15
|
+
*
|
|
16
|
+
* @see https://en.wikipedia.org/wiki/ISO_4217
|
|
17
|
+
*/
|
|
18
|
+
export declare const currencyCode: () => z.core.$ZodBranded<z.ZodEnum<{
|
|
19
|
+
[x: string]: string;
|
|
20
|
+
}>, "IsoCurrencyCode">;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.currencyCode = void 0;
|
|
4
|
+
const currencyCodes = require("currency-codes");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const ISO_CODES = currencyCodes.codes();
|
|
7
|
+
const currencyCodeSchema = zod_1.z.enum(ISO_CODES).brand("IsoCurrencyCode");
|
|
8
|
+
/**
|
|
9
|
+
* Returns a zod schema that validates that the input is a string that matches
|
|
10
|
+
* an ISO 4217 currency 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 currency code strings and return the {@link IsoCurrencyCode}
|
|
16
|
+
* branded type as output.
|
|
17
|
+
*
|
|
18
|
+
* @see https://en.wikipedia.org/wiki/ISO_4217
|
|
19
|
+
*/
|
|
20
|
+
const currencyCode = () => currencyCodeSchema;
|
|
21
|
+
exports.currencyCode = currencyCode;
|
|
22
|
+
//# sourceMappingURL=currency-code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency-code.js","sourceRoot":"","sources":["../../../src/iso/currency-code.ts"],"names":[],"mappings":";;;AAAA,gDAAgD;AAChD,6BAAwB;AAExB,MAAM,SAAS,GAAG,aAAa,CAAC,KAAK,EAAE,CAAC;AAExC,MAAM,kBAAkB,GAAG,OAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;AAItE;;;;;;;;;;;GAWG;AACI,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,kBAAkB,CAAC;AAAxC,QAAA,YAAY,gBAA4B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.iso = void 0;
|
|
4
|
+
const currency_code_js_1 = require("./currency-code.js");
|
|
5
|
+
const module = {
|
|
6
|
+
currencyCode: currency_code_js_1.currencyCode,
|
|
7
|
+
};
|
|
8
|
+
exports.iso = module;
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;CACb,CAAC;AAEiB,qBAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { IsoCurrencyCode } from "./currency-code.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/iso/types.ts"],"names":[],"mappings":""}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -63,6 +63,11 @@ declare const zu: {
|
|
|
63
63
|
polygon: typeof import("./geojson/polygon.js").polygon;
|
|
64
64
|
coordinate: typeof import("./geojson/coordinate.js").coordinate;
|
|
65
65
|
};
|
|
66
|
+
iso: {
|
|
67
|
+
currencyCode: () => z.core.$ZodBranded<z.ZodEnum<{
|
|
68
|
+
[x: string]: string;
|
|
69
|
+
}>, "IsoCurrencyCode">;
|
|
70
|
+
};
|
|
66
71
|
json: typeof import("./json/json.js").json & {
|
|
67
72
|
array: typeof import("./json/json.js").array;
|
|
68
73
|
object: typeof import("./json/json.js").object;
|
package/lib/esm/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { aws } from "./aws/index.js";
|
|
3
3
|
import { geojson } from "./geojson/index.js";
|
|
4
|
+
import { iso } from "./iso/index.js";
|
|
4
5
|
import { json } from "./json/index.js";
|
|
5
6
|
const csvSchema = z.string().transform((str) => str.split(","));
|
|
6
7
|
csvSchema.brand("Toto");
|
|
@@ -64,6 +65,7 @@ function isValid(schema, value) {
|
|
|
64
65
|
const zu = {
|
|
65
66
|
aws,
|
|
66
67
|
geojson,
|
|
68
|
+
iso,
|
|
67
69
|
json,
|
|
68
70
|
csv,
|
|
69
71
|
stringtoInt,
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAEhE,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAExB;;;;GAIG;AACH,SAAS,GAAG;IACV,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,EAAE;IAC7E,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC;IACzC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAA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,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,EAAE;IAC7E,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC;IACzC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE;CAChC,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,SAAS,WAAW;IAClB,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAS,SAAS,CAAsB,MAAS;IAC/C,OAAO,CAAC,KAAc,EAAuB,EAAE;QAC7C,OAAO,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,OAAO,CACd,MAAS,EACT,KAAc;IAEd,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACzC,CAAC;AAED,MAAM,EAAE,GAAG;IACT,GAAG;IACH,OAAO;IACP,GAAG;IACH,IAAI;IACJ,GAAG;IACH,WAAW;IACX,SAAS;IACT,OAAO;CACR,CAAC;AAEF,OAAO,EAAE,EAAE,EAAE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const currencyCodeSchema: z.core.$ZodBranded<z.ZodEnum<{
|
|
3
|
+
[x: string]: string;
|
|
4
|
+
}>, "IsoCurrencyCode">;
|
|
5
|
+
export type IsoCurrencyCode = z.infer<typeof currencyCodeSchema>;
|
|
6
|
+
/**
|
|
7
|
+
* Returns a zod schema that validates that the input is a string that matches
|
|
8
|
+
* an ISO 4217 currency 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 currency code strings and return the {@link IsoCurrencyCode}
|
|
14
|
+
* branded type as output.
|
|
15
|
+
*
|
|
16
|
+
* @see https://en.wikipedia.org/wiki/ISO_4217
|
|
17
|
+
*/
|
|
18
|
+
export declare const currencyCode: () => z.core.$ZodBranded<z.ZodEnum<{
|
|
19
|
+
[x: string]: string;
|
|
20
|
+
}>, "IsoCurrencyCode">;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as currencyCodes from "currency-codes";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
const ISO_CODES = currencyCodes.codes();
|
|
4
|
+
const currencyCodeSchema = z.enum(ISO_CODES).brand("IsoCurrencyCode");
|
|
5
|
+
/**
|
|
6
|
+
* Returns a zod schema that validates that the input is a string that matches
|
|
7
|
+
* an ISO 4217 currency 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 currency code strings and return the {@link IsoCurrencyCode}
|
|
13
|
+
* branded type as output.
|
|
14
|
+
*
|
|
15
|
+
* @see https://en.wikipedia.org/wiki/ISO_4217
|
|
16
|
+
*/
|
|
17
|
+
export const currencyCode = () => currencyCodeSchema;
|
|
18
|
+
//# sourceMappingURL=currency-code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency-code.js","sourceRoot":"","sources":["../../../src/iso/currency-code.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,SAAS,GAAG,aAAa,CAAC,KAAK,EAAE,CAAC;AAExC,MAAM,kBAAkB,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;AAItE;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,kBAAkB,CAAC"}
|
|
@@ -0,0 +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;CACb,CAAC;AAEF,OAAO,EAAE,MAAM,IAAI,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { IsoCurrencyCode } from "./currency-code.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/iso/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infra-blocks/zod-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0-alpha.0",
|
|
4
4
|
"description": "Extensions to the zod package.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zod",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@infra-blocks/types": "^0.24.0",
|
|
60
|
+
"currency-codes": "^2.2.0",
|
|
60
61
|
"zod": "^4.2.1"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|