Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zod

Package Overview
Dependencies
Maintainers
2
Versions
364
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zod

TypeScript-first schema declaration and validation library with static type inference

  • 3.21.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11M
decreased by-16.82%
Maintainers
2
Weekly downloads
 
Created

What is zod?

Zod is a TypeScript-first schema declaration and validation library. It allows developers to create complex schemas for data validation with a simple and intuitive API. Zod schemas are composable and can be used to validate data at the edge of your application, ensuring that you're working with well-structured and type-safe data.

What are zod's main functionalities?

Basic Type Validation

Validates that the input is a string.

{"const schema = zod.string(); try { schema.parse('hello world'); } catch (e) { console.error(e); }"}

Object Schema Validation

Validates that the input is an object with specific properties of certain types.

{"const userSchema = zod.object({ name: zod.string(), age: zod.number(), email: zod.string().email() }); try { userSchema.parse({ name: 'John', age: 30, email: 'john@example.com' }); } catch (e) { console.error(e); }"}

Array Validation

Validates that the input is an array of strings.

{"const stringArraySchema = zod.array(zod.string()); try { stringArraySchema.parse(['apple', 'banana']); } catch (e) { console.error(e); }"}

Complex Nested Validation

Validates nested objects with various property types.

{"const nestedSchema = zod.object({ user: zod.object({ name: zod.string(), contact: zod.object({ email: zod.string().email(), phone: zod.string() }) }) }); try { nestedSchema.parse({ user: { name: 'Jane', contact: { email: 'jane@example.com', phone: '123-456-7890' } } }); } catch (e) { console.error(e); }"}

Custom Validation

Validates that a number is positive using custom validation logic.

{"const positiveNumber = zod.number().positive(); try { positiveNumber.parse(42); } catch (e) { console.error(e); }"}

Error Formatting

Formats validation errors for easier debugging and display.

{"const schema = zod.string(); try { schema.parse(42); } catch (e) { console.error(e.format()); }"}

Other packages similar to zod

Keywords

FAQs

Package last updated on 04 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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