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.9.1 to 1.9.2

7

lib/src/defaultErrorMap.js

@@ -9,3 +9,8 @@ "use strict";

case ZodError_1.ZodErrorCode.invalid_type:
message = "Invalid input: expected " + error.expected + ", received " + error.received;
if (error.received === 'undefined') {
message = 'Required';
}
else {
message = "Expected " + error.expected + ", received " + error.received;
}
break;

@@ -12,0 +17,0 @@ case ZodError_1.ZodErrorCode.nonempty_array_is_empty:

84

lib/src/playground.js
"use strict";
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 FormData = z
.object({
email: z.string().email(),
password: z.string().min(10),
confirm: z.string().min(10),
})
.refine(function (obj) { return obj.password === obj.confirm; }, {
message: 'Passwords do not match',
path: ['confirm'],
});
try {
FormData.parse({
email: 'not an email',
password: 'tooshort',
confirm: 'nomatch',
});
}
catch (err) {
if (!(err instanceof z.ZodError))
throw err;
console.log(err.errors);
/*
[
{ code: 'invalid_string', validation: 'email', path: ['email'], message: 'Invalid email' },
{
code: 'too_small',
minimum: 10,
type: 'string',
inclusive: true,
path: ['password'],
message: 'Should be at least 10 characters',
},
{
code: 'too_small',
minimum: 10,
type: 'string',
inclusive: true,
path: ['confirm'],
message: 'Should be at least 10 characters',
},
{ code: 'custom_error', message: 'Passwords do not match', path: ['confirm'] },
];
*/
console.log(err.formErrors);
/*
{
formErrors: [],
fieldErrors: {
email: ['Invalid email'],
password: ['Should be at least 10 characters'],
confirm: ['Should be at least 10 characters', 'Passwords do not match'],
},
}
*/
}
// 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 };
// };
//# sourceMappingURL=playground.js.map
{
"name": "zod",
"version": "1.9.1",
"version": "1.9.2",
"description": "TypeScript-first schema declaration and validation library with static type inference",

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

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