@nemigo/helpers 0.0.19 → 0.1.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/dist/datetime.js +1 -0
- package/dist/xod.d.ts +24 -0
- package/dist/xod.js +61 -0
- package/package.json +5 -1
package/dist/datetime.js
CHANGED
package/dist/xod.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const invalid: (value: unknown, ctx: z.core.$RefinementCtx, { message, expected }: {
|
|
3
|
+
message: string;
|
|
4
|
+
expected: string;
|
|
5
|
+
}) => never;
|
|
6
|
+
export declare const nullSchema: z.ZodPipe<z.ZodOptional<z.ZodNull>, z.ZodTransform<undefined, null | undefined>>;
|
|
7
|
+
export declare const booleanSchema: z.ZodPipe<z.ZodBoolean, z.ZodTransform<boolean, boolean>>;
|
|
8
|
+
export declare const booleanSchemaOptional: z.ZodUnion<readonly [z.ZodPipe<z.ZodOptional<z.ZodNull>, z.ZodTransform<undefined, null | undefined>>, z.ZodPipe<z.ZodBoolean, z.ZodTransform<boolean, boolean>>]>;
|
|
9
|
+
export declare const numberSchema: z.ZodPipe<z.ZodUnion<[z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>;
|
|
10
|
+
export declare const numberSchemaOptional: z.ZodUnion<readonly [z.ZodPipe<z.ZodOptional<z.ZodNull>, z.ZodTransform<undefined, null | undefined>>, z.ZodPipe<z.ZodUnion<[z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>]>;
|
|
11
|
+
export declare const stringSchema: z.ZodUnion<[z.ZodString, z.ZodPipe<z.ZodNumber, z.ZodTransform<string, number>>]>;
|
|
12
|
+
export declare const stringSchemaOptional: z.ZodUnion<readonly [z.ZodPipe<z.ZodOptional<z.ZodNull>, z.ZodTransform<undefined, null | undefined>>, z.ZodUnion<[z.ZodString, z.ZodPipe<z.ZodNumber, z.ZodTransform<string, number>>]>]>;
|
|
13
|
+
declare const _default: {
|
|
14
|
+
invalid: (value: unknown, ctx: z.core.$RefinementCtx, { message, expected }: {
|
|
15
|
+
message: string;
|
|
16
|
+
expected: string;
|
|
17
|
+
}) => never;
|
|
18
|
+
nullSchema: z.ZodPipe<z.ZodOptional<z.ZodNull>, z.ZodTransform<undefined, null | undefined>>;
|
|
19
|
+
booleanSchema: z.ZodPipe<z.ZodBoolean, z.ZodTransform<boolean, boolean>>;
|
|
20
|
+
booleanSchemaOptional: z.ZodUnion<readonly [z.ZodPipe<z.ZodOptional<z.ZodNull>, z.ZodTransform<undefined, null | undefined>>, z.ZodPipe<z.ZodBoolean, z.ZodTransform<boolean, boolean>>]>;
|
|
21
|
+
numberSchema: z.ZodPipe<z.ZodUnion<[z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>;
|
|
22
|
+
numberSchemaOptional: z.ZodUnion<readonly [z.ZodPipe<z.ZodOptional<z.ZodNull>, z.ZodTransform<undefined, null | undefined>>, z.ZodPipe<z.ZodUnion<[z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>]>;
|
|
23
|
+
};
|
|
24
|
+
export default _default;
|
package/dist/xod.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { caseBoolean, caseNumber, caseString } from "./cases.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export const invalid = (value, ctx, { message, expected }) => {
|
|
4
|
+
ctx.addIssue({
|
|
5
|
+
code: "invalid_type",
|
|
6
|
+
message,
|
|
7
|
+
input: value,
|
|
8
|
+
expected: expected,
|
|
9
|
+
});
|
|
10
|
+
return z.NEVER;
|
|
11
|
+
};
|
|
12
|
+
export const nullSchema = z.union([
|
|
13
|
+
z
|
|
14
|
+
.null()
|
|
15
|
+
.optional()
|
|
16
|
+
.transform(() => undefined),
|
|
17
|
+
z.string().transform((value, ctx) => {
|
|
18
|
+
if (!value)
|
|
19
|
+
return undefined;
|
|
20
|
+
const flat = value.trim().toLowerCase();
|
|
21
|
+
if (flat === "undefined" || flat === "null")
|
|
22
|
+
return undefined;
|
|
23
|
+
return invalid(value, ctx, {
|
|
24
|
+
message: "It isn't a null / undefined",
|
|
25
|
+
expected: "null / undefined (or string like null / undefined)",
|
|
26
|
+
});
|
|
27
|
+
}),
|
|
28
|
+
]);
|
|
29
|
+
//...
|
|
30
|
+
export const booleanSchema = z.unknown().transform((value, ctx) => caseBoolean(value, (result) => result === null
|
|
31
|
+
? invalid(value, ctx, {
|
|
32
|
+
message: "It isn't a boolean",
|
|
33
|
+
expected: "boolean (or string / number like boolean)",
|
|
34
|
+
})
|
|
35
|
+
: result));
|
|
36
|
+
export const booleanSchemaOptional = z.union([nullSchema, booleanSchema]);
|
|
37
|
+
//...
|
|
38
|
+
export const numberSchema = z.unknown().transform((value, ctx) => caseNumber(value, (result) => result === null
|
|
39
|
+
? invalid(value, ctx, {
|
|
40
|
+
message: "It isn't a number",
|
|
41
|
+
expected: "number (or string like number)",
|
|
42
|
+
})
|
|
43
|
+
: result));
|
|
44
|
+
export const numberSchemaOptional = z.union([nullSchema, numberSchema]);
|
|
45
|
+
//...
|
|
46
|
+
export const stringSchema = z.unknown().transform((value, ctx) => caseString(value, (result) => result === null || result === ""
|
|
47
|
+
? invalid(value, ctx, {
|
|
48
|
+
message: "It isn't a string or empty string",
|
|
49
|
+
expected: "string (or number)",
|
|
50
|
+
})
|
|
51
|
+
: result));
|
|
52
|
+
export const stringSchemaOptional = z.union([nullSchema, stringSchema]);
|
|
53
|
+
//...
|
|
54
|
+
export default {
|
|
55
|
+
invalid,
|
|
56
|
+
nullSchema,
|
|
57
|
+
booleanSchema,
|
|
58
|
+
booleanSchemaOptional,
|
|
59
|
+
numberSchema,
|
|
60
|
+
numberSchemaOptional,
|
|
61
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nemigo/helpers",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Vlad Logvin",
|
|
@@ -90,6 +90,10 @@
|
|
|
90
90
|
"./url": {
|
|
91
91
|
"types": "./dist/url.d.ts",
|
|
92
92
|
"default": "./dist/url.js"
|
|
93
|
+
},
|
|
94
|
+
"./xod": {
|
|
95
|
+
"types": "./dist/xod.d.ts",
|
|
96
|
+
"default": "./dist/xod.js"
|
|
93
97
|
}
|
|
94
98
|
},
|
|
95
99
|
"peerDependencies": {
|