Skip to content

Commit 9df0c1b

Browse files
Merge pull request #161 from zereight/feat/153-1
FEAT: id is string or number
2 parents 2485f34 + 1131897 commit 9df0c1b

File tree

2 files changed

+55
-109
lines changed

2 files changed

+55
-109
lines changed

customSchemas.ts

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,57 +19,3 @@ export const flexibleBoolean = z.preprocess((val) => {
1919
}
2020
return val;
2121
}, z.boolean());
22-
23-
24-
export const numericStringSchemaNullable = z.coerce.string().or(z.number()).transform((val, ctx) => {
25-
const strValue = String(val);
26-
const trimmedStrValue = strValue.trim();
27-
28-
if (trimmedStrValue === '') {
29-
ctx.addIssue({
30-
code: z.ZodIssueCode.custom,
31-
message: `Expected a numeric string or number, but received an empty string or string with only whitespace.`,
32-
});
33-
return z.NEVER;
34-
}
35-
if (trimmedStrValue.toLowerCase() === 'null') {
36-
return null;
37-
}
38-
if (isNaN(Number(trimmedStrValue))) {
39-
ctx.addIssue({
40-
code: z.ZodIssueCode.custom,
41-
message: `Expected a numeric string or number, but received ${trimmedStrValue}`,
42-
});
43-
return z.NEVER;
44-
}
45-
return String(trimmedStrValue);
46-
}).nullable();
47-
48-
49-
export const numericStringSchema = z.coerce.string().transform((val, ctx) => {
50-
const strValue = String(val);
51-
const trimmedStrValue = strValue.trim();
52-
53-
if (trimmedStrValue === '') {
54-
ctx.addIssue({
55-
code: z.ZodIssueCode.custom,
56-
message: `Expected a numeric string or number, but received an empty string or string with only whitespace.`,
57-
});
58-
return z.NEVER;
59-
}
60-
if (trimmedStrValue.toLowerCase() === 'null') {
61-
ctx.addIssue({
62-
code: z.ZodIssueCode.custom,
63-
message: `Expected a numeric string or number, but received an null as string`,
64-
});
65-
return z.NEVER;
66-
}
67-
if (isNaN(Number(trimmedStrValue))) {
68-
ctx.addIssue({
69-
code: z.ZodIssueCode.custom,
70-
message: `Expected a numeric string or number, but received ${trimmedStrValue}`,
71-
});
72-
return z.NEVER;
73-
}
74-
return String(trimmedStrValue);
75-
});

0 commit comments

Comments
 (0)