@infra-blocks/zod-utils 0.29.0-alpha.0 → 0.30.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 CHANGED
@@ -135,6 +135,18 @@ import { zu } from "@infra-blocks/zod-utils";
135
135
  const item: zu.Json = zu.codec.stringToJson().parse('[1, "word", null]');
136
136
  ```
137
137
 
138
+ #### stringToPositiveInteger
139
+
140
+ The `zu.codec.stringToPositiveInteger()` is the `positiveInteger` variant of `zu.codec.stringToInteger`.
141
+ The final type is `zu.PositiveInteger`.
142
+
143
+ ```typescript
144
+ import { zu } from "@infra-blocks/zod-utils";
145
+ import { PositiveInteger } from "@infra-blocks/zod-utils";
146
+
147
+ const item: PositiveInteger = zu.codec.stringToPositiveInteger().parse("1234");
148
+ ```
149
+
138
150
  #### stringToUrl
139
151
 
140
152
  The `zu.codec.stringToUrl()` codec is taken [Zod's own documentation](https://zod.dev/codecs#stringtourl).
@@ -7,5 +7,6 @@ export declare const codec: {
7
7
  stringToBuffer: (encoding?: BufferEncoding) => import("zod").ZodCodec<import("zod").ZodString, import("zod").ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>;
8
8
  stringToInteger: () => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodString, "IntegerString">, import("zod/v4/core").$ZodBranded<import("zod").ZodInt, "Integer">>;
9
9
  stringToJson: () => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodString, "JsonString">, import("zod").ZodType<import("../zu.js").Json, unknown, import("zod/v4/core").$ZodTypeInternals<import("../zu.js").Json, unknown>>>;
10
+ stringToPositiveInteger: () => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodString, "PositiveIntegerString">, import("zod/v4/core").$ZodBranded<import("zod").ZodInt, "PositiveInteger">>;
10
11
  stringToUrl: () => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodURL, "UrlString">, import("zod").ZodCustom<import("url").URL, import("url").URL>>;
11
12
  };
@@ -7,6 +7,7 @@ const ms_js_1 = require("./ms.js");
7
7
  const string_to_buffer_js_1 = require("./string-to-buffer.js");
8
8
  const string_to_integer_js_1 = require("./string-to-integer.js");
9
9
  const string_to_json_js_1 = require("./string-to-json.js");
10
+ const string_to_positive_integer_js_1 = require("./string-to-positive-integer.js");
10
11
  const string_to_url_js_1 = require("./string-to-url.js");
11
12
  exports.codec = {
12
13
  csv: csv_js_1.csv,
@@ -15,6 +16,7 @@ exports.codec = {
15
16
  stringToBuffer: string_to_buffer_js_1.stringToBuffer,
16
17
  stringToInteger: string_to_integer_js_1.stringToInteger,
17
18
  stringToJson: string_to_json_js_1.stringToJson,
19
+ stringToPositiveInteger: string_to_positive_integer_js_1.stringToPositiveInteger,
18
20
  stringToUrl: string_to_url_js_1.stringToUrl,
19
21
  };
20
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/codec/index.ts"],"names":[],"mappings":";;;AAAA,qCAA+B;AAC/B,mDAA4C;AAC5C,mCAA6B;AAC7B,+DAAuD;AACvD,iEAAyD;AACzD,2DAAmD;AACnD,yDAAiD;AAEpC,QAAA,KAAK,GAAG;IACnB,GAAG,EAAH,YAAG;IACH,SAAS,EAAT,yBAAS;IACT,EAAE,EAAF,UAAE;IACF,cAAc,EAAd,oCAAc;IACd,eAAe,EAAf,sCAAe;IACf,YAAY,EAAZ,gCAAY;IACZ,WAAW,EAAX,8BAAW;CACZ,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/codec/index.ts"],"names":[],"mappings":";;;AAAA,qCAA+B;AAC/B,mDAA4C;AAC5C,mCAA6B;AAC7B,+DAAuD;AACvD,iEAAyD;AACzD,2DAAmD;AACnD,mFAA0E;AAC1E,yDAAiD;AAEpC,QAAA,KAAK,GAAG;IACnB,GAAG,EAAH,YAAG;IACH,SAAS,EAAT,yBAAS;IACT,EAAE,EAAF,UAAE;IACF,cAAc,EAAd,oCAAc;IACd,eAAe,EAAf,sCAAe;IACf,YAAY,EAAZ,gCAAY;IACZ,uBAAuB,EAAvB,uDAAuB;IACvB,WAAW,EAAX,8BAAW;CACZ,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * A string to positive integer codec.
4
+ *
5
+ * Almost the same as {@link zu.codec.stringToInteger} but leveraging their `positiveInteger`
6
+ * variants.
7
+ *
8
+ * @returns A string to positive integer codec.
9
+ *
10
+ * @see https://zod.dev/codecs#stringtoint
11
+ */
12
+ export declare const stringToPositiveInteger: () => z.ZodCodec<z.core.$ZodBranded<z.ZodString, "PositiveIntegerString">, z.core.$ZodBranded<z.ZodInt, "PositiveInteger">>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringToPositiveInteger = void 0;
4
+ const types_1 = require("@infra-blocks/types");
5
+ const zod_1 = require("zod");
6
+ const index_js_1 = require("../number/index.js");
7
+ const index_js_2 = require("../string/index.js");
8
+ const codec = zod_1.z.codec(index_js_2.string.positiveInteger(), index_js_1.number.positiveInteger(), {
9
+ decode: (str) => Number.parseInt(str, 10),
10
+ encode: (num) => (0, types_1.trusted)(num.toString()),
11
+ });
12
+ /**
13
+ * A string to positive integer codec.
14
+ *
15
+ * Almost the same as {@link zu.codec.stringToInteger} but leveraging their `positiveInteger`
16
+ * variants.
17
+ *
18
+ * @returns A string to positive integer codec.
19
+ *
20
+ * @see https://zod.dev/codecs#stringtoint
21
+ */
22
+ const stringToPositiveInteger = () => codec;
23
+ exports.stringToPositiveInteger = stringToPositiveInteger;
24
+ //# sourceMappingURL=string-to-positive-integer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string-to-positive-integer.js","sourceRoot":"","sources":["../../../src/codec/string-to-positive-integer.ts"],"names":[],"mappings":";;;AAAA,+CAA8C;AAC9C,6BAAwB;AAExB,iDAA4C;AAC5C,iDAA4C;AAE5C,MAAM,KAAK,GAAG,OAAC,CAAC,KAAK,CAAC,iBAAM,CAAC,eAAe,EAAE,EAAE,iBAAM,CAAC,eAAe,EAAE,EAAE;IACxE,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC;IACzC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,eAAO,EAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;CACzC,CAAC,CAAC;AAEH;;;;;;;;;GASG;AACI,MAAM,uBAAuB,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC;AAAtC,QAAA,uBAAuB,2BAAe"}
@@ -7,5 +7,6 @@ export declare const codec: {
7
7
  stringToBuffer: (encoding?: BufferEncoding) => import("zod").ZodCodec<import("zod").ZodString, import("zod").ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>;
8
8
  stringToInteger: () => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodString, "IntegerString">, import("zod/v4/core").$ZodBranded<import("zod").ZodInt, "Integer">>;
9
9
  stringToJson: () => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodString, "JsonString">, import("zod").ZodType<import("../zu.js").Json, unknown, import("zod/v4/core").$ZodTypeInternals<import("../zu.js").Json, unknown>>>;
10
+ stringToPositiveInteger: () => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodString, "PositiveIntegerString">, import("zod/v4/core").$ZodBranded<import("zod").ZodInt, "PositiveInteger">>;
10
11
  stringToUrl: () => import("zod").ZodCodec<import("zod/v4/core").$ZodBranded<import("zod").ZodURL, "UrlString">, import("zod").ZodCustom<import("url").URL, import("url").URL>>;
11
12
  };
@@ -4,6 +4,7 @@ import { ms } from "./ms.js";
4
4
  import { stringToBuffer } from "./string-to-buffer.js";
5
5
  import { stringToInteger } from "./string-to-integer.js";
6
6
  import { stringToJson } from "./string-to-json.js";
7
+ import { stringToPositiveInteger } from "./string-to-positive-integer.js";
7
8
  import { stringToUrl } from "./string-to-url.js";
8
9
  export const codec = {
9
10
  csv,
@@ -12,6 +13,7 @@ export const codec = {
12
13
  stringToBuffer,
13
14
  stringToInteger,
14
15
  stringToJson,
16
+ stringToPositiveInteger,
15
17
  stringToUrl,
16
18
  };
17
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/codec/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,GAAG;IACH,SAAS;IACT,EAAE;IACF,cAAc;IACd,eAAe;IACf,YAAY;IACZ,WAAW;CACZ,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/codec/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,GAAG;IACH,SAAS;IACT,EAAE;IACF,cAAc;IACd,eAAe;IACf,YAAY;IACZ,uBAAuB;IACvB,WAAW;CACZ,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * A string to positive integer codec.
4
+ *
5
+ * Almost the same as {@link zu.codec.stringToInteger} but leveraging their `positiveInteger`
6
+ * variants.
7
+ *
8
+ * @returns A string to positive integer codec.
9
+ *
10
+ * @see https://zod.dev/codecs#stringtoint
11
+ */
12
+ export declare const stringToPositiveInteger: () => z.ZodCodec<z.core.$ZodBranded<z.ZodString, "PositiveIntegerString">, z.core.$ZodBranded<z.ZodInt, "PositiveInteger">>;
@@ -0,0 +1,20 @@
1
+ import { trusted } from "@infra-blocks/types";
2
+ import { z } from "zod";
3
+ import { number } from "../number/index.js";
4
+ import { string } from "../string/index.js";
5
+ const codec = z.codec(string.positiveInteger(), number.positiveInteger(), {
6
+ decode: (str) => Number.parseInt(str, 10),
7
+ encode: (num) => trusted(num.toString()),
8
+ });
9
+ /**
10
+ * A string to positive integer codec.
11
+ *
12
+ * Almost the same as {@link zu.codec.stringToInteger} but leveraging their `positiveInteger`
13
+ * variants.
14
+ *
15
+ * @returns A string to positive integer codec.
16
+ *
17
+ * @see https://zod.dev/codecs#stringtoint
18
+ */
19
+ export const stringToPositiveInteger = () => codec;
20
+ //# sourceMappingURL=string-to-positive-integer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string-to-positive-integer.js","sourceRoot":"","sources":["../../../src/codec/string-to-positive-integer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,MAAM,CAAC,eAAe,EAAE,EAAE;IACxE,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC;IACzC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;CACzC,CAAC,CAAC;AAEH;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infra-blocks/zod-utils",
3
- "version": "0.29.0-alpha.0",
3
+ "version": "0.30.0-alpha.0",
4
4
  "description": "Extensions to the zod package.",
5
5
  "keywords": [
6
6
  "zod",