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.10.0 to 1.11.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);

24

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;

@@ -41,15 +42,16 @@ declare const numberType: () => ZodNumber;

declare const voidType: () => ZodVoid;
declare const arrayType: <T extends ZodType<any, ZodTypeDef>>(schema: T) => ZodArray<T>;
declare const arrayType: <T extends ZodType<any, any>>(schema: T) => ZodArray<T>;
declare const objectType: <T extends import("./types/base").ZodRawShape>(shape: T) => ZodObject<T, {
strict: true;
}, { [k in keyof ({ [k in { [k in keyof { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }]: undefined extends { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }[k] ? k : never; }[{ [k in keyof T]: T[k] extends never ? never : k; }[keyof T]]]?: { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }[k] | undefined; } & { [k in Exclude<{ [k in keyof T]: T[k] extends never ? never : k; }[keyof T], { [k in keyof { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }]: undefined extends { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }[k] ? k : never; }[{ [k in keyof T]: T[k] extends never ? never : k; }[keyof T]]>]: { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }[k]; })]: ({ [k in { [k in keyof { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }]: undefined extends { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }[k] ? k : never; }[{ [k in keyof T]: T[k] extends never ? never : k; }[keyof T]]]?: { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }[k] | undefined; } & { [k in Exclude<{ [k in keyof T]: T[k] extends never ? never : k; }[keyof T], { [k in keyof { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }]: undefined extends { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }[k] ? k : never; }[{ [k in keyof T]: T[k] extends never ? never : k; }[keyof T]]>]: { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }[k]; })[k]; }>;
declare const unionType: <T extends [ZodType<any, ZodTypeDef>, ZodType<any, ZodTypeDef>, ...ZodType<any, ZodTypeDef>[]]>(types: T) => ZodUnion<T>;
declare const intersectionType: <T extends ZodType<any, ZodTypeDef>, U extends ZodType<any, ZodTypeDef>>(left: T, right: U) => ZodIntersection<T, U>;
declare const tupleType: <T extends [] | [ZodType<any, ZodTypeDef>, ...ZodType<any, ZodTypeDef>[]]>(schemas: T) => ZodTuple<T>;
declare const recordType: <Value extends ZodType<any, ZodTypeDef> = ZodType<any, ZodTypeDef>>(valueType: Value) => ZodRecord<Value>;
declare const functionType: <T extends ZodTuple<any> = ZodTuple<[]>, U extends ZodType<any, ZodTypeDef> = ZodVoid>(args?: T | undefined, returns?: U | undefined) => ZodFunction<T, U>;
declare const lazyType: <T extends ZodType<any, ZodTypeDef>>(getter: () => T) => ZodLazy<T>;
declare const unionType: <T extends [ZodType<any, any>, ZodType<any, any>, ...ZodType<any, any>[]]>(types: T) => ZodUnion<T>;
declare const intersectionType: <T extends ZodType<any, any>, U extends ZodType<any, any>>(left: T, right: U) => ZodIntersection<T, U>;
declare const tupleType: <T extends [] | [ZodType<any, any>, ...ZodType<any, any>[]]>(schemas: T) => ZodTuple<T>;
declare const recordType: <Value extends ZodType<any, any> = ZodType<any, any>>(valueType: Value) => ZodRecord<Value>;
declare const functionType: <T extends ZodTuple<any> = ZodTuple<[]>, U extends ZodType<any, any> = ZodVoid>(args?: T | undefined, returns?: U | undefined) => ZodFunction<T, U>;
declare const lazyType: <T extends ZodType<any, any>>(getter: () => T) => ZodLazy<T>;
declare const literalType: <T extends import("./helpers/primitive").Primitive>(value: T) => ZodLiteral<T>;
declare const enumType: <U extends string, T extends [U, ...U[]]>(values: T) => ZodEnum<T>;
declare const promiseType: <T extends ZodType<any, ZodTypeDef>>(schema: T) => ZodPromise<T>;
declare const promiseType: <T extends ZodType<any, any>>(schema: T) => ZodPromise<T>;
declare const codecType: <I extends ZodType<any, any>, O extends ZodType<any, any>>(input: I, output: O, transformer: (arg: I["_type"]) => O["_type"]) => ZodCodec<I, O>;
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;

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

var error = new ZodError_1.ZodError([]);
var returnValue = obj;
var parsedType = exports.getParsedType(obj);

@@ -366,3 +367,3 @@ switch (def.t) {

try {
def.returns.parse(result);
return def.returns.parse(result);
}

@@ -380,4 +381,2 @@ catch (err) {

}
def.returns.parse(result);
return result;
};

