zod
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -6,2 +6,3 @@ export declare class Mocker { | ||
readonly boolean: boolean; | ||
readonly date: Date; | ||
readonly null: null; | ||
@@ -8,0 +9,0 @@ readonly undefined: undefined; |
@@ -39,2 +39,9 @@ "use strict"; | ||
}); | ||
Object.defineProperty(Mocker.prototype, "date", { | ||
get: function () { | ||
return new Date(Math.floor(Date.now() * Math.random())); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Mocker.prototype, "null", { | ||
@@ -41,0 +48,0 @@ get: function () { |
import { ZodString, ZodStringDef } from './types/string'; | ||
import { ZodNumber, ZodNumberDef } from './types/number'; | ||
import { ZodBoolean, ZodBooleanDef } from './types/boolean'; | ||
import { ZodDate, ZodDateDef } from './types/date'; | ||
import { ZodUndefined, ZodUndefinedDef } from './types/undefined'; | ||
@@ -18,6 +19,7 @@ import { ZodNull, ZodNullDef } from './types/null'; | ||
import { ZodError } from './ZodError'; | ||
declare type ZodDef = ZodStringDef | ZodNumberDef | ZodBooleanDef | ZodUndefinedDef | ZodNullDef | ZodArrayDef | ZodObjectDef | ZodUnionDef | ZodIntersectionDef | ZodTupleDef | ZodRecordDef | ZodLazyDef | ZodLiteralDef | ZodEnumDef; | ||
declare type ZodDef = ZodStringDef | ZodNumberDef | ZodBooleanDef | ZodDateDef | ZodUndefinedDef | ZodNullDef | ZodArrayDef | ZodObjectDef | ZodUnionDef | ZodIntersectionDef | ZodTupleDef | ZodRecordDef | ZodLazyDef | ZodLiteralDef | ZodEnumDef; | ||
declare const stringType: () => ZodString; | ||
declare const numberType: () => ZodNumber; | ||
declare const booleanType: () => ZodBoolean; | ||
declare const dateType: () => ZodDate; | ||
declare const undefinedType: () => ZodUndefined; | ||
@@ -40,4 +42,4 @@ declare const nullType: () => ZodNull; | ||
declare const oboolean: () => ZodUnion<[ZodBoolean, ZodUndefined]>; | ||
export { stringType as string, numberType as number, booleanType as boolean, undefinedType as undefined, nullType as null, arrayType as array, objectType as object, unionType as union, intersectionType as intersection, tupleType as tuple, recordType as record, functionType as function, lazyType as lazy, literalType as literal, enumType as enum, ostring, onumber, oboolean, }; | ||
export { ZodString, ZodNumber, ZodBoolean, ZodUndefined, ZodNull, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodRecord, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodType, ZodAny, ZodDef, ZodError, }; | ||
export { stringType as string, numberType as number, booleanType as boolean, dateType as date, undefinedType as undefined, nullType as null, arrayType as array, objectType as object, unionType as union, intersectionType as intersection, tupleType as tuple, recordType as record, functionType as function, lazyType as lazy, literalType as literal, enumType as enum, ostring, onumber, oboolean, }; | ||
export { ZodString, ZodNumber, ZodBoolean, ZodDate, ZodUndefined, ZodNull, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodRecord, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodType, ZodAny, ZodDef, ZodError, }; | ||
export { TypeOf, TypeOf as infer }; |
@@ -10,2 +10,4 @@ "use strict"; | ||
exports.ZodBoolean = boolean_1.ZodBoolean; | ||
var date_1 = require("./types/date"); | ||
exports.ZodDate = date_1.ZodDate; | ||
var undefined_1 = require("./types/undefined"); | ||
@@ -45,2 +47,4 @@ exports.ZodUndefined = undefined_1.ZodUndefined; | ||
exports.boolean = booleanType; | ||
var dateType = date_1.ZodDate.create; | ||
exports.date = dateType; | ||
var undefinedType = undefined_1.ZodUndefined.create; | ||
@@ -47,0 +51,0 @@ exports.undefined = undefinedType; |
@@ -203,2 +203,12 @@ "use strict"; | ||
return parsedRecord; | ||
case z.ZodTypes.date: | ||
if (obj instanceof Date) { | ||
if (!isNaN(obj.getTime())) { | ||
return obj; | ||
} | ||
else { | ||
throw ZodError_1.ZodError.fromString("Invalid date."); | ||
} | ||
} | ||
throw ZodError_1.ZodError.fromString("Non-Date type: " + obj.type); | ||
default: | ||
@@ -205,0 +215,0 @@ // function |
@@ -6,2 +6,3 @@ import { ParseParams } from '../parser'; | ||
boolean = "boolean", | ||
date = "date", | ||
undefined = "undefined", | ||
@@ -8,0 +9,0 @@ null = "null", |
@@ -10,2 +10,3 @@ "use strict"; | ||
ZodTypes["boolean"] = "boolean"; | ||
ZodTypes["date"] = "date"; | ||
ZodTypes["undefined"] = "undefined"; | ||
@@ -12,0 +13,0 @@ ZodTypes["null"] = "null"; |
{ | ||
"name": "zod", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "TypeScript-first schema declaration and validation library with static type inference", | ||
@@ -5,0 +5,0 @@ "main": "./lib/src/index.js", |
@@ -48,4 +48,4 @@ <p align="center"> | ||
- [Errors](#errors) | ||
- [Changelog](#changelog) | ||
- [Comparison](#comparison) | ||
- [Joi](#joi) | ||
@@ -95,2 +95,3 @@ - [Yup](#yup) | ||
const booleanSchema = z.boolean(); // => ZodType<boolean> | ||
const dateSchema = z.Date(); // => ZodType<Date> | ||
const undefinedSchema = z.undefined(); // => ZodType<undefined> | ||
@@ -108,2 +109,4 @@ const nullTypeSchema = z.null(); // => ZodType<null> | ||
Currently there is no support for Date literals in Zod. If you have a use case for this feature, please file an issue. | ||
## Parsing and validation | ||
@@ -151,3 +154,3 @@ | ||
You can extract the TypeScript type of any schema with `z.infer<>`. | ||
You can extract the TypeScript type of any schema with `z.infer<typeof [schema]>`. | ||
@@ -998,1 +1001,14 @@ ```ts | ||
[https://github.com/pelotom/runtypes](https://github.com/pelotom/runtypes) | ||
# Changelog | ||
| zod version | release notes | | ||
| ----------- | ---------------------------------------------------------- | | ||
| zod@1.0.0 | Initial release | | ||
| zod@1.0.0 | Type assertions, literals, enums, detailed error reporting | | ||
| zod@1.0.4 | Empty tuples | | ||
| zod@1.0.10 | Type assertions with `.check` | | ||
| zod@1.0.11 | `.nonstrict` | | ||
| zod@1.1.0 | Records | | ||
| zod@1.2.0 | `.pick`, `.omit`, and `.augment` on object schemas | | ||
| zod@1.2.2 | Date schemas | |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
163704
97
2316
1010