@infra-blocks/zod-utils 0.20.0 → 0.21.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 +38 -7
- package/lib/cjs/codec/csv.d.ts +3 -3
- package/lib/cjs/codec/csv.js +4 -6
- package/lib/cjs/codec/csv.js.map +1 -1
- package/lib/cjs/codec/index.d.ts +2 -0
- package/lib/cjs/codec/index.js +5 -1
- package/lib/cjs/codec/index.js.map +1 -1
- package/lib/cjs/codec/json-parse.d.ts +10 -0
- package/lib/cjs/codec/json-parse.js +20 -0
- package/lib/cjs/codec/json-parse.js.map +1 -0
- package/lib/cjs/codec/string-split.d.ts +13 -0
- package/lib/cjs/codec/string-split.js +21 -0
- package/lib/cjs/codec/string-split.js.map +1 -0
- package/lib/cjs/codec/string-to-integer.d.ts +1 -1
- package/lib/cjs/codec/string-to-integer.js +4 -4
- package/lib/cjs/codec/string-to-integer.js.map +1 -1
- package/lib/cjs/codec/string-to-json.d.ts +6 -0
- package/lib/cjs/codec/string-to-json.js +14 -0
- package/lib/cjs/codec/string-to-json.js.map +1 -0
- package/lib/cjs/codec/string-to-url.js +2 -2
- package/lib/cjs/codec/string-to-url.js.map +1 -1
- package/lib/cjs/index.d.ts +7 -5
- package/lib/cjs/json/array.d.ts +4 -0
- package/lib/cjs/json/array.js +9 -0
- package/lib/cjs/json/array.js.map +1 -0
- package/lib/cjs/json/index.d.ts +4 -6
- package/lib/cjs/json/index.js +6 -4
- package/lib/cjs/json/index.js.map +1 -1
- package/lib/cjs/json/json.d.ts +4 -13
- package/lib/cjs/json/json.js +5 -42
- package/lib/cjs/json/json.js.map +1 -1
- package/lib/cjs/json/object.d.ts +6 -0
- package/lib/cjs/json/object.js +9 -0
- package/lib/cjs/json/object.js.map +1 -0
- package/lib/cjs/json/primitive.d.ts +5 -0
- package/lib/cjs/json/primitive.js +8 -0
- package/lib/cjs/json/primitive.js.map +1 -0
- package/lib/cjs/json/types.d.ts +4 -1
- package/lib/cjs/string/index.d.ts +1 -0
- package/lib/cjs/string/index.js +2 -0
- package/lib/cjs/string/index.js.map +1 -1
- package/lib/cjs/string/json.d.ts +9 -0
- package/lib/cjs/string/json.js +23 -0
- package/lib/cjs/string/json.js.map +1 -0
- package/lib/cjs/string/types.d.ts +1 -0
- package/lib/esm/codec/csv.d.ts +3 -3
- package/lib/esm/codec/csv.js +4 -6
- package/lib/esm/codec/csv.js.map +1 -1
- package/lib/esm/codec/index.d.ts +2 -0
- package/lib/esm/codec/index.js +6 -2
- package/lib/esm/codec/index.js.map +1 -1
- package/lib/esm/codec/json-parse.d.ts +10 -0
- package/lib/esm/codec/json-parse.js +16 -0
- package/lib/esm/codec/json-parse.js.map +1 -0
- package/lib/esm/codec/string-split.d.ts +13 -0
- package/lib/esm/codec/string-split.js +17 -0
- package/lib/esm/codec/string-split.js.map +1 -0
- package/lib/esm/codec/string-to-integer.d.ts +1 -1
- package/lib/esm/codec/string-to-integer.js +2 -2
- package/lib/esm/codec/string-to-integer.js.map +1 -1
- package/lib/esm/codec/string-to-json.d.ts +6 -0
- package/lib/esm/codec/string-to-json.js +10 -0
- package/lib/esm/codec/string-to-json.js.map +1 -0
- package/lib/esm/codec/string-to-url.js +2 -2
- package/lib/esm/codec/string-to-url.js.map +1 -1
- package/lib/esm/index.d.ts +7 -5
- package/lib/esm/json/array.d.ts +4 -0
- package/lib/esm/json/array.js +5 -0
- package/lib/esm/json/array.js.map +1 -0
- package/lib/esm/json/index.d.ts +4 -6
- package/lib/esm/json/index.js +4 -2
- package/lib/esm/json/index.js.map +1 -1
- package/lib/esm/json/json.d.ts +4 -13
- package/lib/esm/json/json.js +3 -36
- package/lib/esm/json/json.js.map +1 -1
- package/lib/esm/json/object.d.ts +6 -0
- package/lib/esm/json/object.js +5 -0
- package/lib/esm/json/object.js.map +1 -0
- package/lib/esm/json/primitive.d.ts +5 -0
- package/lib/esm/json/primitive.js +4 -0
- package/lib/esm/json/primitive.js.map +1 -0
- package/lib/esm/json/types.d.ts +4 -1
- package/lib/esm/string/index.d.ts +1 -0
- package/lib/esm/string/index.js +2 -0
- package/lib/esm/string/index.js.map +1 -1
- package/lib/esm/string/json.d.ts +9 -0
- package/lib/esm/string/json.js +19 -0
- package/lib/esm/string/json.js.map +1 -0
- package/lib/esm/string/types.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ The `zu.codec` module contains codecs.
|
|
|
57
57
|
#### csv
|
|
58
58
|
|
|
59
59
|
The `zu.codec.csv()` utility is a codec transforming a string into an array of string using the string `split` method
|
|
60
|
-
to do so.
|
|
60
|
+
to do so. It uses `zu.codec.stringSplit(",")` internally.
|
|
61
61
|
|
|
62
62
|
```typescript
|
|
63
63
|
import { zu } from "@infra-blocks/zod-utils";
|
|
@@ -65,6 +65,18 @@ import { zu } from "@infra-blocks/zod-utils";
|
|
|
65
65
|
const items = zu.codec.csv().parse("one,two,three"); // items is ["one", "two", "three"]
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
+
#### jsonParse
|
|
69
|
+
|
|
70
|
+
The `zu.codec.jsonParse(schema)` utility is a factory returning a codec where the first schema is
|
|
71
|
+
`zu.string.json()` and the second one is the one provided as input. This is almost verbatim
|
|
72
|
+
what is describe in [Zod's documentation](https://zod.dev/codecs#jsonschema).
|
|
73
|
+
|
|
74
|
+
#### stringSplit
|
|
75
|
+
|
|
76
|
+
The `zu.codec.stringSplit(separator)` utility is a factory returning a codec where the first schema is
|
|
77
|
+
`z.string()`, the second schema is `z.array(z.string())`, and the transformations back and forth
|
|
78
|
+
are accomplished using `String.split` and `Array.join` respectively, using the provided separator.
|
|
79
|
+
|
|
68
80
|
#### stringToInteger
|
|
69
81
|
|
|
70
82
|
The `zu.codec.stringToInteger()` codec is taken almost verbatim
|
|
@@ -78,6 +90,18 @@ import { Integer } from "@infra-blocks/zod-utils";
|
|
|
78
90
|
const item: Integer = zu.codec.stringToInteger().parse("1234");
|
|
79
91
|
```
|
|
80
92
|
|
|
93
|
+
#### stringToJson
|
|
94
|
+
|
|
95
|
+
The `zu.codec.stringToJson()` codec transforms a string into JSON using JSON.parse.
|
|
96
|
+
It uses `zu.codec.jsonParse(zu.json())` internally.
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import { zu } from "@infra-blocks/zod-utils";
|
|
100
|
+
import type { Json } from "@infra-blocks/zod-utils/json";
|
|
101
|
+
|
|
102
|
+
const item: Json = zu.codec.stringToJson().parse('[1, "word", null]');
|
|
103
|
+
```
|
|
104
|
+
|
|
81
105
|
#### stringToUrl
|
|
82
106
|
|
|
83
107
|
The `zu.codec.stringToUrl()` codec is taken [Zod's own documentation](https://zod.dev/codecs#stringtourl).
|
|
@@ -253,7 +277,7 @@ zu.iso.countryCode.alpha3("CAN"); // Its communist little brother.
|
|
|
253
277
|
|
|
254
278
|
### json
|
|
255
279
|
|
|
256
|
-
The `json` module contains utilities to validate JSON objects and
|
|
280
|
+
The `json` module contains utilities to validate JSON objects, arrays and primitives.
|
|
257
281
|
|
|
258
282
|
````typescript
|
|
259
283
|
import { zu } from "@infra-blocks/zod-utils";
|
|
@@ -280,11 +304,6 @@ zu.json().parse(undefined); // Boom.
|
|
|
280
304
|
zu.json().parse(Symbol("nope")); // Boom.
|
|
281
305
|
zu.json().parse(new Set()); // Boom.
|
|
282
306
|
// etc...
|
|
283
|
-
|
|
284
|
-
// You can also parse stringified JSON!
|
|
285
|
-
zu.json.stringified().parse("5"); // Returns the number 5.
|
|
286
|
-
zu.json.stringified().parse('"JSON string"'); // Returns "JSON string". Note the quotes were removed.
|
|
287
|
-
zu.json.stringified().parse(JSON.strinfify({ field: "value" })); // Returns {field: "value"}.
|
|
288
307
|
````
|
|
289
308
|
|
|
290
309
|
#### Sub schemas & Types
|
|
@@ -350,6 +369,18 @@ expectTypeOf(result).toEqualTypeOf<IntegerString>();
|
|
|
350
369
|
expect(result).to.equal("1234");
|
|
351
370
|
```
|
|
352
371
|
|
|
372
|
+
#### json
|
|
373
|
+
|
|
374
|
+
```typescript
|
|
375
|
+
import { zu } from "@infra-blocks/zod-utils";
|
|
376
|
+
import { JsonString } from "@infra-blocks/zod-utils/string";
|
|
377
|
+
import { expectTypeOf } from "expect-type";
|
|
378
|
+
|
|
379
|
+
const result = zu.string.json().parse('[1, "word", null]');
|
|
380
|
+
expectTypeOf(result).toEqualTypeOf<UrlString>();
|
|
381
|
+
expect(result).to.equal('[1, "word", null]');
|
|
382
|
+
```
|
|
383
|
+
|
|
353
384
|
### Type Guard
|
|
354
385
|
|
|
355
386
|
The `typeGuard` utility allows to obtain a function that will act as a type guard for the type
|
package/lib/cjs/codec/csv.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
1
|
/**
|
|
3
2
|
* Returns a codec that takes in a CSV string and outputs a string array.
|
|
4
3
|
*
|
|
5
|
-
* The string is splitted on the "," character.
|
|
4
|
+
* The string is splitted on the "," character. It uses `stringSplit(",")`
|
|
5
|
+
* internally.
|
|
6
6
|
*
|
|
7
7
|
* @returns A CSV codec.
|
|
8
8
|
*/
|
|
9
|
-
export declare const csv: () =>
|
|
9
|
+
export declare const csv: () => import("zod").ZodCodec<import("zod").ZodString, import("zod").ZodArray<import("zod").ZodString>>;
|
package/lib/cjs/codec/csv.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.csv = void 0;
|
|
4
|
-
const
|
|
5
|
-
const codec =
|
|
6
|
-
decode: (str) => str.split(","),
|
|
7
|
-
encode: (arr) => arr.join(","),
|
|
8
|
-
});
|
|
4
|
+
const string_split_js_1 = require("./string-split.js");
|
|
5
|
+
const codec = (0, string_split_js_1.stringSplit)(",");
|
|
9
6
|
/**
|
|
10
7
|
* Returns a codec that takes in a CSV string and outputs a string array.
|
|
11
8
|
*
|
|
12
|
-
* The string is splitted on the "," character.
|
|
9
|
+
* The string is splitted on the "," character. It uses `stringSplit(",")`
|
|
10
|
+
* internally.
|
|
13
11
|
*
|
|
14
12
|
* @returns A CSV codec.
|
|
15
13
|
*/
|
package/lib/cjs/codec/csv.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csv.js","sourceRoot":"","sources":["../../../src/codec/csv.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"csv.js","sourceRoot":"","sources":["../../../src/codec/csv.ts"],"names":[],"mappings":";;;AAAA,uDAAgD;AAEhD,MAAM,KAAK,GAAG,IAAA,6BAAW,EAAC,GAAG,CAAC,CAAC;AAE/B;;;;;;;GAOG;AACI,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC;AAAlB,QAAA,GAAG,OAAe"}
|
package/lib/cjs/codec/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
declare const codec: {
|
|
2
2
|
csv: () => import("zod").ZodCodec<import("zod").ZodString, import("zod").ZodArray<import("zod").ZodString>>;
|
|
3
|
+
jsonParse: <S extends import("zod").ZodType>(schema: S) => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodString, "JsonString">, S>;
|
|
3
4
|
stringtoInteger: () => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodString, "IntegerString">, import("zod/v4/core").$ZodBranded<import("zod").ZodInt, "Integer">>;
|
|
5
|
+
stringToJson: () => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodString, "JsonString">, import("zod").ZodType<import("../json/json.js").Json, unknown, import("zod/v4/core").$ZodTypeInternals<import("../json/json.js").Json, unknown>>>;
|
|
4
6
|
stringToUrl: () => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodURL, "UrlString">, import("zod").ZodCustom<import("url").URL, import("url").URL>>;
|
|
5
7
|
};
|
|
6
8
|
export { codec };
|
package/lib/cjs/codec/index.js
CHANGED
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.codec = void 0;
|
|
4
4
|
const csv_js_1 = require("./csv.js");
|
|
5
|
+
const json_parse_js_1 = require("./json-parse.js");
|
|
5
6
|
const string_to_integer_js_1 = require("./string-to-integer.js");
|
|
7
|
+
const string_to_json_js_1 = require("./string-to-json.js");
|
|
6
8
|
const string_to_url_js_1 = require("./string-to-url.js");
|
|
7
9
|
const codec = {
|
|
8
10
|
csv: csv_js_1.csv,
|
|
9
|
-
|
|
11
|
+
jsonParse: json_parse_js_1.jsonParse,
|
|
12
|
+
stringtoInteger: string_to_integer_js_1.stringToInteger,
|
|
13
|
+
stringToJson: string_to_json_js_1.stringToJson,
|
|
10
14
|
stringToUrl: string_to_url_js_1.stringToUrl,
|
|
11
15
|
};
|
|
12
16
|
exports.codec = codec;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/codec/index.ts"],"names":[],"mappings":";;;AAAA,qCAA+B;AAC/B,iEAAyD;AACzD,yDAAiD;AAEjD,MAAM,KAAK,GAAG;IACZ,GAAG,EAAH,YAAG;IACH,eAAe,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/codec/index.ts"],"names":[],"mappings":";;;AAAA,qCAA+B;AAC/B,mDAA4C;AAC5C,iEAAyD;AACzD,2DAAmD;AACnD,yDAAiD;AAEjD,MAAM,KAAK,GAAG;IACZ,GAAG,EAAH,YAAG;IACH,SAAS,EAAT,yBAAS;IACT,eAAe,EAAE,sCAAe;IAChC,YAAY,EAAZ,gCAAY;IACZ,WAAW,EAAX,8BAAW;CACZ,CAAC;AAEO,sBAAK"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* A codec factory that returns a codec that expects a valid JSON string
|
|
4
|
+
* as input, parses it using JSON.parse, then passes the result to the
|
|
5
|
+
* provided schema.
|
|
6
|
+
*
|
|
7
|
+
* @returns A codec where the first schema is {@link string.json}, and the
|
|
8
|
+
* second one is the provided input.
|
|
9
|
+
*/
|
|
10
|
+
export declare const jsonParse: <S extends z.ZodType>(schema: S) => z.ZodCodec<z.core.$ZodBranded<z.ZodString, "JsonString">, S>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jsonParse = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const lib_js_1 = require("../lib.js");
|
|
6
|
+
const index_js_1 = require("../string/index.js");
|
|
7
|
+
/**
|
|
8
|
+
* A codec factory that returns a codec that expects a valid JSON string
|
|
9
|
+
* as input, parses it using JSON.parse, then passes the result to the
|
|
10
|
+
* provided schema.
|
|
11
|
+
*
|
|
12
|
+
* @returns A codec where the first schema is {@link string.json}, and the
|
|
13
|
+
* second one is the provided input.
|
|
14
|
+
*/
|
|
15
|
+
const jsonParse = (schema) => zod_1.z.codec(index_js_1.string.json(), schema, {
|
|
16
|
+
decode: (str) => JSON.parse(str),
|
|
17
|
+
encode: (json) => (0, lib_js_1.trusted)(JSON.stringify(json)),
|
|
18
|
+
});
|
|
19
|
+
exports.jsonParse = jsonParse;
|
|
20
|
+
//# sourceMappingURL=json-parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-parse.js","sourceRoot":"","sources":["../../../src/codec/json-parse.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,sCAAoC;AACpC,iDAA4C;AAE5C;;;;;;;GAOG;AACI,MAAM,SAAS,GAAG,CAAsB,MAAS,EAAE,EAAE,CAC1D,OAAC,CAAC,KAAK,CAAC,iBAAM,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE;IAC7B,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;IAChC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,gBAAO,EAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;CAChD,CAAC,CAAC;AAJQ,QAAA,SAAS,aAIjB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* A codec factory that returns a codec that expects a string
|
|
4
|
+
* as input, splits it using {@link String.split} with the provided
|
|
5
|
+
* seperator, then passes the result to the provided schema.
|
|
6
|
+
*
|
|
7
|
+
* When encoding, the array is joined with the same separator provided.
|
|
8
|
+
*
|
|
9
|
+
* @returns A codec where the first schema is {@link z.string}, the
|
|
10
|
+
* second one is `z.array(z.string())`, and the transformations are
|
|
11
|
+
* done using {@link String.split} and {@link Array.join}
|
|
12
|
+
*/
|
|
13
|
+
export declare const stringSplit: (separator: string) => z.ZodCodec<z.ZodString, z.ZodArray<z.ZodString>>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringSplit = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* A codec factory that returns a codec that expects a string
|
|
7
|
+
* as input, splits it using {@link String.split} with the provided
|
|
8
|
+
* seperator, then passes the result to the provided schema.
|
|
9
|
+
*
|
|
10
|
+
* When encoding, the array is joined with the same separator provided.
|
|
11
|
+
*
|
|
12
|
+
* @returns A codec where the first schema is {@link z.string}, the
|
|
13
|
+
* second one is `z.array(z.string())`, and the transformations are
|
|
14
|
+
* done using {@link String.split} and {@link Array.join}
|
|
15
|
+
*/
|
|
16
|
+
const stringSplit = (separator) => zod_1.z.codec(zod_1.z.string(), zod_1.z.array(zod_1.z.string()), {
|
|
17
|
+
decode: (str) => str.split(separator),
|
|
18
|
+
encode: (arr) => arr.join(separator),
|
|
19
|
+
});
|
|
20
|
+
exports.stringSplit = stringSplit;
|
|
21
|
+
//# sourceMappingURL=string-split.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-split.js","sourceRoot":"","sources":["../../../src/codec/string-split.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB;;;;;;;;;;GAUG;AACI,MAAM,WAAW,GAAG,CAAC,SAAiB,EAAE,EAAE,CAC/C,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,EAAE;IACvC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC;IACrC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC;CACrC,CAAC,CAAC;AAJQ,QAAA,WAAW,eAInB"}
|
|
@@ -10,4 +10,4 @@ import { z } from "zod";
|
|
|
10
10
|
*
|
|
11
11
|
* @see https://zod.dev/codecs#stringtoint
|
|
12
12
|
*/
|
|
13
|
-
export declare const
|
|
13
|
+
export declare const stringToInteger: () => z.ZodCodec<z.core.$ZodBranded<z.ZodString, "IntegerString">, z.core.$ZodBranded<z.ZodInt, "Integer">>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.stringToInteger = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const lib_js_1 = require("../lib.js");
|
|
6
6
|
const index_js_1 = require("../number/index.js");
|
|
7
7
|
const index_js_2 = require("../string/index.js");
|
|
8
|
-
const
|
|
8
|
+
const codec = zod_1.z.codec(index_js_2.string.integer(), index_js_1.number.integer(), {
|
|
9
9
|
decode: (str) => Number.parseInt(str, 10),
|
|
10
10
|
encode: (num) => (0, lib_js_1.trusted)(num.toString()),
|
|
11
11
|
});
|
|
@@ -20,6 +20,6 @@ const stringToIntegerCodec = zod_1.z.codec(index_js_2.string.integer(), index_js
|
|
|
20
20
|
*
|
|
21
21
|
* @see https://zod.dev/codecs#stringtoint
|
|
22
22
|
*/
|
|
23
|
-
const
|
|
24
|
-
exports.
|
|
23
|
+
const stringToInteger = () => codec;
|
|
24
|
+
exports.stringToInteger = stringToInteger;
|
|
25
25
|
//# sourceMappingURL=string-to-integer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-to-integer.js","sourceRoot":"","sources":["../../../src/codec/string-to-integer.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,sCAAoC;AACpC,iDAA4C;AAC5C,iDAA4C;AAE5C,MAAM,
|
|
1
|
+
{"version":3,"file":"string-to-integer.js","sourceRoot":"","sources":["../../../src/codec/string-to-integer.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,sCAAoC;AACpC,iDAA4C;AAC5C,iDAA4C;AAE5C,MAAM,KAAK,GAAG,OAAC,CAAC,KAAK,CAAC,iBAAM,CAAC,OAAO,EAAE,EAAE,iBAAM,CAAC,OAAO,EAAE,EAAE;IACxD,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC;IACzC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,gBAAO,EAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;CACzC,CAAC,CAAC;AAEH;;;;;;;;;;GAUG;AACI,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC;AAA9B,QAAA,eAAe,mBAAe"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A string to JSON codec.
|
|
3
|
+
*
|
|
4
|
+
* @returns A string to JSON codec.
|
|
5
|
+
*/
|
|
6
|
+
export declare const stringToJson: () => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodString, "JsonString">, import("zod").ZodType<import("../json/json.js").Json, unknown, import("zod/v4/core").$ZodTypeInternals<import("../json/json.js").Json, unknown>>>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringToJson = void 0;
|
|
4
|
+
const index_js_1 = require("../json/index.js");
|
|
5
|
+
const json_parse_js_1 = require("./json-parse.js");
|
|
6
|
+
const codec = (0, json_parse_js_1.jsonParse)((0, index_js_1.json)());
|
|
7
|
+
/**
|
|
8
|
+
* A string to JSON codec.
|
|
9
|
+
*
|
|
10
|
+
* @returns A string to JSON codec.
|
|
11
|
+
*/
|
|
12
|
+
const stringToJson = () => codec;
|
|
13
|
+
exports.stringToJson = stringToJson;
|
|
14
|
+
//# sourceMappingURL=string-to-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-to-json.js","sourceRoot":"","sources":["../../../src/codec/string-to-json.ts"],"names":[],"mappings":";;;AAAA,+CAAwC;AACxC,mDAA4C;AAE5C,MAAM,KAAK,GAAG,IAAA,yBAAS,EAAC,IAAA,eAAI,GAAE,CAAC,CAAC;AAEhC;;;;GAIG;AACI,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC;AAA3B,QAAA,YAAY,gBAAe"}
|
|
@@ -4,7 +4,7 @@ exports.stringToUrl = void 0;
|
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const lib_js_1 = require("../lib.js");
|
|
6
6
|
const index_js_1 = require("../string/index.js");
|
|
7
|
-
const
|
|
7
|
+
const codec = zod_1.z.codec(index_js_1.string.url(), zod_1.z.instanceof(URL), {
|
|
8
8
|
decode: (urlString) => new URL(urlString),
|
|
9
9
|
encode: (url) => (0, lib_js_1.trusted)(url.href),
|
|
10
10
|
});
|
|
@@ -15,6 +15,6 @@ const stringToURLCodec = zod_1.z.codec(index_js_1.string.url(), zod_1.z.instance
|
|
|
15
15
|
*
|
|
16
16
|
* @see https://zod.dev/codecs#stringtourl
|
|
17
17
|
*/
|
|
18
|
-
const stringToUrl = () =>
|
|
18
|
+
const stringToUrl = () => codec;
|
|
19
19
|
exports.stringToUrl = stringToUrl;
|
|
20
20
|
//# sourceMappingURL=string-to-url.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-to-url.js","sourceRoot":"","sources":["../../../src/codec/string-to-url.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,sCAAoC;AACpC,iDAA4C;AAE5C,MAAM,
|
|
1
|
+
{"version":3,"file":"string-to-url.js","sourceRoot":"","sources":["../../../src/codec/string-to-url.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,sCAAoC;AACpC,iDAA4C;AAE5C,MAAM,KAAK,GAAG,OAAC,CAAC,KAAK,CAAC,iBAAM,CAAC,GAAG,EAAE,EAAE,OAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;IACrD,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,SAAS,CAAC;IACzC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,gBAAO,EAAC,GAAG,CAAC,IAAI,CAAC;CACnC,CAAC,CAAC;AAEH;;;;;;GAMG;AACI,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC;AAA1B,QAAA,WAAW,eAAe"}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -38,7 +38,9 @@ declare const zu: {
|
|
|
38
38
|
};
|
|
39
39
|
codec: {
|
|
40
40
|
csv: () => z.ZodCodec<z.ZodString, z.ZodArray<z.ZodString>>;
|
|
41
|
+
jsonParse: <S extends z.ZodType>(schema: S) => z.ZodCodec<z.core.$ZodBranded<z.ZodString, "JsonString">, S>;
|
|
41
42
|
stringtoInteger: () => z.ZodCodec<z.core.$ZodBranded<z.ZodString, "IntegerString">, z.core.$ZodBranded<z.ZodInt, "Integer">>;
|
|
43
|
+
stringToJson: () => z.ZodCodec<z.core.$ZodBranded<z.ZodString, "JsonString">, z.ZodType<import("./json/json.js").Json, unknown, z.core.$ZodTypeInternals<import("./json/json.js").Json, unknown>>>;
|
|
42
44
|
stringToUrl: () => z.ZodCodec<z.core.$ZodBranded<z.ZodURL, "UrlString">, z.ZodCustom<import("url").URL, import("url").URL>>;
|
|
43
45
|
};
|
|
44
46
|
geojson: typeof import("./geojson/geojson.js").geojson & {
|
|
@@ -64,17 +66,17 @@ declare const zu: {
|
|
|
64
66
|
}>, "IsoAlpha3CountryCode">;
|
|
65
67
|
};
|
|
66
68
|
};
|
|
67
|
-
json:
|
|
68
|
-
array:
|
|
69
|
-
object:
|
|
70
|
-
primitive:
|
|
71
|
-
stringified: typeof import("./json/json.js").stringifiedJson;
|
|
69
|
+
json: (() => z.ZodType<import("./json/json.js").Json, unknown, z.core.$ZodTypeInternals<import("./json/json.js").Json, unknown>>) & {
|
|
70
|
+
array: () => z.ZodArray<z.ZodType<import("./json/json.js").Json, unknown, z.core.$ZodTypeInternals<import("./json/json.js").Json, unknown>>>;
|
|
71
|
+
object: () => z.ZodRecord<z.ZodString, z.ZodType<import("./json/json.js").Json, unknown, z.core.$ZodTypeInternals<import("./json/json.js").Json, unknown>>>;
|
|
72
|
+
primitive: () => z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
|
|
72
73
|
};
|
|
73
74
|
number: {
|
|
74
75
|
integer: () => z.core.$ZodBranded<z.ZodInt, "Integer">;
|
|
75
76
|
};
|
|
76
77
|
string: {
|
|
77
78
|
integer: () => z.core.$ZodBranded<z.ZodString, "IntegerString">;
|
|
79
|
+
json: () => z.core.$ZodBranded<z.ZodString, "JsonString">;
|
|
78
80
|
url: () => z.core.$ZodBranded<z.ZodURL, "UrlString">;
|
|
79
81
|
};
|
|
80
82
|
isValid: typeof isValid;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.array = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const json_js_1 = require("./json.js");
|
|
6
|
+
const schema = zod_1.z.array((0, json_js_1.json)());
|
|
7
|
+
const array = () => schema;
|
|
8
|
+
exports.array = array;
|
|
9
|
+
//# sourceMappingURL=array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../../src/json/array.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,uCAA4C;AAE5C,MAAM,MAAM,GAAG,OAAC,CAAC,KAAK,CAAC,IAAA,cAAI,GAAE,CAAC,CAAC;AAIxB,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC;AAArB,QAAA,KAAK,SAAgB"}
|
package/lib/cjs/json/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
primitive: typeof primitive;
|
|
6
|
-
stringified: typeof stringifiedJson;
|
|
1
|
+
declare const module: (() => import("zod").ZodType<import("./json.js").Json, unknown, import("zod/v4/core").$ZodTypeInternals<import("./json.js").Json, unknown>>) & {
|
|
2
|
+
array: () => import("zod").ZodArray<import("zod").ZodType<import("./json.js").Json, unknown, import("zod/v4/core").$ZodTypeInternals<import("./json.js").Json, unknown>>>;
|
|
3
|
+
object: () => import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodType<import("./json.js").Json, unknown, import("zod/v4/core").$ZodTypeInternals<import("./json.js").Json, unknown>>>;
|
|
4
|
+
primitive: () => import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber, import("zod").ZodBoolean, import("zod").ZodNull]>;
|
|
7
5
|
};
|
|
8
6
|
export { module as json };
|
package/lib/cjs/json/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.json = void 0;
|
|
4
|
+
const array_js_1 = require("./array.js");
|
|
4
5
|
const json_js_1 = require("./json.js");
|
|
6
|
+
const object_js_1 = require("./object.js");
|
|
7
|
+
const primitive_js_1 = require("./primitive.js");
|
|
5
8
|
const module = Object.assign(json_js_1.json, {
|
|
6
|
-
array:
|
|
7
|
-
object:
|
|
8
|
-
primitive:
|
|
9
|
-
stringified: json_js_1.stringifiedJson,
|
|
9
|
+
array: array_js_1.array,
|
|
10
|
+
object: object_js_1.object,
|
|
11
|
+
primitive: primitive_js_1.primitive,
|
|
10
12
|
});
|
|
11
13
|
exports.json = module;
|
|
12
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/json/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/json/index.ts"],"names":[],"mappings":";;;AAAA,yCAAmC;AACnC,uCAAiC;AACjC,2CAAqC;AACrC,iDAA2C;AAE3C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,cAAI,EAAE;IACjC,KAAK,EAAL,gBAAK;IACL,MAAM,EAAN,kBAAM;IACN,SAAS,EAAT,wBAAS;CACV,CAAC,CAAC;AAEgB,sBAAI"}
|
package/lib/cjs/json/json.d.ts
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export type JsonObject = {
|
|
6
|
-
[key: string]: Json;
|
|
7
|
-
};
|
|
8
|
-
export type JsonArray = Array<Json>;
|
|
2
|
+
import type { JsonArray } from "./array.js";
|
|
3
|
+
import type { JsonObject } from "./object.js";
|
|
4
|
+
import { type JsonPrimitive } from "./primitive.js";
|
|
9
5
|
export type Json = JsonPrimitive | JsonObject | JsonArray;
|
|
10
|
-
export declare
|
|
11
|
-
export declare function object(): z.ZodRecord<z.ZodString, z.ZodType<Json, unknown, z.core.$ZodTypeInternals<Json, unknown>>>;
|
|
12
|
-
export declare function array(): z.ZodArray<z.ZodType<Json, unknown, z.core.$ZodTypeInternals<Json, unknown>>>;
|
|
13
|
-
export declare const stringifiedJsonSchema: z.ZodType<Json, string>;
|
|
14
|
-
export declare function stringifiedJson(): z.ZodType<Json, string, z.core.$ZodTypeInternals<Json, string>>;
|
|
15
|
-
export {};
|
|
6
|
+
export declare const json: () => z.ZodType<Json, unknown, z.core.$ZodTypeInternals<Json, unknown>>;
|
package/lib/cjs/json/json.js
CHANGED
|
@@ -1,46 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.primitive = primitive;
|
|
5
|
-
exports.json = json;
|
|
6
|
-
exports.object = object;
|
|
7
|
-
exports.array = array;
|
|
8
|
-
exports.stringifiedJson = stringifiedJson;
|
|
3
|
+
exports.json = void 0;
|
|
9
4
|
const zod_1 = require("zod");
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
zod_1.z.null(),
|
|
15
|
-
]);
|
|
16
|
-
function primitive() {
|
|
17
|
-
return primitiveSchema;
|
|
18
|
-
}
|
|
19
|
-
const jsonSchema = zod_1.z.lazy(() => zod_1.z.union([primitive(), zod_1.z.array(jsonSchema), zod_1.z.record(zod_1.z.string(), jsonSchema)]));
|
|
20
|
-
function json() {
|
|
21
|
-
return jsonSchema;
|
|
22
|
-
}
|
|
23
|
-
const objectSchema = zod_1.z.record(zod_1.z.string(), jsonSchema);
|
|
24
|
-
function object() {
|
|
25
|
-
return objectSchema;
|
|
26
|
-
}
|
|
27
|
-
const arraySchema = zod_1.z.array(jsonSchema);
|
|
28
|
-
function array() {
|
|
29
|
-
return arraySchema;
|
|
30
|
-
}
|
|
31
|
-
// TODO: codec stringToJson.
|
|
32
|
-
exports.stringifiedJsonSchema = zod_1.z
|
|
33
|
-
.string()
|
|
34
|
-
.transform((str, ctx) => {
|
|
35
|
-
try {
|
|
36
|
-
return JSON.parse(str);
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
ctx.addIssue({ code: "custom", message: "Invalid JSON" });
|
|
40
|
-
return zod_1.z.NEVER;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
function stringifiedJson() {
|
|
44
|
-
return exports.stringifiedJsonSchema;
|
|
45
|
-
}
|
|
5
|
+
const primitive_js_1 = require("./primitive.js");
|
|
6
|
+
const schema = zod_1.z.lazy(() => zod_1.z.union([(0, primitive_js_1.primitive)(), zod_1.z.array(schema), zod_1.z.record(zod_1.z.string(), schema)]));
|
|
7
|
+
const json = () => schema;
|
|
8
|
+
exports.json = json;
|
|
46
9
|
//# sourceMappingURL=json.js.map
|
package/lib/cjs/json/json.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/json/json.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/json/json.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAGxB,iDAA+D;AAE/D,MAAM,MAAM,GAAoB,OAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAC1C,OAAC,CAAC,KAAK,CAAC,CAAC,IAAA,wBAAS,GAAE,EAAE,OAAC,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CACtE,CAAC;AAIK,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC;AAApB,QAAA,IAAI,QAAgB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.object = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const json_js_1 = require("./json.js");
|
|
6
|
+
const schema = zod_1.z.record(zod_1.z.string(), (0, json_js_1.json)());
|
|
7
|
+
const object = () => schema;
|
|
8
|
+
exports.object = object;
|
|
9
|
+
//# sourceMappingURL=object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../../src/json/object.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,uCAA4C;AAE5C,MAAM,MAAM,GAAG,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,IAAA,cAAI,GAAE,CAAC,CAAC;AAIrC,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC;AAAtB,QAAA,MAAM,UAAgB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const schema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
|
|
3
|
+
export type JsonPrimitive = z.infer<typeof schema>;
|
|
4
|
+
export declare const primitive: () => z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.primitive = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const schema = zod_1.z.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.boolean(), zod_1.z.null()]);
|
|
6
|
+
const primitive = () => schema;
|
|
7
|
+
exports.primitive = primitive;
|
|
8
|
+
//# sourceMappingURL=primitive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitive.js","sourceRoot":"","sources":["../../../src/json/primitive.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,MAAM,MAAM,GAAG,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,OAAO,EAAE,EAAE,OAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAIjE,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC;AAAzB,QAAA,SAAS,aAAgB"}
|
package/lib/cjs/json/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
declare const string: {
|
|
2
2
|
integer: () => import("zod/v4/core").$ZodBranded<import("zod").ZodString, "IntegerString">;
|
|
3
|
+
json: () => import("zod/v4/core").$ZodBranded<import("zod").ZodString, "JsonString">;
|
|
3
4
|
url: () => import("zod/v4/core").$ZodBranded<import("zod").ZodURL, "UrlString">;
|
|
4
5
|
};
|
|
5
6
|
export { string };
|
package/lib/cjs/string/index.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.string = void 0;
|
|
4
4
|
const integer_js_1 = require("./integer.js");
|
|
5
|
+
const json_js_1 = require("./json.js");
|
|
5
6
|
const url_js_1 = require("./url.js");
|
|
6
7
|
const string = {
|
|
7
8
|
integer: integer_js_1.integer,
|
|
9
|
+
json: json_js_1.json,
|
|
8
10
|
url: url_js_1.url,
|
|
9
11
|
};
|
|
10
12
|
exports.string = string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/string/index.ts"],"names":[],"mappings":";;;AAAA,6CAAuC;AACvC,qCAA+B;AAE/B,MAAM,MAAM,GAAG;IACb,OAAO,EAAP,oBAAO;IACP,GAAG,EAAH,YAAG;CACJ,CAAC;AAEO,wBAAM"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/string/index.ts"],"names":[],"mappings":";;;AAAA,6CAAuC;AACvC,uCAAiC;AACjC,qCAA+B;AAE/B,MAAM,MAAM,GAAG;IACb,OAAO,EAAP,oBAAO;IACP,IAAI,EAAJ,cAAI;IACJ,GAAG,EAAH,YAAG;CACJ,CAAC;AAEO,wBAAM"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const schema: z.core.$ZodBranded<z.ZodString, "JsonString">;
|
|
3
|
+
export type JsonString = z.infer<typeof schema>;
|
|
4
|
+
/**
|
|
5
|
+
* @returns A schema that validates its input as a JSON string and returns a {@link JsonString}
|
|
6
|
+
* upon success.
|
|
7
|
+
*/
|
|
8
|
+
export declare const json: () => z.core.$ZodBranded<z.ZodString, "JsonString">;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.json = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const schema = zod_1.z
|
|
6
|
+
.string()
|
|
7
|
+
.refine((s) => {
|
|
8
|
+
try {
|
|
9
|
+
JSON.parse(s);
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}, { error: "invalid JSON string" })
|
|
16
|
+
.brand("JsonString");
|
|
17
|
+
/**
|
|
18
|
+
* @returns A schema that validates its input as a JSON string and returns a {@link JsonString}
|
|
19
|
+
* upon success.
|
|
20
|
+
*/
|
|
21
|
+
const json = () => schema;
|
|
22
|
+
exports.json = json;
|
|
23
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/string/json.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,MAAM,MAAM,GAAG,OAAC;KACb,MAAM,EAAE;KACR,MAAM,CACL,CAAC,CAAC,EAAE,EAAE;IACJ,IAAI,CAAC;QACH,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,EACD,EAAE,KAAK,EAAE,qBAAqB,EAAE,CACjC;KACA,KAAK,CAAC,YAAY,CAAC,CAAC;AAIvB;;;GAGG;AACI,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC;AAApB,QAAA,IAAI,QAAgB"}
|