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.11.3 to 1.11.4

2

lib/src/parser.js

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

var makeError = function (errorData) {
var errorArg = __assign({}, errorData, { path: params.path });
var errorArg = __assign({}, errorData, { path: params.path.concat((errorData.path || [])) });
var ctxArg = { data: obj };

@@ -141,0 +141,0 @@ var defaultError = defaultErrorMap_1.defaultErrorMap === params.errorMap

@@ -11,24 +11,18 @@ "use strict";

var z = __importStar(require("."));
var rawServiceSchema = z.object({
// configPath: z.string(),
port: z.number().positive(),
var schema = z.object({
items: z.array(z.string()).refine(function (data) { return data.length > 3; }, {
path: ['items-too-few'],
}),
});
var rawNcdcConfigSchema = z.record(rawServiceSchema);
var rawDataToParse = {
Config1: {
// configPath: './my-file.yml',
port: 5001,
},
Config2: {
// configPath: './my-file.yml',
port: 5002,
},
// this one is missing a port so I expect a validation error to be thrown
'Another Config': {
// configPath: './my-file.yml',
// realApi: 'http://example.com',
},
var customErrorMap = function (error, ctx) {
// console.log(`code: ${error.code}`);
// console.log('message:', error.message);
// console.log('path:', error.path);
console.log(JSON.stringify(error, null, 2));
console.log('data:', data);
return { message: error.message || ctx.defaultError };
};
var parsed = rawNcdcConfigSchema.safeParse(rawDataToParse);
var data = { items: ['first'] };
var parsed = schema.safeParse(data, { errorMap: customErrorMap });
console.log(JSON.stringify(parsed, null, 2));
//# sourceMappingURL=playground.js.map
{
"name": "zod",
"version": "1.11.3",
"version": "1.11.4",
"description": "TypeScript-first schema declaration and validation library with static type inference",

@@ -59,2 +59,2 @@ "main": "./lib/src/index.js",

}
}
}

@@ -315,6 +315,7 @@ <p align="center">

```ts
z.object({
password: z.string(),
confirm: z.string(),
})
const passwordForm = z
.object({
password: z.string(),
confirm: z.string(),
})
.refine(data => data.password === data.confirm, {

@@ -341,2 +342,25 @@ message: "Passwords don't match",

Important note, the value passed to the `path` option is _concatenated_ to the actual error path. So if you took `passwordForm` from above and nested it inside another object, you would still get the error path you expect.
```ts
const allForms = z.object({ passwordForm }).parse({
passwordForm: {
password: 'asdf',
confirm: 'qwer',
},
});
```
would result in
```
ZodError {
errors: [{
"code": "custom_error",
"path": [ "passwordForm", "confirm" ],
"message": "Invalid input."
}]
}
```
## Type inference

@@ -343,0 +367,0 @@

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