Comparing version 0.0.4 to 0.0.5
@@ -39,22 +39,28 @@ "use strict"; | ||
case TypeName.ZodNumber: | ||
return (arg) => z | ||
.string() | ||
.regex(/^\d+(\.\d+)?$/, { | ||
message: "Value doesn't appear to be a number!", | ||
}) | ||
.transform(Number) | ||
.parse(arg); | ||
return (arg) => { | ||
if (/^\d+(\.\d+)?$/.test(arg)) | ||
return Number(arg); | ||
return arg; | ||
}; | ||
case TypeName.ZodBigInt: | ||
return (arg) => z | ||
.string() | ||
.regex(/^\d+$/, { message: "Value doesn't appear to be a bigint!" }) | ||
.transform(BigInt) | ||
.parse(arg); | ||
return (arg) => { | ||
if (/^\d+$/.test(arg)) | ||
return BigInt(arg); | ||
return arg; | ||
}; | ||
case TypeName.ZodBoolean: | ||
return (arg) => z | ||
.union([ | ||
z.enum(["true", "yes", "1"]).transform(() => true), | ||
z.enum(["false", "no", "0"]).transform(() => false), | ||
]) | ||
.parse(arg); | ||
return (arg) => { | ||
switch (arg) { | ||
case "true": | ||
case "yes": | ||
case "1": | ||
return true; | ||
case "false": | ||
case "no": | ||
case "0": | ||
return false; | ||
default: | ||
return arg; | ||
} | ||
}; | ||
case TypeName.ZodArray: | ||
@@ -64,2 +70,3 @@ case TypeName.ZodObject: | ||
case TypeName.ZodRecord: | ||
case TypeName.ZodIntersection: | ||
return (arg) => { | ||
@@ -69,2 +76,5 @@ // neither `undefined` nor the empty string are valid json. | ||
return arg; | ||
// the one circumstance when a preprocessor should be able to throw is | ||
// if the json is invalid -- this way the error message will be more | ||
// informative (rather than just "expected x, got string") | ||
return JSON.parse(arg); | ||
@@ -129,3 +139,2 @@ }; | ||
case TypeName.ZodUnion: | ||
case TypeName.ZodIntersection: | ||
case TypeName.ZodNativeEnum: | ||
@@ -132,0 +141,0 @@ throw new Error(`Zod type not yet supported: "${typeName}" (PRs welcome)`); |
{ | ||
"name": "znv", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Parse your environment with Zod schemas", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28791
421