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.0.7 to 1.0.8

lib/types/enum.d.ts

12

lib/index.d.ts

@@ -13,4 +13,6 @@ import { ZodString, ZodStringDef } from './types/string';

import { ZodLazy, ZodLazyDef } from './types/lazy';
import { ZodLiteral, ZodLiteralDef } from './types/literal';
import { ZodEnum, ZodEnumDef } from './types/enum';
import { TypeOf, ZodType, ZodAny } from './types/base';
export declare type ZodDef = ZodStringDef | ZodNumberDef | ZodBooleanDef | ZodUndefinedDef | ZodNullDef | ZodArrayDef | ZodObjectDef | ZodUnionDef | ZodIntersectionDef | ZodTupleDef | ZodFunctionDef | ZodLazyDef;
export declare type ZodDef = ZodStringDef | ZodNumberDef | ZodBooleanDef | ZodUndefinedDef | ZodNullDef | ZodArrayDef | ZodObjectDef | ZodUnionDef | ZodIntersectionDef | ZodTupleDef | ZodFunctionDef | ZodLazyDef | ZodLiteralDef | ZodEnumDef;
declare const stringType: () => ZodString;

@@ -28,7 +30,9 @@ declare const numberType: () => ZodNumber;

declare const lazyType: <T extends ZodAny>(getter: () => T) => ZodLazy<T>;
declare const literalType: <T extends string | number | boolean>(value: T) => ZodLiteral<T>;
declare const enumType: <T extends [ZodLiteral<string>, ...ZodLiteral<string>[]]>(values: T) => ZodEnum<T>;
declare const ostring: () => ZodUnion<[ZodString, ZodUndefined]>;
declare const onumber: () => ZodUnion<[ZodNumber, ZodUndefined]>;
declare const oboolean: () => ZodUnion<[ZodBoolean, ZodUndefined]>;
export { stringType as string, numberType as number, booleanType as boolean, undefinedType as undefined, nullType, arrayType as array, objectType as object, unionType as union, intersectionType as intersection, tupleType as tuple, functionType, lazyType as lazy, ostring, onumber, oboolean, };
export { ZodString, ZodNumber, ZodBoolean, ZodUndefined, ZodNull, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodFunction, ZodLazy, ZodType, ZodAny, };
export { TypeOf };
export { stringType as string, numberType as number, booleanType as boolean, undefinedType as undefined, nullType as null, arrayType as array, objectType as object, unionType as union, intersectionType as intersection, tupleType as tuple, functionType as function, lazyType as lazy, literalType as literal, enumType as enum, ostring, onumber, oboolean, };
export { ZodString, ZodNumber, ZodBoolean, ZodUndefined, ZodNull, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodType, ZodAny, };
export { TypeOf, TypeOf as Infer };

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

exports.ZodLazy = lazy_1.ZodLazy;
var literal_1 = require("./types/literal");
exports.ZodLiteral = literal_1.ZodLiteral;
var enum_1 = require("./types/enum");
exports.ZodEnum = enum_1.ZodEnum;
var base_1 = require("./types/base");

@@ -40,3 +44,3 @@ exports.ZodType = base_1.ZodType;

var nullType = null_1.ZodNull.create;
exports.nullType = nullType;
exports.null = nullType;
var arrayType = array_1.ZodArray.create;

@@ -53,5 +57,9 @@ exports.array = arrayType;

var functionType = function_1.ZodFunction.create;
exports.functionType = functionType;
exports.function = functionType;
var lazyType = lazy_1.ZodLazy.create;
exports.lazy = lazyType;
var literalType = literal_1.ZodLiteral.create;
exports.literal = literalType;
var enumType = enum_1.ZodEnum.create;
exports.enum = enumType;
var ostring = function () { return stringType().optional(); };

@@ -58,0 +66,0 @@ exports.ostring = ostring;

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

var z = __importStar(require("./types/base"));
function assertNever(x) {
throw new Error('Unexpected object: ' + x);
}
exports.ZodParser = function (schemaDef) { return function (obj) {

@@ -126,6 +129,22 @@ var def = schemaDef;

return obj;
case z.ZodTypes.literal:
if (obj === def.value)
return obj;
throw new Error(obj + " !== Literal<" + def.value + ">");
case z.ZodTypes.enum:
for (var _b = 0, _c = def.values; _b < _c.length; _b++) {
var literalDef = _c[_b];
try {
literalDef.parse(obj);
return obj;
}
catch (err) { }
}
throw new Error("\"" + obj + "\" does not match any value in enum");
case z.ZodTypes.function:
return obj;
default:
throw new Error("Invalid schema type: " + def.t);
assertNever(def);
}
}; };
//# sourceMappingURL=parser.js.map
"use strict";
// import * as z from '.';
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 MyEnum = z.enum([z.literal('Hello'), z.literal('There'), z.literal('Bobby')]);
MyEnum.parse('Bobby');
//# sourceMappingURL=playground.js.map

@@ -14,3 +14,5 @@ import { ZodTuple } from './tuple';

function = "function",
lazy = "lazy"
lazy = "lazy",
literal = "literal",
enum = "enum"
}

@@ -17,0 +19,0 @@ export declare type ZodRawShape = {

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

ZodTypes["lazy"] = "lazy";
ZodTypes["literal"] = "literal";
ZodTypes["enum"] = "enum";
})(ZodTypes = exports.ZodTypes || (exports.ZodTypes = {}));

@@ -25,3 +27,3 @@ // interface Assertable<T> {

var ZodType = /** @class */ (function () {
// assert(u: unknown): asserts u is Type {
// assert: (u: unknown) => asserts u is Type = u => {
// try {

@@ -32,3 +34,3 @@ // this.parse(u);

// }
// }
// };
function ZodType(def) {

@@ -35,0 +37,0 @@ this.parse = parser_1.ZodParser(def);

{
"name": "zod",
"version": "1.0.7",
"version": "1.0.8",
"description": "Typescript-first schema declaration and validation library with static type inference",

@@ -50,3 +50,3 @@ "main": "./lib/index.js",

"prepare": "npm run build",
"play": "nodemon -e ts -w . -x ts-node playground.ts"
"play": "nodemon -e ts -w . -x ts-node src/playground.ts"
},

@@ -53,0 +53,0 @@ "devDependencies": {

@@ -0,1 +1,5 @@

# Zod
<img src="logo.svg" alt="logo" width="200"/>
### Table of contents

@@ -197,3 +201,3 @@

const neverType = z.intersection(z.string(), z.number());
const stringAndNumber = z.intersection(z.string(), z.number());
type Never = z.TypeOf<typeof stringAndNumber>; // => never

@@ -311,3 +315,3 @@ ```

This lets you confidently This way you can confidently execute business logic in a "validated function" without worrying about invalid inputs or return types, mixing your validation and business logic, or writing duplicative types for your functions.
This way you can confidently execute business logic in a "validated function" without worrying about invalid inputs or return types, mixing your validation and business logic, or writing duplicative types for your functions.

@@ -314,0 +318,0 @@ Here's an example.

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