forked from colinhacks/zod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Colin McDonnell
committed
Nov 10, 2020
1 parent
e6b11d7
commit f6759d0
Showing
17 changed files
with
154 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
| [email protected] | Introduced `.safeParse` option.<br>Introduced .regex method on string schemas.<br>Implemented `.primitives()` and `.nonprimitives()` on object schemas.<br>Implemented `z.nativeEnum()` for creating schemas from TypeScript `enum`s.<br>Switched to `new URL()` constructor to check valid URLs. | | ||
| [email protected] | Dropping support for TypeScript 3.2 . | | ||
| [email protected] | Added z.instanceof() and z.custom(). Implemented ZodSchema.array() method. | | ||
| [email protected] | 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). | | ||
| [email protected] | Introduced z.void(). Major overhaul to error handling system, including the introduction of custom error maps. Wrote new [error handling guide](https://github.com/colinhacks/zod/blob/master/ERROR_HANDLING.md). | | ||
| [email protected] | Added several built-in validators to string, number, and array schemas. Calls to `.refine` now return new instance. | | ||
| [email protected] | Any and unknown types | | ||
| [email protected] | Refinement types (`.refine`), `.parse` no longer returns deep clone | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
github: vriad | ||
github: colinhacks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,10 @@ | |
<h1 align="center">Zod</h1> | ||
</p> | ||
<p align="center"> | ||
<a href="https://twitter.com/vriad" rel="nofollow"><img src="https://img.shields.io/badge/created%20by-@vriad-4BBAAB.svg" alt="Created by Colin McDonnell"></a> | ||
<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://twitter.com/colinhacks" rel="nofollow"><img src="https://img.shields.io/badge/created%20by-@colinhacks-4BBAAB.svg" alt="Created by Colin McDonnell"></a> | ||
<a href="https://opensource.org/licenses/MIT" rel="nofollow"><img src="https://img.shields.io/github/license/colinhacks/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="https://www.npmjs.com/package/zod" rel="nofollow"><img src="https://img.shields.io/github/stars/colinhacks/zod" alt="stars"></a> | ||
<a href="./src/__tests__" rel="nofollow"><img src="./coverage.svg" alt="coverage"></a> | ||
|
||
</p> | ||
|
@@ -16,7 +16,7 @@ if you're happy and you know it, star this repo ⭐ | |
|
||
<br/> | ||
|
||
<!-- **Zod 2 is coming! Follow [@vriad](https://twitter.com/vriad) to stay updated and discuss the future of Zod.** --> | ||
<!-- **Zod 2 is coming! Follow [@colinhacks](https://twitter.com/colinhacks) to stay updated and discuss the future of Zod.** --> | ||
|
||
### **Sept 17 — Zod 2 is now in beta!** | ||
|
||
|
@@ -45,10 +45,10 @@ In almost all cases, you'll be able to upgrade to Zod 2 without changing any cod | |
|
||
Aug 30 — [email protected] was released with lots of cool features! | ||
|
||
- All schemas now have a `.safeParse` method. This lets you validate data in a more functional way, similar to `io-ts`: https://github.com/vriad/zod#safe-parse | ||
- String schemas have a new `.regex` refinement method: https://github.com/vriad/zod#strings | ||
- Object schemas now have two new methods: `.primitives()` and `.nonprimitives()`. These methods let you quickly pick or omit primitive fields from objects, useful for validating API inputs: https://github.com/vriad/zod#primitives-and-nonprimitives | ||
- Zod now provides `z.nativeEnum()`, which lets you create z Zod schema from an existing TypeScript `enum`: https://github.com/vriad/zod#native-enums | ||
- All schemas now have a `.safeParse` method. This lets you validate data in a more functional way, similar to `io-ts`: https://github.com/colinhacks/zod#safe-parse | ||
- String schemas have a new `.regex` refinement method: https://github.com/colinhacks/zod#strings | ||
- Object schemas now have two new methods: `.primitives()` and `.nonprimitives()`. These methods let you quickly pick or omit primitive fields from objects, useful for validating API inputs: https://github.com/colinhacks/zod#primitives-and-nonprimitives | ||
- Zod now provides `z.nativeEnum()`, which lets you create z Zod schema from an existing TypeScript `enum`: https://github.com/colinhacks/zod#native-enums | ||
|
||
<!-- > ⚠️ You might be encountering issues building your project if you're using zod@<1.10.2. This is the result of a bug in the TypeScript compiler. To solve this without updating, set `"skipLibCheck": true` in your tsconfig.json "compilerOptions". This issue is resolved in [email protected] and later. --> | ||
|
||
|
@@ -70,7 +70,7 @@ Some other great aspects: | |
|
||
# Sponsorship | ||
|
||
I work on Zod in my free time, so if you're making money from a product that is built with Zod, I'd massively appreciate sponsorship at any level. For solo devs, I recommend the [Chipotle Bowl tier](https://github.com/sponsors/vriad) or the [Cup of Coffee tier](https://github.com/sponsors/vriad). If you're making money from a product you built using Zod, consider the [Startup tier]([Cup of Coffee tier](https://github.com/sponsors/vriad)). You can learn more about the tiers at [github.com/sponsors/vriad](github.com/sponsors/vriad). | ||
I work on Zod in my free time, so if you're making money from a product that is built with Zod, I'd massively appreciate sponsorship at any level. For solo devs, I recommend the [Chipotle Bowl tier](https://github.com/sponsors/colinhacks) or the [Cup of Coffee tier](https://github.com/sponsors/colinhacks). If you're making money from a product you built using Zod, consider the [Startup tier]([Cup of Coffee tier](https://github.com/sponsors/colinhacks)). You can learn more about the tiers at [github.com/sponsors/colinhacks](github.com/sponsors/colinhacks). | ||
|
||
### Sponsors | ||
|
||
|
@@ -99,7 +99,7 @@ I work on Zod in my free time, so if you're making money from a product that is | |
</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._ | ||
_To get your name + Twitter + website here, sponsor Zod at the [Freelancer](https://github.com/sponsors/colinhacks) or [Consultancy](https://github.com/sponsors/colinhacks) tier._ | ||
|
||
# Table of contents | ||
|
||
|
@@ -464,7 +464,7 @@ z.string().url({ message: 'Invalid url' }); | |
z.string().uuid({ message: 'Invalid UUID' }); | ||
``` | ||
|
||
> To see the email and url regexes, check out [this file](https://github.com/vriad/zod/blob/master/src/types/string.ts). To use a more advanced method, use a custom refinement. | ||
> To see the email and url regexes, check out [this file](https://github.com/colinhacks/zod/blob/master/src/types/string.ts). To use a more advanced method, use a custom refinement. | ||
## Numbers | ||
|
||
|
@@ -1478,7 +1478,6 @@ If this example sounds contrived, check out the homepage of the popular GraphQL | |
Zod's solution to this is "masking". Masking is known by a lot of other names too: _derived types_, _views_ (especially in the SQL world), _projections_, and more. | ||
#### Picking | ||
```ts | ||
const User = z.object({ | ||
|
@@ -1638,15 +1637,15 @@ type in = z.input<stringToNumber>; // string | |
|
||
## Errors | ||
|
||
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) | ||
There is a dedicated guide on Zod's error handling system here: [ERROR_HANDLING.md](https://github.com/colinhacks/zod/blob/master/ERROR_HANDLING.md) | ||
|
||
# Comparison | ||
|
||
There are a handful of other widely-used validation libraries, but all of them have certain design limitations that make for a non-ideal developer experience. | ||
|
||
<!-- The table below summarizes the feature differences. Below the table there are more involved discussions of certain alternatives, where necessary. --> | ||
|
||
<!-- | Feature | [Zod](https://github.com/vriad) | [Joi](https://github.com/hapijs/joi) | [Yup](https://github.com/jquense/yup) | [io-ts](https://github.com/gcanti/io-ts) | [Runtypes](https://github.com/pelotom/runtypes) | [ow](https://github.com/sindresorhus/ow) | [class-validator](https://github.com/typestack/class-validator) | | ||
<!-- | Feature | [Zod](https://github.com/colinhacks) | [Joi](https://github.com/hapijs/joi) | [Yup](https://github.com/jquense/yup) | [io-ts](https://github.com/gcanti/io-ts) | [Runtypes](https://github.com/pelotom/runtypes) | [ow](https://github.com/sindresorhus/ow) | [class-validator](https://github.com/typestack/class-validator) | | ||
| ---------------------------------------------------------------------------------------------------------------------- | :-----------------------------: | :----------------------------------: | :-----------------------------------: | :--------------------------------------: | :---------------------------------------------: | :--------------------------------------: | :-------------------------------------------------------------: | | ||
| <abbr title='Any ability to extract a TypeScript type from a validator instance counts.'>Type inference</abbr> | 🟢 | 🔴 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| <abbr title="Yup's inferred types are incorrect in certain cases, see discussion below.">Correct type inference</abbr> | 🟢 | 🔴 | 🔴 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
|
@@ -1797,4 +1796,4 @@ If you want to validate function inputs, use function schemas in Zod! It's a muc | |
|
||
# Changelog | ||
|
||
View the changelog at [CHANGELOG.md](https://github.com/vriad/zod/blob/master/CHANGELOG.md) | ||
View the changelog at [CHANGELOG.md](https://github.com/colinhacks/zod/blob/master/CHANGELOG.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
{ | ||
"name": "zod", | ||
"version": "2.0.0-beta.18", | ||
"version": "2.0.0-beta.21", | ||
"description": "TypeScript-first schema declaration and validation library with static type inference", | ||
"main": "./lib/cjs/index.js", | ||
"module": "./lib/esm/index.js", | ||
"types": "./lib/esm/index.d.ts", | ||
"types": "./lib/cjs/index.d.ts", | ||
"files": [ | ||
"lib" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/vriad/zod" | ||
"url": "https://github.com/colinhacks/zod" | ||
}, | ||
"author": "Colin McDonnell <colin@vriad.com>", | ||
"author": "Colin McDonnell <colin@colinhacks.com>", | ||
"license": "MIT", | ||
"sideEffects": false, | ||
"bugs": { | ||
"url": "https://github.com/vriad/zod/issues" | ||
"url": "https://github.com/colinhacks/zod/issues" | ||
}, | ||
"homepage": "https://github.com/vriad/zod", | ||
"homepage": "https://github.com/colinhacks/zod", | ||
"dependencies": {}, | ||
"keywords": [ | ||
"typescript", | ||
|
@@ -29,7 +28,7 @@ | |
], | ||
"scripts": { | ||
"clean": "rm -rf lib/*", | ||
"build": "yarn run clean && tsc --p tsconfig.json && tsc --p tsconfig.esm.json", | ||
"build": "yarn run clean && tsc --p tsconfig.json", | ||
"buildall": "yarn add [email protected] && yarn build && yarn add [email protected] && yarn build && yarn add [email protected] && yarn build && yarn add [email protected] && yarn build && yarn add [email protected] && yarn build && yarn add [email protected] && yarn build && yarn add typescript@4 && yarn build && yarn add [email protected]", | ||
"buildallv2": "yarn add [email protected] && yarn build && yarn add [email protected] && yarn build && yarn add [email protected] && yarn build && yarn add [email protected] && yarn build && yarn add [email protected] && yarn build && yarn add [email protected]", | ||
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"", | ||
|
@@ -51,4 +50,4 @@ | |
"tslint-config-prettier": "^1.18.0", | ||
"typescript": "4.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.