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.6.1 to 1.6.2

2

lib/src/parser.js

@@ -343,3 +343,3 @@ "use strict";

var check = customChecks_1[_b];
if (check.check(obj) !== true) {
if (!check.check(obj)) {
throw ZodError_1.ZodError.fromString(check.message || "Failed custom check.");

@@ -346,0 +346,0 @@ }

"use strict";
// import * as z from '.';
// export const TestObject = z
// // const stringSchema = z.string();
// // try {
// // stringSchema.parse(12);
// // } catch (err) {
// // const zerr: z.ZodError = err;
// // zerr.stack;
// // console.log(err instanceof z.ZodError);
// // if (err instanceof z.ZodError) {
// // // handle
// // // err.
// // }
// // }
// const myObject = z
// .object({
// email: z.string(),
// firstName: z.string(),
// lastName: z.string(),
// first: z.string(),
// second: z.string(),
// })
// .nonstrict();
// // const asdf = TestObject.parse('doesntmatter');
// // export type TestObject = z.infer<typeof TestObject>;
// // const asfdwer:TestObject = "asdf" as any;
// const testUnion = z.object({ asdf: z.array(z.union([z.string(), z.number()])) });
// testUnion.parse({ asdf: [false] });
// .partial()
// .refine(data => data.first || data.second, 'Either first or second should be filled in.');
// myObject.parse({
// first: 'asdf',
// });
// myObject.parse({
// second: 'asdf',
// });
// myObject.parse({
// first: 'wqewdscsdf',
// second: 'asdf',
// });
// myObject.parse({});
//# sourceMappingURL=playground.js.map

@@ -49,3 +49,3 @@ import { ParseParams } from '../parser';

check(u: Type | unknown): u is Type;
refine: <Val extends (arg: this["_type"]) => boolean>(check: Val, message: string) => this;
refine: <Val extends (arg: this["_type"]) => any>(check: Val, message?: string) => this;
constructor(def: Def);

@@ -52,0 +52,0 @@ abstract toJSON: () => object;

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

this.refine = function (check, message) {
if (message === void 0) { message = 'Invalid value.'; }
_this._def.checks = _this._def.checks || [];

@@ -45,0 +46,0 @@ _this._def.checks.push({ check: check, message: message });

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

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

@@ -44,2 +44,12 @@ "use strict";

};
ZodUnion.make = function () {
var types = [];
for (var _i = 0; _i < arguments.length; _i++) {
types[_i] = arguments[_i];
}
return new ZodUnion({
t: z.ZodTypes.union,
options: types,
});
};
return ZodUnion;

@@ -46,0 +56,0 @@ }(z.ZodType));

{
"name": "zod",
"version": "1.6.1",
"version": "1.6.2",
"description": "TypeScript-first schema declaration and validation library with static type inference",

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

@@ -5,14 +5,14 @@ <p align="center">

</p>
<div style="display:flex;flex-direction:row;justify-content:center;flex-wrap:wrap;">
<p align="center">
<a href="https://opensource.org/licenses/MIT" rel="nofollow"><img src="https://img.shields.io/github/license/vriad/zod" alt="License"></a>
<a href="https://www.npmjs.com/package/zod" rel="nofollow"><img src="https://img.shields.io/npm/dw/zod.svg" alt="npm"></a>
<a href="https://www.npmjs.com/package/zod" rel="nofollow"><img src="https://img.shields.io/github/stars/vriad/zod" alt="stars"></a>
<a href="./src/__tests__" rel="nofollow"><img src="./coverage.svg" alt="coverage"></a>
</p>
<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>
[![License][license-image]][license-url]
[![npm](https://img.shields.io/npm/dw/zod.svg)](https://www.npmjs.com/package/zod)
[![stars](https://img.shields.io/github/stars/vriad/zod)](https://img.shields.io/github/stars/vriad/zod)
[![coverage](./coverage.svg)](./src/__tests__)
</div>
[license-url]: https://opensource.org/licenses/MIT
[license-image]: https://img.shields.io/github/license/vriad/zod
<br/>

@@ -26,3 +26,3 @@

#### Table of contents
# Table of contents

@@ -44,3 +44,3 @@ - [Installation](#installation)

- [Arrays](#arrays)
- [.nonempty](#nonempty-arrays)
- [.nonempty](#non-empty-lists)
- [Unions](#unions)

@@ -528,3 +528,3 @@ - [.optional](#optional-types)

const nonEmptyDogsList = z.array(dogSchema).nonempty();
nonEmptyDogsList.parse([]); // throws Error("Array cannot be empty")
nonEmptyDogsList.parse([]); // throws: "Array cannot be empty"
```

@@ -1058,3 +1058,3 @@

Doesn't support static type inference. 😕
Doesn't support static type inference. Boo. 😕

@@ -1067,4 +1067,10 @@ #### Yup

Yup supports static type inference, but unfortunately the inferred types aren't actually correct. Currently, the yup package treats all object properties as optional by default:
Yup supports static type inference! But unfortunately the inferred types aren't actually correct.
##### Incorrect object typing (now fixed!)
This issue was fixed on May 19, 2020 ([here](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/44589)).
<del>Currently, the yup package treats all object properties as optional by default:</del>.
```ts

@@ -1075,3 +1081,7 @@ const schema = yup.object({

schema.validate({}); // passes
```
Yet the inferred type indicates that all properties are required:
```ts
type SchemaType = yup.InferType<typeof schema>;

@@ -1082,4 +1092,6 @@ // returns { asdf: string }

Yup also mis-infers the type of required arrays.
##### 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

@@ -1100,4 +1112,6 @@ const numList = yup

These may sound like nitpicks but it can result in some very unintuitive behavior/bugs.
##### Unions and intersections
Finally, Yup doesn't support any generic `union` or `intersection` operator.
#### io-ts

@@ -1104,0 +1118,0 @@

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