@guillaume-docquier/tools-ts 9.1.0 → 10.0.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 +8 -6
- package/dist/entry.schemas.d.ts +3 -0
- package/dist/entry.schemas.js +4 -0
- package/dist/entry.schemas.js.map +1 -0
- package/dist/entry.tools-ts.d.ts +0 -1
- package/dist/entry.tools-ts.js +0 -1
- package/dist/entry.tools-ts.js.map +1 -1
- package/dist/schemas/Integer.d.ts +10 -0
- package/dist/schemas/Integer.js +7 -0
- package/dist/schemas/Integer.js.map +1 -0
- package/dist/schemas/PositiveNumber.d.ts +10 -0
- package/dist/schemas/PositiveNumber.js +10 -0
- package/dist/schemas/PositiveNumber.js.map +1 -0
- package/dist/{typedParse.d.ts → schemas/typedParse.d.ts} +1 -1
- package/dist/schemas/typedParse.js.map +1 -0
- package/package.json +6 -1
- package/dist/typedParse.js.map +0 -1
- /package/dist/{typedParse.js → schemas/typedParse.js} +0 -0
package/README.md
CHANGED
|
@@ -37,12 +37,14 @@ external APIs, CLI input, local storage, or other unknown data.
|
|
|
37
37
|
|
|
38
38
|
### Zod Parsing
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
| Export
|
|
43
|
-
|
|
|
44
|
-
| typedParse
|
|
45
|
-
| safeTypedParse
|
|
40
|
+
Import these tools from `@guillaume-docquier/tools-ts/schemas`. Install Zod in the consuming project to use this optional subpath; the root entry point does not load Zod.
|
|
41
|
+
|
|
42
|
+
| Export | What it is | Use it when |
|
|
43
|
+
| ----------------------------------------- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
|
|
44
|
+
| typedParse | Parses a typed, deeply unbranded value with a Zod schema and returns its output. | Invalid data is an internal invariant violation that should throw. |
|
|
45
|
+
| safeTypedParse | The non-throwing counterpart, returning a Zod safe parse result. | Validation may fail and the caller will handle the result. |
|
|
46
|
+
| IntegerSchema and `Integer` | Parses and brands whole numbers. | A value must be an integer, including zero or a negative integer. |
|
|
47
|
+
| PositiveNumberSchema and `PositiveNumber` | Parses and brands numbers greater than zero. | A value must be positive but may be fractional. |
|
|
46
48
|
|
|
47
49
|
### Numeric Utilities
|
|
48
50
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry.schemas.js","sourceRoot":"","sources":["../src/entry.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAgB,MAAM,sBAAsB,CAAA;AAClE,OAAO,EAAE,oBAAoB,EAAuB,MAAM,6BAA6B,CAAA;AACvF,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA"}
|
package/dist/entry.tools-ts.d.ts
CHANGED
|
@@ -13,7 +13,6 @@ export { Profile } from "./Profile.js";
|
|
|
13
13
|
export { Range } from "./Range.js";
|
|
14
14
|
export { Scalar } from "./Scalar.js";
|
|
15
15
|
export { TypeGuard } from "./TypeGuard.js";
|
|
16
|
-
export { typedParse, safeTypedParse } from "./typedParse.js";
|
|
17
16
|
export { setTimeoutAsync } from "./setTimeoutAsync.js";
|
|
18
17
|
export { noop, asyncNoop } from "./noop.js";
|
|
19
18
|
export { Logger } from "./logging/Logger.js";
|
package/dist/entry.tools-ts.js
CHANGED
|
@@ -12,7 +12,6 @@ export { Profile } from "./Profile.js";
|
|
|
12
12
|
export { Range } from "./Range.js";
|
|
13
13
|
export { Scalar } from "./Scalar.js";
|
|
14
14
|
export { TypeGuard } from "./TypeGuard.js";
|
|
15
|
-
export { typedParse, safeTypedParse } from "./typedParse.js";
|
|
16
15
|
export { setTimeoutAsync } from "./setTimeoutAsync.js";
|
|
17
16
|
export { noop, asyncNoop } from "./noop.js";
|
|
18
17
|
export { Logger } from "./logging/Logger.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.tools-ts.js","sourceRoot":"","sources":["../src/entry.tools-ts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qB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EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAgB,OAAO,EAAgE,MAAM,YAAY,CAAA;AAChH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type Branded } from "../Brand.js";
|
|
3
|
+
/**
|
|
4
|
+
* A whole number, including zero and negative numbers.
|
|
5
|
+
*/
|
|
6
|
+
export type Integer = Branded<"Integer", number>;
|
|
7
|
+
/**
|
|
8
|
+
* Parses a number as an integer.
|
|
9
|
+
*/
|
|
10
|
+
export declare const IntegerSchema: z.ZodPipe<z.ZodInt, z.ZodTransform<Integer, number>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Integer.js","sourceRoot":"","sources":["../../src/schemas/Integer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,OAAO,EAAgB,MAAM,aAAa,CAAA;AAOnD;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,OAAgB,CAAC,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type Branded } from "../Brand.js";
|
|
3
|
+
/**
|
|
4
|
+
* A number greater than zero; zero is neither positive nor negative.
|
|
5
|
+
*/
|
|
6
|
+
export type PositiveNumber = Branded<"PositiveNumber", number>;
|
|
7
|
+
/**
|
|
8
|
+
* Parses a number greater than zero, including positive fractions.
|
|
9
|
+
*/
|
|
10
|
+
export declare const PositiveNumberSchema: z.ZodPipe<z.ZodNumber, z.ZodTransform<PositiveNumber, number>>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { branded } from "../Brand.js";
|
|
3
|
+
/**
|
|
4
|
+
* Parses a number greater than zero, including positive fractions.
|
|
5
|
+
*/
|
|
6
|
+
export const PositiveNumberSchema = z
|
|
7
|
+
.number()
|
|
8
|
+
.positive()
|
|
9
|
+
.transform(branded);
|
|
10
|
+
//# sourceMappingURL=PositiveNumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PositiveNumber.js","sourceRoot":"","sources":["../../src/schemas/PositiveNumber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,OAAO,EAAgB,MAAM,aAAa,CAAA;AAOnD;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC;KAClC,MAAM,EAAE;KACR,QAAQ,EAAE;KACV,SAAS,CAAC,OAAuB,CAAC,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { z } from "zod";
|
|
2
|
-
import type { DeepUnbranded } from "
|
|
2
|
+
import type { DeepUnbranded } from "../Brand.js";
|
|
3
3
|
/**
|
|
4
4
|
* We use zod schemas on unknown inputs to parse & validate the data.
|
|
5
5
|
* However, when you have already parsed data (usually because it is trusted data) and want to validate, using schema.parse is bad because the parameter is `unknown`, so you don't get feedback from TypeScript.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typedParse.js","sourceRoot":"","sources":["../../src/schemas/typedParse.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,UAAU,CAA4B,MAAe,EAAE,KAAuC;IAC5G,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAe,EACf,KAAuC;IAEvC,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;AAChC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guillaume-docquier/tools-ts",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"description": "My personal collection of typescript tools",
|
|
5
5
|
"homepage": "https://github.com/Guillaume-Docquier/tools-ts",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,6 +18,11 @@
|
|
|
18
18
|
"types": "./dist/entry.tools-ts.d.ts",
|
|
19
19
|
"import": "./dist/entry.tools-ts.js",
|
|
20
20
|
"require": "./dist/entry.tools-ts.js"
|
|
21
|
+
},
|
|
22
|
+
"./schemas": {
|
|
23
|
+
"types": "./dist/entry.schemas.d.ts",
|
|
24
|
+
"import": "./dist/entry.schemas.js",
|
|
25
|
+
"require": "./dist/entry.schemas.js"
|
|
21
26
|
}
|
|
22
27
|
},
|
|
23
28
|
"publishConfig": {
|
package/dist/typedParse.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typedParse.js","sourceRoot":"","sources":["../src/typedParse.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,UAAU,CAA4B,MAAe,EAAE,KAAuC;IAC5G,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAe,EACf,KAAuC;IAEvC,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;AAChC,CAAC"}
|
|
File without changes
|