@@ -447,2 +446,7 @@ return validatedFunc;

}); });
case z.ZodTypes.codec:
def.input.parse(obj);
returnValue = def.transformer(obj);
def.output.parse(returnValue);
break;
default:

@@ -462,4 +466,4 @@ util_1.util.assertNever(def);

}
return obj;
return returnValue;
}; };
//# sourceMappingURL=parser.js.map
"use strict";
// import * as z from '.';
// const ZodRHF = <T extends z.ZodType<any,any>>(schema:T)=>(values:any)=>{
// try{
// schema.parse(values)
// return {}
// }catch(err){
// return (err as z.ZodError).formErrors.fieldErrors;
// }
// }
// z.string()
// .parseAsync(undefined)
// .catch(err => console.log(JSON.stringify(err.errors, null, 2)));
// export const errorMap: z.ZodErrorMap = (err, ctx) => {
// if (err.code === z.ZodErrorCode.invalid_type) {
// if (err.received === 'undefined') {
// return { message: 'Required.' };
// }
// }
// return { message: ctx.defaultError };
// };
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var z = __importStar(require("."));
var trimAndMultiply = z.ZodCodec.fromSchema(z.string())
.transform(z.number(), function (x) { return parseFloat(x); })
.transform(z.number(), function (num) { return num * 5; })
.refine(function (x) {
console.log("x: " + x);
return x > 30;
}, 'Number is too small');
console.log(trimAndMultiply.parse('5'));
//# sourceMappingURL=playground.js.map

@@ -22,3 +22,3 @@ import * as z from './base';

nonempty: () => ZodNonEmptyArray<T>;
static create: <T_1 extends z.ZodType<any, z.ZodTypeDef>>(schema: T_1) => ZodArray<T_1>;
static create: <T_1 extends z.ZodType<any, any>>(schema: T_1) => ZodArray<T_1>;
}

@@ -25,0 +25,0 @@ export declare class ZodNonEmptyArray<T extends z.ZodTypeAny> extends z.ZodType<[T['_type'], ...T['_type'][]], ZodArrayDef<T>> {

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

@@ -26,5 +26,6 @@ export declare enum ZodTypes {

unknown = "unknown",
void = "void"
void = "void",
codec = "codec"
}
export declare type ZodTypeAny = ZodType<any>;
export declare type ZodTypeAny = ZodType<any, any>;
export declare type ZodRawShape = {

@@ -43,2 +44,3 @@ [k: string]: ZodTypeAny;

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

@@ -66,3 +68,5 @@ export declare type TypeOf<T extends {

array: () => ZodArray<this>;
accepts: <U extends ZodType<any>, Tx extends (arg: U['_type']) => this['_type']>(x: U, transformer: Tx) => ZodCodec<U, this>;
or: <U extends ZodType<any>>(arg: U) => ZodUnion<[this, U]>;
}
export {};

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

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

@@ -72,2 +73,21 @@ var ZodType = /** @class */ (function () {

this.array = function () { return __1.ZodArray.create(_this); };
// pre: <T extends string>(
// input: T,
// transformer: (arg: T) => Type,
// ) => any = (input, transformer) => 'adsf';
this.accepts = function (input, transformer) {
return __1.ZodCodec.create(input, _this, transformer);
};
// codec = (): ZodCodec<this, this> => {
// return ZodCodec.create(this, this, x => x);
// };
// transform: <U extends ZodType<any>, Tx extends (arg: Type) => U['_type']>(
// x: U,s
// transformer: Tx,
// ) => ZodCodec<this, U> = (input, transformer) => {
// return ZodCodec.create(input, this, transformer);
// };
this.or = function (arg) {
return __1.ZodUnion.create([_this, arg]);
};
this.parse = parser_1.ZodParser(def);

@@ -74,0 +94,0 @@ this._def = def;

@@ -13,7 +13,7 @@ import * as z from './base';

readonly _type: TypeOfFunction<Args, Returns>;
args: <Items extends [] | [z.ZodType<any, z.ZodTypeDef>, ...z.ZodType<any, z.ZodTypeDef>[]]>(...items: Items) => ZodFunction<ZodTuple<Items>, Returns>;
args: <Items extends [] | [z.ZodType<any, any>, ...z.ZodType<any, any>[]]>(...items: Items) => ZodFunction<ZodTuple<Items>, Returns>;
returns: <NewReturnType extends z.ZodType<any, any>>(returnType: NewReturnType) => ZodFunction<Args, NewReturnType>;
implement: (func: TypeOfFunction<Args, Returns>) => TypeOfFunction<Args, Returns>;
validate: (func: TypeOfFunction<Args, Returns>) => TypeOfFunction<Args, Returns>;
static create: <T extends ZodTuple<any> = ZodTuple<[]>, U extends z.ZodType<any, z.ZodTypeDef> = ZodVoid>(args?: T | undefined, returns?: U | undefined) => ZodFunction<T, U>;
static create: <T extends ZodTuple<any> = ZodTuple<[]>, U extends z.ZodType<any, any> = ZodVoid>(args?: T | undefined, returns?: U | undefined) => ZodFunction<T, U>;
toJSON: () => {

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

@@ -13,3 +13,3 @@ import * as z from './base';

};
static create: <T_1 extends z.ZodType<any, z.ZodTypeDef>, U_1 extends z.ZodType<any, z.ZodTypeDef>>(left: T_1, right: U_1) => ZodIntersection<T_1, U_1>;
static create: <T_1 extends z.ZodType<any, any>, U_1 extends z.ZodType<any, any>>(left: T_1, right: U_1) => ZodIntersection<T_1, U_1>;
}

@@ -9,3 +9,3 @@ import * as z from './base';

toJSON: () => never;
static create: <T_1 extends z.ZodType<any, z.ZodTypeDef>>(getter: () => T_1) => ZodLazy<T_1>;
static create: <T_1 extends z.ZodType<any, any>>(getter: () => T_1) => ZodLazy<T_1>;
}

@@ -11,3 +11,3 @@ import * as z from './base';

};
static create: <T_1 extends z.ZodType<any, z.ZodTypeDef>>(schema: T_1) => ZodPromise<T_1>;
static create: <T_1 extends z.ZodType<any, any>>(schema: T_1) => ZodPromise<T_1>;
}

