Socket
Socket
Sign inDemoInstall

zod

Package Overview
Dependencies
Maintainers
1
Versions
361
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zod - npm Package Compare versions

Comparing version 1.9.0 to 1.10.0-alpha.1

lib/src/types/codec.d.ts

3

lib/src/codegen.js

@@ -133,2 +133,5 @@ "use strict";

return _this.setType(id, _this.generate(lazyType).id);
case z.ZodTypes.codec:
var codecOutput = def.output;
return _this.setType(id, _this.generate(codecOutput).id);
default:

@@ -135,0 +138,0 @@ util_1.util.assertNever(def);

8

lib/src/index.d.ts

@@ -22,2 +22,3 @@ import { ZodString, ZodStringDef } from './types/string';

import { ZodPromise, ZodPromiseDef } from './types/promise';
import { ZodCodec, ZodCodecDef } from './types/codec';
import { TypeOf, ZodType, ZodTypeAny, ZodTypeDef, ZodTypes } from './types/base';

@@ -29,3 +30,3 @@ import { ZodError, ZodErrorCode } from './ZodError';

export { ZodTypeDef, ZodTypes };
declare type ZodDef = ZodStringDef | ZodNumberDef | ZodBigIntDef | ZodBooleanDef | ZodDateDef | ZodUndefinedDef | ZodNullDef | ZodAnyDef | ZodUnknownDef | ZodVoidDef | ZodArrayDef | ZodObjectDef | ZodUnionDef | ZodIntersectionDef | ZodTupleDef | ZodRecordDef | ZodFunctionDef | ZodLazyDef | ZodLiteralDef | ZodEnumDef | ZodPromiseDef;
declare type ZodDef = ZodStringDef | ZodNumberDef | ZodBigIntDef | ZodBooleanDef | ZodDateDef | ZodUndefinedDef | ZodNullDef | ZodAnyDef | ZodUnknownDef | ZodVoidDef | ZodArrayDef | ZodObjectDef | ZodUnionDef | ZodIntersectionDef | ZodTupleDef | ZodRecordDef | ZodFunctionDef | ZodLazyDef | ZodLiteralDef | ZodEnumDef | ZodPromiseDef | ZodCodecDef;
declare const stringType: () => ZodString;

@@ -54,2 +55,3 @@ declare const numberType: () => ZodNumber;

declare const promiseType: <T extends ZodType<any, ZodTypeDef>>(schema: T) => ZodPromise<T>;
declare const codecType: <T extends ZodType<any, ZodTypeDef>, U extends ZodType<any, ZodTypeDef>>(input: T, output: U, transformer: (arg: T["_type"]) => U["_type"]) => ZodCodec<T, U>;
declare const ostring: () => ZodUnion<[ZodString, ZodUndefined]>;

@@ -63,3 +65,3 @@ declare const onumber: () => ZodUnion<[ZodNumber, ZodUndefined]>;

} & Pick<import("./ZodError").CustomError, "message" | "params">, "message" | "path" | "params"> | undefined) => ZodType<InstanceType<T>, ZodTypeDef>;
export { stringType as string, numberType as number, bigIntType as bigint, booleanType as boolean, dateType as date, undefinedType as undefined, nullType as null, anyType as any, unknownType as unknown, voidType as void, 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, promiseType as promise, instanceOfType as instanceof, ostring, onumber, oboolean, codegen, };
export { stringType as string, numberType as number, bigIntType as bigint, booleanType as boolean, dateType as date, undefinedType as undefined, nullType as null, anyType as any, unknownType as unknown, voidType as void, 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, promiseType as promise, codecType as codec, instanceOfType as instanceof, ostring, onumber, oboolean, codegen, };
export declare const late: {

@@ -70,3 +72,3 @@ object: <T extends import("./types/base").ZodRawShape>(shape: () => T) => ZodObject<T, {

};
export { ZodString, ZodNumber, ZodBigInt, ZodBoolean, ZodDate, ZodUndefined, ZodNull, ZodAny, ZodUnknown, ZodVoid, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodRecord, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodPromise, ZodType, ZodType as Schema, ZodType as ZodSchema, ZodTypeAny, ZodDef, ZodError, ZodErrorMap, ZodErrorCode, ZodParsedType, ZodCodeGenerator, };
export { ZodString, ZodNumber, ZodBigInt, ZodBoolean, ZodDate, ZodUndefined, ZodNull, ZodAny, ZodUnknown, ZodVoid, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodRecord, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodPromise, ZodCodec, ZodType, ZodType as Schema, ZodType as ZodSchema, ZodTypeAny, ZodDef, ZodError, ZodErrorMap, ZodErrorCode, ZodParsedType, ZodCodeGenerator, };
export { TypeOf, TypeOf as infer };

@@ -46,2 +46,4 @@ "use strict";

exports.ZodPromise = promise_1.ZodPromise;
var codec_1 = require("./types/codec");
exports.ZodCodec = codec_1.ZodCodec;
var base_1 = require("./types/base");

@@ -101,2 +103,4 @@ exports.ZodType = base_1.ZodType;

exports.promise = promiseType;
var codecType = codec_1.ZodCodec.create;
exports.codec = codecType;
var ostring = function () { return stringType().optional(); };

@@ -103,0 +107,0 @@ exports.ostring = ostring;

@@ -435,2 +435,6 @@ "use strict";

}); });
case z.ZodTypes.codec:
def.input.parse(obj);
var transformed = def.transformer(obj);
return def.output.parse(transformed);
default:

