@infra-blocks/zod-utils 0.7.0 → 0.8.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.
@@ -6,6 +6,14 @@ import { z } from "zod";
6
6
  * @returns A CSV schema.
7
7
  */
8
8
  declare function csv(): z.ZodPipe<z.ZodString, z.ZodTransform<string[], string>>;
9
+ /**
10
+ * A string to integer codec, as defined in Zod's documentation.
11
+ *
12
+ * @returns A string to int codec.
13
+ *
14
+ * @see https://zod.dev/codecs?id=stringtoint
15
+ */
16
+ declare function stringtoInt(): z.ZodCodec<z.ZodString, z.ZodInt>;
9
17
  /**
10
18
  * Returns a type guard function using the provided schema as the source of truth.
11
19
  *
@@ -146,6 +154,7 @@ declare const zu: {
146
154
  stringified: typeof import("./json/json.js").stringifiedJson;
147
155
  };
148
156
  csv: typeof csv;
157
+ stringtoInt: typeof stringtoInt;
149
158
  typeGuard: typeof typeGuard;
150
159
  validate: typeof validate;
151
160
  };
package/lib/cjs/index.js CHANGED
@@ -14,6 +14,20 @@ csvSchema.brand("Toto");
14
14
  function csv() {
15
15
  return csvSchema;
16
16
  }
17
+ const stringToIntCodec = zod_1.z.codec(zod_1.z.string().regex(zod_1.z.regexes.integer), zod_1.z.int(), {
18
+ decode: (str) => Number.parseInt(str, 10),
19
+ encode: (num) => num.toString(),
20
+ });
21
+ /**
22
+ * A string to integer codec, as defined in Zod's documentation.
23
+ *
24
+ * @returns A string to int codec.
25
+ *
26
+ * @see https://zod.dev/codecs?id=stringtoint
27
+ */
28
+ function stringtoInt() {
29
+ return stringToIntCodec;
30
+ }
17
31
  /**
18
32
  * Returns a type guard function using the provided schema as the source of truth.
19
33
  *
@@ -53,6 +67,7 @@ const zu = {
53
67
  geojson: index_js_1.geojson,
54
68
  json: index_js_2.json,
55
69
  csv,
70
+ stringtoInt,
56
71
  typeGuard,
57
72
  validate,
58
73
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,6BAAwB;AACxB,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;;;;;;;;;;;;;;GAcG;AACH,SAAS,SAAS,CAAsB,MAAS;IAC/C,OAAO,CAAC,KAAc,EAAuB,EAAE;QAC7C,OAAO,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,QAAQ,CACf,MAAS,EACT,KAAc;IAEd,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACzC,CAAC;AAED,MAAM,EAAE,GAAG;IACT,OAAO,EAAP,kBAAO;IACP,IAAI,EAAJ,eAAI;IACJ,GAAG;IACH,SAAS;IACT,QAAQ;CACT,CAAC;AAEO,gBAAE"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,6BAAwB;AACxB,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,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,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,QAAQ,CACf,MAAS,EACT,KAAc;IAEd,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACzC,CAAC;AAED,MAAM,EAAE,GAAG;IACT,OAAO,EAAP,kBAAO;IACP,IAAI,EAAJ,eAAI;IACJ,GAAG;IACH,WAAW;IACX,SAAS;IACT,QAAQ;CACT,CAAC;AAEO,gBAAE"}
@@ -6,6 +6,14 @@ import { z } from "zod";
6
6
  * @returns A CSV schema.
7
7
  */
8
8
  declare function csv(): z.ZodPipe<z.ZodString, z.ZodTransform<string[], string>>;
9
+ /**
10
+ * A string to integer codec, as defined in Zod's documentation.
11
+ *
12
+ * @returns A string to int codec.
13
+ *
14
+ * @see https://zod.dev/codecs?id=stringtoint
15
+ */
16
+ declare function stringtoInt(): z.ZodCodec<z.ZodString, z.ZodInt>;
9
17
  /**
10
18
  * Returns a type guard function using the provided schema as the source of truth.
11
19
  *
@@ -146,6 +154,7 @@ declare const zu: {
146
154
  stringified: typeof import("./json/json.js").stringifiedJson;
147
155
  };
148
156
  csv: typeof csv;
157
+ stringtoInt: typeof stringtoInt;
149
158
  typeGuard: typeof typeGuard;
150
159
  validate: typeof validate;
151
160
  };
package/lib/esm/index.js CHANGED
@@ -11,6 +11,20 @@ csvSchema.brand("Toto");
11
11
  function csv() {
12
12
  return csvSchema;
13
13
  }
14
+ const stringToIntCodec = z.codec(z.string().regex(z.regexes.integer), z.int(), {
15
+ decode: (str) => Number.parseInt(str, 10),
16
+ encode: (num) => num.toString(),
17
+ });
18
+ /**
19
+ * A string to integer codec, as defined in Zod's documentation.
20
+ *
21
+ * @returns A string to int codec.
22
+ *
23
+ * @see https://zod.dev/codecs?id=stringtoint
24
+ */
25
+ function stringtoInt() {
26
+ return stringToIntCodec;
27
+ }
14
28
  /**
15
29
  * Returns a type guard function using the provided schema as the source of truth.
16
30
  *
@@ -50,6 +64,7 @@ const zu = {
50
64
  geojson,
51
65
  json,
52
66
  csv,
67
+ stringtoInt,
53
68
  typeGuard,
54
69
  validate,
55
70
  };
@@ -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,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;;;;;;;;;;;;;;GAcG;AACH,SAAS,SAAS,CAAsB,MAAS;IAC/C,OAAO,CAAC,KAAc,EAAuB,EAAE;QAC7C,OAAO,QAAQ,CAAC,MAAM,EAAE,KA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;;;;;GAcG;AACH,SAAS,SAAS,CAAsB,MAAS;IAC/C,OAAO,CAAC,KAAc,EAAuB,EAAE;QAC7C,OAAO,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,QAAQ,CACf,MAAS,EACT,KAAc;IAEd,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACzC,CAAC;AAED,MAAM,EAAE,GAAG;IACT,OAAO;IACP,IAAI;IACJ,GAAG;IACH,WAAW;IACX,SAAS;IACT,QAAQ;CACT,CAAC;AAEF,OAAO,EAAE,EAAE,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infra-blocks/zod-utils",
3
- "version": "0.7.0",
3
+ "version": "0.8.0-alpha.0",
4
4
  "description": "Extensions to the zod package.",
5
5
  "keywords": [
6
6
  "zod",