@@ -13,3 +13,3 @@ import * as z from './base';

};
static create: <Value_1 extends z.ZodType<any, z.ZodTypeDef> = z.ZodType<any, z.ZodTypeDef>>(valueType: Value_1) => ZodRecord<Value_1>;
static create: <Value_1 extends z.ZodType<any, any> = z.ZodType<any, any>>(valueType: Value_1) => ZodRecord<Value_1>;
}
import * as z from './base';
import { errorUtil } from '../helpers/errorUtil';
export interface ZodStringDef extends z.ZodTypeDef {

@@ -17,5 +18,3 @@ t: z.ZodTypes.string;

} | undefined) => this;
length: (len: number, message?: string | {
message?: string | undefined;
} | undefined) => this;
length(len: number, message?: errorUtil.ErrMessage): this;
email: (message?: string | {

@@ -22,0 +21,0 @@ message?: string | undefined;

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

};
_this.length = function (len, message) { return _this.min(len, message).max(len, message); };
_this.email = function (message) {

@@ -70,2 +69,5 @@ return _this._refinement(__assign({ check: function (data) { return emailRegex.test(data); }, code: __1.ZodErrorCode.invalid_string, validation: 'email' }, errorUtil_1.errorUtil.errToObj(message)));

}
ZodString.prototype.length = function (len, message) {
return this.min(len, message).max(len, message);
};
ZodString.create = function () {

@@ -72,0 +74,0 @@ return new ZodString({

@@ -14,3 +14,3 @@ import * as z from './base';

};
static create: <T_1 extends [] | [z.ZodType<any, z.ZodTypeDef>, ...z.ZodType<any, z.ZodTypeDef>[]]>(schemas: T_1) => ZodTuple<T_1>;
static create: <T_1 extends [] | [z.ZodType<any, any>, ...z.ZodType<any, any>[]]>(schemas: T_1) => ZodTuple<T_1>;
}

@@ -11,4 +11,3 @@ import * as z from './base';

};
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>;
static create: <T_1 extends [z.ZodType<any, any>, z.ZodType<any, any>, ...z.ZodType<any, any>[]]>(types: T_1) => ZodUnion<T_1>;
}

