npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ashu-bhai/common

v1.0.4

Published

zod

Readme

## Zod Wrapper: Streamline Input Validation for Server and Client

Tired of duplicating validation logic between your server and client code? Zod, the foundation of Zod Wrapper, is designed with developer experience in mind. It's a TypeScript-first library that allows you to define data structures, or schemas (encompassing everything from simple strings to intricate nested objects), using intuitive constructs. The key advantage? Automatic Type Inference. Declare a validator once, and Zod infers the corresponding TypeScript type, eliminating tedious type duplication and enhancing code readability. Furthermore, Zod excels at composing simpler types into complex data structures, making it well-suited for even the most demanding validation scenarios.

Key Benefits:

  • Reduced Code Duplication: Define validation schemas once and share them between server and client, maintaining a single source of truth.
  • Improved Maintainability: Easier to update validation rules in a single location, promoting code consistency and reducing the risk of errors.
  • Enhanced Developer Experience: Focus on core application logic, leaving input validation to the dedicated Zod Wrapper package.
  • Type-Safety: Leverage Zod's type-safe validation for better code readability and early error detection.

Installation:

Bash

npm install @ashu-bhai/common

Usage:

1. Define Shared Validation Schemas:

Create a file (e.g., index.ts) to house your Zod schemas accessible from both server and client code:

TypeScript

// validation-schemas.ts
import { z } from "zod";

export const signupInput = z.object({
  username: z.string().nonempty(),
  password: z.string().min(8).strong({
    // Use Zod's built-in strong password complexity checker or define custom rules
  }),
});

export  type  SignupParams  =  z.infer<typeof  signupInput>;

2. Server-Side Validation:

Import the shared schema from validation-schemas and use it to validate server-side input:

TypeScript

// server-side code (e.g., Node.js)
import { signupInput } from "@ashu-bhai/common";

const userData = { username: "ashutosh", password: "********" };

try {
  signupInput.parse(userData);
  console.log("Input validation successful!");
  // Proceed with processing validated data
} catch (error) {
  console.error("Input validation failed:", error.format());
  // Handle validation errors gracefully, e.g., return error response to client
}

3. Client-Side Validation:

Similarly, import the shared schema on the client-side and validate user input before sending it to the server:

TypeScript

// client-side code (e.g., React, Vue.js)
import { signupInput } from "@ashu-bhai/common";

const userData = { username: "ashutoh", password: "********" };

try {
  signupInput.parse(userData);
  console.log("Input validation successful!");
  // Send validated data to server
} catch (error) {
  console.error("Input validation failed:", error.format());
  // Display error messages to the user and prevent invalid submissions
}

Contributing:

We encourage contributions to the Zod Wrapper package! If you encounter issues, have suggestions, or want to implement new features, feel free to:

  • Open an issue on the project's GitHub repository (https://github.com/ashutoshgithubs/package-zod).
  • Submit a pull request with your contributions.

Further Considerations:

  • For complex validation rules, customize Zod's validation functions to match your specific requirements.
  • Consider implementing additional functionality within the Zod Wrapper package for improved error handling, data transformation, or integration with your chosen front-end framework.