Comparing version 3.0.0-alpha.11 to 3.0.0-alpha.12
{ | ||
"name": "zod", | ||
"version": "3.0.0-alpha.11", | ||
"version": "3.0.0-alpha.12", | ||
"description": "TypeScript-first schema declaration and validation library with static type inference", | ||
"main": "./lib/cjs/index.js", | ||
"types": "./lib/cjs/index.d.ts", | ||
"module": "./lib/esm/index.js", | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"module": "dist/zod.esm.js", | ||
"exports": { | ||
"require": "./lib/cjs/index.js", | ||
"import": "./lib/esm/index.js" | ||
"require": "./dist/index.js", | ||
"import": "./dist/zod.esm.js" | ||
}, | ||
"files": [ | ||
"/lib" | ||
], | ||
"repository": { | ||
@@ -40,53 +36,39 @@ "type": "git", | ||
], | ||
"scripts": { | ||
"check:format": "prettier --check \"src/**/*.ts\" \"deno/lib/**/*.ts\"", | ||
"fix:format": "prettier --write \"src/**/*.ts\" \"deno/lib/**/*.ts\"", | ||
"check:lint": "eslint --ext .ts ./src", | ||
"fix:lint": "eslint --fix --ext .ts ./src", | ||
"check": "yarn check:lint && yarn check:format", | ||
"fix": "yarn fix:lint && yarn fix:format", | ||
"clean": "rm -rf lib/* deno/lib/*", | ||
"build": "yarn run clean && npm run build:cjs && npm run build:esm && npm run build:deno", | ||
"build:deno": "node ./deno/build.mjs", | ||
"build:esm": "tsc --p tsconfig.esm.json", | ||
"build:cjs": "tsc --p tsconfig.cjs.json", | ||
"test": "node --trace-warnings node_modules/.bin/jest --coverage && yarn run badge", | ||
"testone": "jest", | ||
"badge": "make-coverage-badge --output-path ./coverage.svg", | ||
"prepublishOnly": "npm run build && npm run build:deno", | ||
"play": "nodemon -e ts -w . -x ts-node src/playground.ts --project tsconfig.json --trace-warnings", | ||
"depcruise": "depcruise -c .dependency-cruiser.js src" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^26.0.17", | ||
"@types/node": "^14.14.10", | ||
"@typescript-eslint/eslint-plugin": "^4.11.1", | ||
"@typescript-eslint/parser": "^4.11.1", | ||
"dependency-cruiser": "^9.19.0", | ||
"eslint": "^7.15.0", | ||
"eslint-config-prettier": "^7.1.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-simple-import-sort": "^7.0.0", | ||
"eslint-plugin-unused-imports": "^1.1.0", | ||
"husky": "^4.3.4", | ||
"jest": "^26.6.3", | ||
"lint-staged": "^10.5.3", | ||
"make-coverage-badge": "^1.2.0", | ||
"nodemon": "^2.0.2", | ||
"prettier": "^2.2.1", | ||
"ts-jest": "^26.4.4", | ||
"ts-node": "^9.1.0", | ||
"tsdx": "^0.14.1", | ||
"tslib": "^2.1.0", | ||
"typescript": "4.1" | ||
}, | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"engines": { | ||
"node": ">=10" | ||
}, | ||
"scripts": { | ||
"start": "tsdx watch", | ||
"build": "npm run build:pkg && npm run build:deno", | ||
"build:pkg": "tsdx build", | ||
"build:deno": "rm -rf deno/lib/* && node ./deno/build.mjs", | ||
"test": "tsdx test", | ||
"lint": "tsdx lint", | ||
"prepare": "tsdx build", | ||
"play": "nodemon -e ts -w . -x ts-node src/playground.ts --project tsconfig.json" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "yarn build:deno && lint-staged" | ||
"pre-commit": "tsdx lint --fix && yarn build:deno" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.ts": [ | ||
"yarn fix:lint", | ||
"yarn fix:format" | ||
] | ||
"prettier": { | ||
"printWidth": 80, | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
} | ||
} |
126
README.md
@@ -111,6 +111,6 @@ <p align="center"> | ||
.transform((val) => val.length) | ||
.refine((val) => val > 5, { message: "Input is too short" }) | ||
.refine((val) => val > 5, { message: 'Input is too short' }) | ||
.transform((val) => val * 2); | ||
test.parse("12characters"); // => 24 | ||
test.parse('12characters'); // => 24 | ||
``` | ||
@@ -225,7 +225,7 @@ | ||
```ts | ||
import { z } from "zod"; | ||
import { z } from 'zod'; | ||
// creating a schema for strings | ||
const mySchema = z.string(); | ||
mySchema.parse("tuna"); // => "tuna" | ||
mySchema.parse('tuna'); // => "tuna" | ||
mySchema.parse(12); // => throws ZodError | ||
@@ -237,3 +237,3 @@ ``` | ||
```ts | ||
import { z } from "zod"; | ||
import { z } from 'zod'; | ||
@@ -256,3 +256,3 @@ const User = z.object({ | ||
```ts | ||
import { z } from "zod"; | ||
import { z } from 'zod'; | ||
@@ -284,3 +284,3 @@ // primitive values | ||
```ts | ||
const tuna = z.literal("tuna"); | ||
const tuna = z.literal('tuna'); | ||
const twelve = z.literal(12); | ||
@@ -316,8 +316,8 @@ const tru = z.literal(true); | ||
```ts | ||
z.string().min(5, { message: "Must be 5 or more characters long" }); | ||
z.string().max(5, { message: "Must be 5 or fewer characters long" }); | ||
z.string().length(5, { message: "Must be exactly 5 characters long" }); | ||
z.string().email({ message: "Invalid email address." }); | ||
z.string().url({ message: "Invalid url" }); | ||
z.string().uuid({ message: "Invalid UUID" }); | ||
z.string().min(5, { message: 'Must be 5 or more characters long' }); | ||
z.string().max(5, { message: 'Must be 5 or fewer characters long' }); | ||
z.string().length(5, { message: 'Must be exactly 5 characters long' }); | ||
z.string().email({ message: 'Invalid email address.' }); | ||
z.string().url({ message: 'Invalid url' }); | ||
z.string().uuid({ message: 'Invalid UUID' }); | ||
``` | ||
@@ -344,3 +344,3 @@ | ||
```ts | ||
z.number().max(5, { message: "this👏is👏too👏big" }); | ||
z.number().max(5, { message: 'this👏is👏too👏big' }); | ||
``` | ||
@@ -498,3 +498,3 @@ | ||
person.parse({ | ||
name: "bob dylan", | ||
name: 'bob dylan', | ||
extraKey: 61, | ||
@@ -512,3 +512,3 @@ }); | ||
person.passthrough().parse({ | ||
name: "bob dylan", | ||
name: 'bob dylan', | ||
extraKey: 61, | ||
@@ -531,3 +531,3 @@ }); | ||
person.parse({ | ||
name: "bob dylan", | ||
name: 'bob dylan', | ||
extraKey: 61, | ||
@@ -554,3 +554,3 @@ }); | ||
person.parse({ | ||
name: "bob dylan", | ||
name: 'bob dylan', | ||
validExtraKey: 61, // works fine | ||
@@ -560,3 +560,3 @@ }); | ||
person.parse({ | ||
name: "bob dylan", | ||
name: 'bob dylan', | ||
validExtraKey: false, // fails | ||
@@ -595,3 +595,3 @@ }); | ||
nonEmptyStrings.parse([]); // throws: "Array cannot be empty" | ||
nonEmptyStrings.parse(["Ariana Grande"]); // passes | ||
nonEmptyStrings.parse(['Ariana Grande']); // passes | ||
``` | ||
@@ -616,3 +616,3 @@ | ||
stringOrNumber.parse("foo"); // passes | ||
stringOrNumber.parse('foo'); // passes | ||
stringOrNumber.parse(14); // passes | ||
@@ -663,3 +663,3 @@ ``` | ||
const nullableString = z.nullable(z.string()); | ||
nullableString.parse("asdf"); // => "asdf" | ||
nullableString.parse('asdf'); // => "asdf" | ||
nullableString.parse(null); // => null | ||
@@ -721,8 +721,8 @@ ``` | ||
userStore["77d2586b-9e8e-4ecf-8b21-ea7e0530eadd"] = { | ||
name: "Carlotta", | ||
userStore['77d2586b-9e8e-4ecf-8b21-ea7e0530eadd'] = { | ||
name: 'Carlotta', | ||
}; // passes | ||
userStore["77d2586b-9e8e-4ecf-8b21-ea7e0530eadd"] = { | ||
whatever: "Ice cream sundae", | ||
userStore['77d2586b-9e8e-4ecf-8b21-ea7e0530eadd'] = { | ||
whatever: 'Ice cream sundae', | ||
}; // TypeError | ||
@@ -739,3 +739,3 @@ ``` | ||
const testMap: { [k: number]: string } = { | ||
1: "one", | ||
1: 'one', | ||
}; | ||
@@ -792,3 +792,3 @@ | ||
```ts | ||
const FishEnum = z.enum(["Salmon", "Tuna", "Trout"]); | ||
const FishEnum = z.enum(['Salmon', 'Tuna', 'Trout']); | ||
type FishEnum = z.infer<typeof FishEnum>; | ||
@@ -801,3 +801,3 @@ // 'Salmon' | 'Tuna' | 'Trout' | ||
```ts | ||
const fish = ["Salmon", "Tuna", "Trout"]; | ||
const fish = ['Salmon', 'Tuna', 'Trout']; | ||
const FishEnum = z.enum(fish); | ||
@@ -857,4 +857,4 @@ ``` | ||
enum Fruits { | ||
Apple = "apple", | ||
Banana = "banana", | ||
Apple = 'apple', | ||
Banana = 'banana', | ||
Cantaloupe, // you can mix numerical and string enums | ||
@@ -868,6 +868,6 @@ } | ||
FruitEnum.parse(Fruits.Cantaloupe); // passes | ||
FruitEnum.parse("apple"); // passes | ||
FruitEnum.parse("banana"); // passes | ||
FruitEnum.parse('apple'); // passes | ||
FruitEnum.parse('banana'); // passes | ||
FruitEnum.parse(0); // passes | ||
FruitEnum.parse("Cantaloupe"); // fails | ||
FruitEnum.parse('Cantaloupe'); // fails | ||
``` | ||
@@ -881,4 +881,4 @@ | ||
const Fruits = { | ||
Apple: "apple", | ||
Banana: "banana", | ||
Apple: 'apple', | ||
Banana: 'banana', | ||
Cantaloupe: 3, | ||
@@ -890,6 +890,6 @@ } as const; | ||
FruitEnum.parse("apple"); // passes | ||
FruitEnum.parse("banana"); // passes | ||
FruitEnum.parse('apple'); // passes | ||
FruitEnum.parse('banana'); // passes | ||
FruitEnum.parse(3); // passes | ||
FruitEnum.parse("Cantaloupe"); // fails | ||
FruitEnum.parse('Cantaloupe'); // fails | ||
``` | ||
@@ -933,7 +933,7 @@ | ||
Category.parse({ | ||
name: "People", | ||
name: 'People', | ||
subcategories: [ | ||
{ | ||
name: "Politicians", | ||
subcategories: [{ name: "Presidents", subcategories: [] }], | ||
name: 'Politicians', | ||
subcategories: [{ name: 'Presidents', subcategories: [] }], | ||
}, | ||
@@ -1003,10 +1003,10 @@ ], | ||
```ts | ||
numberPromise.parse("tuna"); | ||
numberPromise.parse('tuna'); | ||
// ZodError: Non-Promise type: string | ||
numberPromise.parse(Promise.resolve("tuna")); | ||
numberPromise.parse(Promise.resolve('tuna')); | ||
// => Promise<number> | ||
const test = async () => { | ||
await numberPromise.parse(Promise.resolve("tuna")); | ||
await numberPromise.parse(Promise.resolve('tuna')); | ||
// ZodError: Non-number type: string | ||
@@ -1034,5 +1034,5 @@ | ||
const blob: any = "whatever"; | ||
const blob: any = 'whatever'; | ||
TestSchema.parse(new Test()); // passes | ||
TestSchema.parse("blob"); // throws | ||
TestSchema.parse('blob'); // throws | ||
``` | ||
@@ -1095,4 +1095,4 @@ | ||
trimmedLength("sandwich"); // => 8 | ||
trimmedLength(" asdf "); // => 4 | ||
trimmedLength('sandwich'); // => 8 | ||
trimmedLength(' asdf '); // => 4 | ||
``` | ||
@@ -1126,3 +1126,3 @@ | ||
const stringSchema = z.string(); | ||
stringSchema.parse("fish"); // => returns "fish" | ||
stringSchema.parse('fish'); // => returns "fish" | ||
stringSchema.parse(12); // throws Error('Non-string type: number'); | ||
@@ -1139,3 +1139,3 @@ ``` | ||
const stringSchema = z.string().refine(async (val) => val.length > 20); | ||
const value = await stringSchema.parseAsync("hello"); // => hello | ||
const value = await stringSchema.parseAsync('hello'); // => hello | ||
``` | ||
@@ -1153,3 +1153,3 @@ | ||
stringSchema.safeParse("billie"); | ||
stringSchema.safeParse('billie'); | ||
// => { success: true; data: 'billie' } | ||
@@ -1161,3 +1161,3 @@ ``` | ||
```ts | ||
const result = stringSchema.safeParse("billie"); | ||
const result = stringSchema.safeParse('billie'); | ||
if (!result.success) { | ||
@@ -1177,3 +1177,3 @@ // handle error then return | ||
```ts | ||
await stringSchema.safeParseAsync("billie"); | ||
await stringSchema.safeParseAsync('billie'); | ||
``` | ||
@@ -1184,3 +1184,3 @@ | ||
```ts | ||
await stringSchema.spa("billie"); | ||
await stringSchema.spa('billie'); | ||
``` | ||
@@ -1246,5 +1246,5 @@ | ||
message: "Passwords don't match", | ||
path: ["confirm"], // path of error | ||
path: ['confirm'], // path of error | ||
}) | ||
.parse({ password: "asdf", confirm: "qwer" }); | ||
.parse({ password: 'asdf', confirm: 'qwer' }); | ||
``` | ||
@@ -1318,3 +1318,3 @@ | ||
const stringToNumber = z.string().transform((val) => myString.length); | ||
stringToNumber.parse("string"); // => 6 | ||
stringToNumber.parse('string'); // => 6 | ||
``` | ||
@@ -1332,5 +1332,5 @@ | ||
.email() | ||
.transform((val) => val.split("@")[1]); | ||
.transform((val) => val.split('@')[1]); | ||
emailToDomain.parse("colinhacks@example.com"); // => example.com | ||
emailToDomain.parse('colinhacks@example.com'); // => example.com | ||
``` | ||
@@ -1369,3 +1369,3 @@ | ||
```ts | ||
const stringWithDefault = z.string().default("tuna"); | ||
const stringWithDefault = z.string().default('tuna'); | ||
@@ -1394,3 +1394,3 @@ stringWithDefault.parse(undefined); // => "tuna" | ||
const u: A = 12; // TypeError | ||
const u: A = "asdf"; // compiles | ||
const u: A = 'asdf'; // compiles | ||
``` | ||
@@ -1536,3 +1536,3 @@ | ||
```ts | ||
import * as t from "io-ts"; | ||
import * as t from 'io-ts'; | ||
@@ -1539,0 +1539,0 @@ const A = t.type({ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
1069477
7
11161
34
1
1
No