@@ -34,7 +34,7 @@ "use strict";

}); };
_this.distribute = function (f) {
return ZodUnion.create(_this._def.options.map(f));
};
return _this;
}
// distribute = <F extends (arg: T[number]) => z.ZodTypeAny>(f: F): ZodUnion<{ [k in keyof T]: ReturnType<F> }> => {
// return ZodUnion.create(this._def.options.map(f) as any);
// };
ZodUnion.create = function (types) {

@@ -41,0 +41,0 @@ return new ZodUnion({

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

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

@@ -1276,2 +1276,11 @@ <p align="center">

- Missing object methods: (pick, omit, partial, deepPartial, merge, extend)
- Missing nonempty arrays with proper typing (`[T, ...T[]]`)
- Missing lazy/recursive types
- Missing promise schemas
- Missing function schemas
- Missing union & intersection schemas
- Missing support for parsing cyclical data (maybe)
- Missing error customization
#### Joi

@@ -1281,3 +1290,3 @@

Doesn't support static type inference. Boo. ๐Ÿ˜•
Doesn't support static type inference ๐Ÿ˜•

@@ -1290,48 +1299,15 @@ #### Yup

Yup supports static type inference! But unfortunately the inferred types aren't actually correct.
Differences
##### Incorrect object typing (now fixed!)
- Supports for casting and transformation
- All object fields are optional by default
- Non-standard `.required()`ยน
- Missing object methods: (pick, omit, partial, deepPartial, merge, extend)
- Missing nonempty arrays with proper typing (`[T, ...T[]]`)
- Missing promise schemas
- Missing function schemas
- Missing union & intersection schemas
This issue was fixed on May 19, 2020 ([here](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/44589)).
ยน Yup has a strange interpretation of the `.required()` is odd and non-standard. Instead of meaning "not undefined", Yup uses it to mean "not empty". So `yup.string().required()` will not accept an empty string, and `yup.array(yup.string()).required()` will not accept an empty array. For Zod arrays there is a dedicated `.nonempty()` method to indicate this, or you can implement it with a custom validator.
<del>Currently, the yup package treats all object properties as optional by default:</del>.
```ts
const schema = yup.object({
asdf: yup.string(),
});
schema.validate({}); // passes
```
Yet the inferred type indicates that all properties are required:
```ts
type SchemaType = yup.InferType<typeof schema>;
// returns { asdf: string }
// should be { asdf?: string }
```
##### Unintuitive `.required()` behavior
In general, Yup's interpretation of `.required()` is odd and non-standard. Instead of meaning "not undefined", Yup uses it to mean "not empty". So `yup.string().required()` will not accept an empty string, and `yup.array(yup.string()).required()` will not accept an empty array. For Zod arrays there is a dedicated `.nonempty()` method to indicate this, or you can implement it with a custom validator.
```ts
const numList = yup
.array()
.of(yup.string())
.required();
// interpreted as a non-empty list
numList.validateSync([]); // fails
// yet the inferred type doesn't reflect this
type NumList = yup.InferType<typeof numList>;
// returns string[]
// should be [string,...string[]]
```
##### Unions and intersections
Finally, Yup doesn't support any generic `union` or `intersection` operator.
#### io-ts

@@ -1343,6 +1319,4 @@

In our experience, io-ts prioritizes functional programming purity over developer experience in many cases. This is a valid and admirable design goal, but it makes io-ts particularly hard to integrate into an existing codebase with a more procedural or object-oriented bias.
In our experience, io-ts prioritizes functional programming purity over developer experience in many cases. This is a valid and admirable design goal, but it makes io-ts particularly hard to integrate into an existing codebase with a more procedural or object-oriented bias. For instance, consider how to define an object with optional properties in io-ts:
For instance, consider how to define an object with optional properties in io-ts:
```ts

@@ -1381,4 +1355,16 @@ import * as t from 'io-ts';

`io-ts` also requires the use of gcanti's functional programming library `fp-ts` to parse results and handle errors. This is another fantastic resource for developers looking to keep their codebase strictly functional. But depending on `fp-ts` necessarily comes with a lot of intellectual overhead; a developer has to be familiar with functional programming concepts, `fp-ts`'s nomenclature, and the `Either` monad to do a simple schema validation. It's just not worth it for many people.
`io-ts` also requires the use of gcanti's functional programming library `fp-ts` to parse results and handle errors. This is another fantastic resource for developers looking to keep their codebase strictly functional. But depending on `fp-ts` necessarily comes with a lot of intellectual overhead; a developer has to be familiar with functional programming concepts and the `fp-ts` nomenclature to use the library.
- Supports codecs with seria\lization & deserialization transforms
- Supports branded types
- Supports advanced functional programming, higher-kinded types, `fp-ts` compatibility
- Missing object methods: (pick, omit, partial, deepPartial, merge, extend)
- Missing nonempty arrays with proper typing (`[T, ...T[]]`)
- Missing lazy/recursive types
- Missing promise schemas
- Missing function schemas
- Missing union & intersection schemas
- Missing support for parsing cyclical data (maybe)
- Missing error customization
#### Runtypes

@@ -1390,2 +1376,12 @@

- Supports "pattern matching": computed properties that distribute over unions
- Supports readonly types
- Missing object methods: (pick, omit, partial, deepPartial, merge, extend)
- Missing nonempty arrays with proper typing (`[T, ...T[]]`)
- Missing lazy/recursive types
- Missing promise schemas
- Missing union & intersection schemas
- Missing error customization
- Missing record schemas (their "record" is equivalent to Zod "object")
#### Ow

@@ -1401,19 +1397,2 @@

| 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 |
View the changelog at [CHANGELOG.md](https://github.com/vriad/zod/blob/master/CHANGELOG.md)

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