/zod-examples

Demonstrate Zod Implementation

Primary LanguageTypeScript

Zod Demo

This repository serves as a demonstration for utilizing the Zod library in a TypeScript project. Zod is a powerful TypeScript-first schema declaration and validation library that simplifies handling complex data structures.

Getting Started

Prerequisites

Before you begin, ensure that you have Node.js, npm, and TypeScript installed on your machine.

Quick Start

  1. Clone the repository:
git clone https://github.com/vkpatva/zod-examples
  1. Navigate to the project directory:
cd zod-examples
  1. Install the dependencies:
npm install
  1. Build the TypeScript files:
npm run build

Usage

The main purpose of this demo is to showcase how Zod can be used to validate API data schemas in a TypeScript project. There are three example scripts you can use to explore different scenarios:

  • Start a script using Zod for validation:
npm run start-zod
  • Start a script without using Zod:
npm run start-withoutZod
  • Start another example script without using Zod:
npm run start-example
  • Example script for DataValidation:
npm run DataValidation
  • Example script for coersion:
npm run coersion

Feel free to explore and modify the examples in the TypeScript files (withZod.ts, withoutZod.ts, withoutZod2.ts) to suit your specific use case.

Credits

This project was inspired by Jimmydalecleveland's Zod Introduction Video. You can also check out the original source code on GitHub.