@@ -437,0 +441,0 @@ util_1.util.assertNever(def);

"use strict";
// import * as z from '.';
// z.date().parse(new Date('invalid'));
// import { ZodCodec } from './types/codec';
// const test = ZodCodec.create(z.string(), z.string(), x => x.trim().toUpperCase());
// const adsf = test.parse(' asdf12345 asdf asdfas ');
// console.log(adsf);
// const FormData = z
// .object({
// email: z.string().email(),
// password: z.string().min(10),
// confirm: z.string().min(10),
// })
// .refine(obj => obj.password === obj.confirm, {
// message: 'Passwords do not match',
// path: ['confirm'], // sets the path of the error thrown by this refinement
// });
// try {
// FormData.parse({
// email: 'not an email',
// password: 'tooshort',
// confirm: 'nomatch',
// });
// } catch (err) {
// if (!(err instanceof z.ZodError)) throw err;
// console.log(err.errors);
// /*
// [
// { code: 'invalid_string', validation: 'email', path: ['email'], message: 'Invalid email' },
// {
// code: 'too_small',
// minimum: 10,
// type: 'string',
// inclusive: true,
// path: ['password'],
// message: 'Should be at least 10 characters',
// },
// {
// code: 'too_small',
// minimum: 10,
// type: 'string',
// inclusive: true,
// path: ['confirm'],
// message: 'Should be at least 10 characters',
// },
// { code: 'custom_error', message: 'Passwords do not match', path: ['confirm'] },
// ];
// */
// console.log(err.formErrors);
// /*
// {
// formErrors: [],
// fieldErrors: {
// email: ['Invalid email'],
// password: ['Should be at least 10 characters'],
// confirm: ['Should be at least 10 characters', 'Passwords do not match'],
// },
// }
// */
// }
//
//# sourceMappingURL=playground.js.map
import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
import { ZodUnion } from './union';
export interface ZodAnyDef extends z.ZodTypeDef {

@@ -9,6 +6,4 @@ t: z.ZodTypes.any;

export declare class ZodAny extends z.ZodType<any, ZodAnyDef> {
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
toJSON: () => ZodAnyDef;
static create: () => ZodAny;
}

@@ -24,5 +24,2 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
var ZodAny = /** @class */ (function (_super) {

@@ -32,4 +29,4 @@ __extends(ZodAny, _super);

var _this = _super !== null && _super.apply(this, arguments) || this;
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.toJSON = function () { return _this._def; };

@@ -36,0 +33,0 @@ return _this;

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
import { ZodUnion } from './union';
export interface ZodArrayDef<T extends z.ZodTypeAny = z.ZodTypeAny> extends z.ZodTypeDef {

@@ -17,4 +14,2 @@ t: z.ZodTypes.array;

readonly element: T;
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
min: (minLength: number, message?: string | {

@@ -35,4 +30,2 @@ message?: string | undefined;

};
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
min: (minLength: number, message?: string | {

@@ -39,0 +32,0 @@ message?: string | undefined;

@@ -35,5 +35,5 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
// import { ZodUndefined } from './undefined';
// import { ZodNull } from './null';
// import { ZodUnion } from './union';
var __1 = require("..");

@@ -51,4 +51,4 @@ var ZodArray = /** @class */ (function (_super) {

};
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.min = function (minLength, message) {

@@ -93,4 +93,4 @@ return _this._refinement(__assign({ check: function (data) { return data.length >= minLength; }, code: __1.ZodErrorCode.too_small, type: 'array', inclusive: true, minimum: minLength }, (typeof message === 'string' ? { message: message } : message)));

};
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.min = function (minLength, message) {

@@ -97,0 +97,0 @@ return _this._refinement(__assign({ check: function (data) { return data.length >= minLength; }, code: __1.ZodErrorCode.too_small, minimum: minLength, type: 'array', inclusive: true }, (typeof message === 'string' ? { message: message } : message)));

import { ParseParams, MakeErrorData } from '../parser';
import { util } from '../helpers/util';
import { ZodArray } from '..';
import { ZodArray, ZodUnion, ZodNull, ZodUndefined } from '..';
import { CustomError } from '../ZodError';

@@ -26,3 +26,4 @@ export declare enum ZodTypes {

unknown = "unknown",
void = "void"
void = "void",
codec = "codec"
}

@@ -43,2 +44,3 @@ export declare type ZodTypeAny = ZodType<any>;

checks?: InternalCheck<any>[];
accepts?: ZodType<any, any>;
}

@@ -63,6 +65,6 @@ export declare type TypeOf<T extends {

abstract toJSON: () => object;
abstract optional: () => any;
abstract nullable: () => any;
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
array: () => ZodArray<this>;
}
export {};

@@ -39,2 +39,3 @@ "use strict";

ZodTypes["void"] = "void";
ZodTypes["codec"] = "codec";
})(ZodTypes = exports.ZodTypes || (exports.ZodTypes = {}));

@@ -68,2 +69,5 @@ var ZodType = /** @class */ (function () {

};
// abstract // opt optional: () => any;
this.optional = function () { return __1.ZodUnion.create([_this, __1.ZodUndefined.create()]); };
this.nullable = function () { return __1.ZodUnion.create([_this, __1.ZodNull.create()]); };
this.array = function () { return __1.ZodArray.create(_this); };

@@ -70,0 +74,0 @@ this.parse = parser_1.ZodParser(def);

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
import { ZodUnion } from './union';
export interface ZodBigIntDef extends z.ZodTypeDef {

@@ -9,6 +6,4 @@ t: z.ZodTypes.bigint;

export declare class ZodBigInt extends z.ZodType<bigint, ZodBigIntDef> {
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
toJSON: () => ZodBigIntDef;
static create: () => ZodBigInt;
}

@@ -24,11 +24,8 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
var ZodBigInt = /** @class */ (function (_super) {
__extends(ZodBigInt, _super);
function ZodBigInt() {
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.toJSON = function () { return _this._def; };

@@ -35,0 +32,0 @@ return _this;

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
import { ZodUnion } from './union';
export interface ZodBooleanDef extends z.ZodTypeDef {

@@ -9,6 +6,4 @@ t: z.ZodTypes.boolean;

export declare class ZodBoolean extends z.ZodType<boolean, ZodBooleanDef> {
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
toJSON: () => ZodBooleanDef;
static create: () => ZodBoolean;
}

@@ -24,11 +24,8 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
var ZodBoolean = /** @class */ (function (_super) {
__extends(ZodBoolean, _super);
function ZodBoolean() {
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.toJSON = function () { return _this._def; };

@@ -35,0 +32,0 @@ return _this;

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
import { ZodUnion } from './union';
export interface ZodDateDef extends z.ZodTypeDef {

@@ -9,6 +6,4 @@ t: z.ZodTypes.date;

export declare class ZodDate extends z.ZodType<Date, ZodDateDef> {
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
toJSON: () => ZodDateDef;
static create: () => ZodDate;
}

@@ -24,11 +24,8 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
var ZodDate = /** @class */ (function (_super) {
__extends(ZodDate, _super);
function ZodDate() {
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.toJSON = function () { return _this._def; };

@@ -35,0 +32,0 @@ return _this;

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
import { ZodUnion } from './union';
export declare type ArrayKeys = keyof any[];

@@ -16,4 +13,2 @@ export declare type Indices<T> = Exclude<keyof T, ArrayKeys>;

export declare class ZodEnum<T extends [string, ...string[]]> extends z.ZodType<T[number], ZodEnumDef<T>> {
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
toJSON: () => ZodEnumDef<T>;

@@ -20,0 +15,0 @@ readonly options: T;

@@ -24,11 +24,8 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
var ZodEnum = /** @class */ (function (_super) {
__extends(ZodEnum, _super);
function ZodEnum() {
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.toJSON = function () { return _this._def; };

@@ -35,0 +32,0 @@ return _this;

import * as z from './base';
import { ZodTuple } from './tuple';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
import { ZodUnion } from './union';
import { ZodVoid } from './void';

@@ -21,4 +18,2 @@ export interface ZodFunctionDef<Args extends ZodTuple<any> = ZodTuple<any>, Returns extends z.ZodTypeAny = z.ZodTypeAny> extends z.ZodTypeDef {

static create: <T extends ZodTuple<any> = ZodTuple<[]>, U extends z.ZodType<any, z.ZodTypeDef> = ZodVoid>(args?: T | undefined, returns?: U | undefined) => ZodFunction<T, U>;
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
toJSON: () => {

@@ -25,0 +20,0 @@ t: z.ZodTypes.function;

@@ -36,5 +36,5 @@ "use strict";

var tuple_1 = require("./tuple");
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
// import { ZodUndefined } from './undefined';
// import { ZodNull } from './null';
// import { ZodUnion } from './union';
var void_1 = require("./void");

@@ -60,4 +60,4 @@ var ZodFunction = /** @class */ (function (_super) {

_this.validate = _this.implement;
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.toJSON = function () {

@@ -64,0 +64,0 @@ return {

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
import { ZodUnion } from './union';
export interface ZodIntersectionDef<T extends z.ZodTypeAny = z.ZodTypeAny, U extends z.ZodTypeAny = z.ZodTypeAny> extends z.ZodTypeDef {

@@ -11,4 +8,2 @@ t: z.ZodTypes.intersection;

export declare class ZodIntersection<T extends z.ZodTypeAny, U extends z.ZodTypeAny> extends z.ZodType<T['_type'] & U['_type'], ZodIntersectionDef<T, U>> {
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
toJSON: () => {

@@ -15,0 +10,0 @@ t: z.ZodTypes.intersection;

@@ -24,11 +24,8 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
var ZodIntersection = /** @class */ (function (_super) {
__extends(ZodIntersection, _super);
function ZodIntersection() {
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.toJSON = function () { return ({

@@ -35,0 +32,0 @@ t: _this._def.t,

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
import { ZodUnion } from './union';
export interface ZodLazyDef<T extends z.ZodTypeAny = z.ZodTypeAny> extends z.ZodTypeDef {

@@ -11,6 +8,4 @@ t: z.ZodTypes.lazy;

readonly schema: T;
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
toJSON: () => never;
static create: <T_1 extends z.ZodType<any, z.ZodTypeDef>>(getter: () => T_1) => ZodLazy<T_1>;
}

@@ -24,5 +24,2 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
var ZodLazy = /** @class */ (function (_super) {

@@ -32,4 +29,4 @@ __extends(ZodLazy, _super);

var _this = _super !== null && _super.apply(this, arguments) || this;
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.toJSON = function () {

@@ -36,0 +33,0 @@ throw new Error("Can't JSONify recursive structure");

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
import { ZodUnion } from './union';
import { Primitive } from '../helpers/primitive';

@@ -11,6 +8,4 @@ export interface ZodLiteralDef<T extends any = any> extends z.ZodTypeDef {

export declare class ZodLiteral<T extends any> extends z.ZodType<T, ZodLiteralDef<T>> {
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
toJSON: () => ZodLiteralDef<T>;
static create: <T_1 extends Primitive>(value: T_1) => ZodLiteral<T_1>;
}

@@ -24,11 +24,8 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
var ZodLiteral = /** @class */ (function (_super) {
__extends(ZodLiteral, _super);
function ZodLiteral() {
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.toJSON = function () { return _this._def; };

@@ -35,0 +32,0 @@ return _this;

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodUnion } from './union';
export interface ZodNullDef extends z.ZodTypeDef {

@@ -8,6 +6,4 @@ t: z.ZodTypes.null;

export declare class ZodNull extends z.ZodType<null, ZodNullDef> {
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
toJSON: () => ZodNullDef;
static create: () => ZodNull;
}

@@ -24,10 +24,8 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var union_1 = require("./union");
var ZodNull = /** @class */ (function (_super) {
__extends(ZodNull, _super);
function ZodNull() {
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, ZodNull.create()]); };
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.toJSON = function () { return _this._def; };

@@ -34,0 +32,0 @@ return _this;

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
import { ZodUnion } from './union';
export interface ZodNumberDef extends z.ZodTypeDef {

@@ -9,4 +6,2 @@ t: z.ZodTypes.number;

export declare class ZodNumber extends z.ZodType<number, ZodNumberDef> {
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
toJSON: () => ZodNumberDef;

@@ -13,0 +8,0 @@ static create: () => ZodNumber;

@@ -35,5 +35,5 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
// import { ZodUndefined } from './undefined';
// import { ZodNull } from './null';
// import { ZodUnion } from './union';
var __1 = require("..");

@@ -44,5 +44,5 @@ var errorUtil_1 = require("../helpers/errorUtil");

function ZodNumber() {
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.toJSON = function () { return _this._def; };

@@ -49,0 +49,0 @@ _this.min = function (minimum, message) {

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
import { ZodUnion } from './union';

@@ -36,4 +35,2 @@ import { objectUtil } from '../helpers/objectUtil';

}>;
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
augment: <Augmentation extends z.ZodRawShape>(augmentation: Augmentation) => ZodObject<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k in keyof Augmentation]: Augmentation[k]; }, Params, ZodObjectType<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k in keyof Augmentation]: Augmentation[k]; }, Params>>;

@@ -40,0 +37,0 @@ extend: <Augmentation extends z.ZodRawShape>(augmentation: Augmentation) => ZodObject<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k in keyof Augmentation]: Augmentation[k]; }, Params, ZodObjectType<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k in keyof Augmentation]: Augmentation[k]; }, Params>>;

@@ -35,5 +35,2 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
var objectUtil_1 = require("../helpers/objectUtil");

@@ -64,4 +61,4 @@ var AugmentFactory = function (def) { return function (augmentation) {

};
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
// nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.augment = AugmentFactory(_this._def);

@@ -68,0 +65,0 @@ _this.extend = AugmentFactory(_this._def);

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
import { ZodUnion } from './union';
export interface ZodPromiseDef<T extends z.ZodTypeAny = z.ZodTypeAny> extends z.ZodTypeDef {

@@ -14,5 +11,3 @@ t: z.ZodTypes.promise;

};
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
static create: <T_1 extends z.ZodType<any, z.ZodTypeDef>>(schema: T_1) => ZodPromise<T_1>;
}

@@ -24,5 +24,2 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
var ZodPromise = /** @class */ (function (_super) {

@@ -38,6 +35,6 @@ __extends(ZodPromise, _super);

};
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
return _this;
}
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
ZodPromise.create = function (schema) {

@@ -44,0 +41,0 @@ return new ZodPromise({

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
import { ZodUnion } from './union';
export interface ZodRecordDef<Value extends z.ZodTypeAny = z.ZodTypeAny> extends z.ZodTypeDef {

@@ -16,5 +13,3 @@ t: z.ZodTypes.record;

};
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
static create: <Value_1 extends z.ZodType<any, z.ZodTypeDef> = z.ZodType<any, z.ZodTypeDef>>(valueType: Value_1) => ZodRecord<Value_1>;
}

@@ -24,5 +24,2 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
var ZodRecord = /** @class */ (function (_super) {

@@ -36,6 +33,6 @@ __extends(ZodRecord, _super);

}); };
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
return _this;
}
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
ZodRecord.create = function (valueType) {

@@ -42,0 +39,0 @@ return new ZodRecord({

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
import { ZodUnion } from './union';
export interface ZodStringDef extends z.ZodTypeDef {

@@ -13,4 +10,2 @@ t: z.ZodTypes.string;

export declare class ZodString extends z.ZodType<string, ZodStringDef> {
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
toJSON: () => ZodStringDef;

@@ -17,0 +12,0 @@ min: (minLength: number, message?: string | {

@@ -35,5 +35,5 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
// import { ZodUndefined } from './undefined';
// import { ZodNull } from './null';
// import { ZodUnion } from './union';
var __1 = require("..");

@@ -47,5 +47,5 @@ var errorUtil_1 = require("../helpers/errorUtil");

function ZodString() {
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.toJSON = function () { return _this._def; };

@@ -52,0 +52,0 @@ _this.min = function (minLength, message) {

import * as z from './base';
import { ZodUnion } from './union';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
export declare type TypeOfTuple<T extends [z.ZodTypeAny, ...z.ZodTypeAny[]] | []> = {

@@ -17,5 +14,3 @@ [k in keyof T]: T[k] extends z.ZodType<infer U> ? U : never;

};
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
static create: <T_1 extends [] | [z.ZodType<any, z.ZodTypeDef>, ...z.ZodType<any, z.ZodTypeDef>[]]>(schemas: T_1) => ZodTuple<T_1>;
}

@@ -24,5 +24,2 @@ "use strict";

var z = __importStar(require("./base"));
var union_1 = require("./union");
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var ZodTuple = /** @class */ (function (_super) {

@@ -36,6 +33,6 @@ __extends(ZodTuple, _super);

}); };
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
return _this;
}
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
ZodTuple.create = function (schemas) {

@@ -42,0 +39,0 @@ return new ZodTuple({

import * as z from './base';
import { ZodUnion } from './union';
import { ZodNull } from './null';
export interface ZodUndefinedDef extends z.ZodTypeDef {

@@ -9,5 +7,3 @@ t: z.ZodTypes.undefined;

toJSON: () => z.ZodTypeDef;
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
static create: () => ZodUndefined;
}

@@ -24,4 +24,2 @@ "use strict";

var z = __importStar(require("./base"));
var union_1 = require("./union");
var null_1 = require("./null");
var ZodUndefined = /** @class */ (function (_super) {

@@ -32,6 +30,6 @@ __extends(ZodUndefined, _super);

_this.toJSON = function () { return _this._def; };
_this.optional = function () { return union_1.ZodUnion.create([_this, ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
return _this;
}
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
ZodUndefined.create = function () {

@@ -38,0 +36,0 @@ return new ZodUndefined({

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
export interface ZodUnionDef<T extends [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]] = [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]]> extends z.ZodTypeDef {

@@ -9,4 +7,2 @@ t: z.ZodTypes.union;

export declare class ZodUnion<T extends [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]]> extends z.ZodType<T[number]['_type'], ZodUnionDef<T>> {
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
toJSON: () => {

@@ -16,3 +12,4 @@ t: z.ZodTypes.union;

};
distribute: <F extends (arg: T[number]) => z.ZodType<any, z.ZodTypeDef>>(f: F) => ZodUnion<{ [k in keyof T]: ReturnType<F>; }>;
static create: <T_1 extends [z.ZodType<any, z.ZodTypeDef>, z.ZodType<any, z.ZodTypeDef>, ...z.ZodType<any, z.ZodTypeDef>[]]>(types: T_1) => ZodUnion<T_1>;
}

@@ -24,10 +24,8 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var ZodUnion = /** @class */ (function (_super) {
__extends(ZodUnion, _super);
function ZodUnion() {
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.optional = function () { return ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return ZodUnion.create([_this, null_1.ZodNull.create()]); };
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.toJSON = function () { return ({

@@ -37,2 +35,5 @@ t: _this._def.t,

}); };
_this.distribute = function (f) {
return ZodUnion.create(_this._def.options.map(f));
};
return _this;

@@ -39,0 +40,0 @@ }

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
import { ZodUnion } from './union';
export interface ZodUnknownDef extends z.ZodTypeDef {

@@ -9,6 +6,4 @@ t: z.ZodTypes.unknown;

export declare class ZodUnknown extends z.ZodType<unknown, ZodUnknownDef> {
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
toJSON: () => ZodUnknownDef;
static create: () => ZodUnknown;
}

@@ -24,5 +24,2 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
var ZodUnknown = /** @class */ (function (_super) {

@@ -32,4 +29,4 @@ __extends(ZodUnknown, _super);

var _this = _super !== null && _super.apply(this, arguments) || this;
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.toJSON = function () { return _this._def; };

@@ -36,0 +33,0 @@ return _this;

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
import { ZodUnion } from './union';
export interface ZodVoidDef extends z.ZodTypeDef {

@@ -9,6 +6,4 @@ t: z.ZodTypes.void;

export declare class ZodVoid extends z.ZodType<void, ZodVoidDef> {
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
toJSON: () => ZodVoidDef;
static create: () => ZodVoid;
}

@@ -24,5 +24,2 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
var ZodVoid = /** @class */ (function (_super) {

@@ -32,4 +29,4 @@ __extends(ZodVoid, _super);

var _this = _super !== null && _super.apply(this, arguments) || this;
_this.optional = function () { return union_1.ZodUnion.create([_this, undefined_1.ZodUndefined.create()]); };
_this.nullable = function () { return union_1.ZodUnion.create([_this, null_1.ZodNull.create()]); };
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
_this.toJSON = function () { return _this._def; };

@@ -36,0 +33,0 @@ return _this;

@@ -84,2 +84,3 @@ import { ZodParsedType } from './parser';

};
export declare const quotelessJson: (obj: any) => string;
export declare class ZodError extends Error {

@@ -93,3 +94,9 @@ errors: ZodSuberror[];

addErrors: (subs?: ZodSuberror[]) => void;
readonly formErrors: {
formErrors: string[];
fieldErrors: {
[k: string]: string[];
};
};
}
export {};

@@ -32,2 +32,6 @@ "use strict";

]);
exports.quotelessJson = function (obj) {
var json = JSON.stringify(obj, null, 2); // {"name":"John Smith"}
return json.replace(/"([^"]+)":/g, '$1:');
};
var ZodError = /** @class */ (function (_super) {

@@ -54,8 +58,15 @@ __extends(ZodError, _super);

get: function () {
return this.errors
.map(function (_a) {
var path = _a.path, message = _a.message;
return path.length ? path.join('.') + ": " + message : "" + message;
})
.join('\n');
var errorMessage = [this.errors.length + " validation issue(s)", ''];
for (var _i = 0, _a = this.errors; _i < _a.length; _i++) {
var err = _a[_i];
errorMessage.push(" Issue #" + this.errors.indexOf(err) + ": " + err.code + " at " + err.path.join('.'));
errorMessage.push(" " + err.message);
errorMessage.push('');
}
return errorMessage.join('\n');
// return quotelessJson(this);
// .map(({ path, message }) => {
// return path.length ? `${path.join('.')}: ${message}` : `${message}`;
// })
// .join('\n');
},

@@ -72,2 +83,21 @@ enumerable: true,

});
Object.defineProperty(ZodError.prototype, "formErrors", {
get: function () {
var fieldErrors = {};
var formErrors = [];
for (var _i = 0, _a = this.errors; _i < _a.length; _i++) {
var sub = _a[_i];
if (sub.path.length > 0) {
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
fieldErrors[sub.path[0]].push(sub.message);
}
else {
formErrors.push(sub.message);
}
}
return { formErrors: formErrors, fieldErrors: fieldErrors };
},
enumerable: true,
configurable: true
});
ZodError.create = function (errors) {

@@ -74,0 +104,0 @@ var error = new ZodError(errors);

{
"name": "zod",
"version": "1.9.0",
"version": "1.10.0-alpha.1",
"description": "TypeScript-first schema declaration and validation library with static type inference",

@@ -5,0 +5,0 @@ "main": "./lib/src/index.js",

@@ -13,4 +13,2 @@ <p align="center">

if you're happy and you know it, star this repo ⭐
<br/>
created by <a href="https://twitter.com/vriad" target="_blank">@vriad</a> 👋
</p>

@@ -26,2 +24,52 @@

# What is Zod
Zod is a TypeScript-first schema declaration and validation library. I'm using the term "schema" to broadly refer to any data type/structure, from a simple `string` to a complex nested object.
Zod is designed to be as developer-friendly as possible. My goal is to eliminate duplicative type declarations wherever possible. With Zod, you declare a validator _once_ and Zod will automatically infer the static TypeScript type. It's easy to compose simpler types into complex data structures.
Some other great aspects:
- Zero dependencies
- Tiny: 8kb minified + zipped
- Immutability: methods (i.e. `.optional()` return a new instance
- Concise, chainable interface
- Functional approach: [parse, don't validate](https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/)
# Sponsorship
Hi! 👋
I'm Colin (AKA [@vriad](https://twitter.com/vriad)), creator/maintainer of Zod. Currently I work on Zod in my spare time, but I'd love to drop my other commitments and work on it (and other OSS projects) full time. To that end, I recently applied and was accepted into the GitHub Sponsors program, which I hope will provide the resources I need to focus on open-source full time.
If you make money from the software you build with Zod, I would massively appreciate a sponsorship at any level! 🙏 https://github.com/sponsors/vriad
<p align="right">
— Colin
</p>
### Sponsors
<table>
<tr>
<td align="center">
<a href="https://twitter.com/flybayer"><img src="https://avatars2.githubusercontent.com/u/8813276?s=460&u=4ff8beb9a67b173015c4b426a92d89cab960af1b&v=4" width="100px;" alt=""/><br /><b>Brandon Bayer</b></a><br/>
<span>Creator of <a href="https://blitzjs.com">Blitz.js</a></span>
<br />
</td>
</tr>
</table>
_To get your name + Twitter + website here, sponsor Zod at the [Freelancer](https://github.com/sponsors/vriad) or [Consultancy](https://github.com/sponsors/vriad) tier._
<!--
| | |
|---|-|
| <p align="center"> Brandon Bayer<br>[@flybayer](https://twitter.com/flybayer)</p> | _To get your name + Twitter + website here, <br/>sponsor Zod at the [Freelancer](https://github.com/sponsors/vriad) or [Consultancy](https://github.com/sponsors/vriad) tier._ |
| | -->
<!-- ### Sponsors who know Zod
_To get your name + Twitter + website here, sponsor Zod at the [Freelancer](https://github.com/sponsors/vriad) or [Consultancy](https://github.com/sponsors/vriad) tier._ -->
# Table of contents

@@ -83,10 +131,9 @@

1. Zod 1.x requires TypeScript 3.2+
2. You must configure your project to use TypeScript's **strict mode**. Otherwise Zod can't correctly infer the types of your schemas!
2. You must enable `strictNullChecks` or use `strict` mode which includes `strictNullChecks`. Otherwise Zod can't correctly infer the types of your schemas!
```ts
// tsconfig.json
{
// ...
"compilerOptions": {
// ...
"strict": true
"strictNullChecks": true
}

@@ -1189,3 +1236,3 @@ }

There is a dedicated guide on Zod's error handling system here: [ERROR_HANDLING.md](https://github.com/vriad/zod/blob/beta/ERROR_HANDLING.md)
There is a dedicated guide on Zod's error handling system here: [ERROR_HANDLING.md](https://github.com/vriad/zod/blob/master/ERROR_HANDLING.md)

@@ -1353,19 +1400,19 @@ # Comparison

| zod version | release notes |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| zod@1.9 | Added z.instanceof() and z.custom(). Implemented ZodSchema.array() method. |
| zod@1.8 | Introduced z.void(). Major overhaul to error handling system, including the introduction of custom error maps. Wrote new [error handling guide](https://github.com/vriad/zod/blob/beta/ERROR_HANDLING.md). |
| zod@1.7 | Added several built-in validators to string, number, and array schemas. Calls to `.refine` now return new instance. |
| zod@1.5 | Any and unknown types |
| zod@1.4 | Refinement types (`.refine`), `.parse` no longer returns deep clone |
| zod@1.3 | Promise schemas |
| zod@1.2.6 | `.parse` accepts `unknown`, `bigint` schemas |
| zod@1.2.5 | `.partial` and `.deepPartial` on object schemas |
| zod@1.2.3 | Date schemas |
| zod@1.2.0 | `.pick`, `.omit`, and `.extend` on object schemas |
| zod@1.1.0 | Records |
| zod@1.0.11 | `.nonstrict` |
| zod@1.0.10 | Type assertions with `.check` |
| zod@1.0.4 | Empty tuples |
| zod@1.0.0 | Type assertions, literals, enums, detailed error reporting |
| zod@1.0.0 | Initial release |
| zod version | release notes |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| zod@1.9 | Added z.instanceof() and z.custom(). Implemented ZodSchema.array() method. |
| zod@1.8 | Introduced z.void(). Major overhaul to error handling system, including the introduction of custom error maps. Wrote new [error handling guide](https://github.com/vriad/zod/blob/master/ERROR_HANDLING.md). |
| zod@1.7 | Added several built-in validators to string, number, and array schemas. Calls to `.refine` now return new instance. |
| zod@1.5 | Any and unknown types |
| zod@1.4 | Refinement types (`.refine`), `.parse` no longer returns deep clone |
| zod@1.3 | Promise schemas |
| zod@1.2.6 | `.parse` accepts `unknown`, `bigint` schemas |
| zod@1.2.5 | `.partial` and `.deepPartial` on object schemas |
| zod@1.2.3 | Date schemas |
| zod@1.2.0 | `.pick`, `.omit`, and `.extend` on object schemas |
| zod@1.1.0 | Records |
| zod@1.0.11 | `.nonstrict` |
| zod@1.0.10 | Type assertions with `.check` |
| zod@1.0.4 | Empty tuples |
| zod@1.0.0 | Type assertions, literals, enums, detailed error reporting |
| zod@1.0.0 | Initial release |

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

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

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

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

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

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc