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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bharatsharma19/user-input-parser

v3.0.0

Published

A package for parsing user input

Downloads

4

Readme

@bharatsharma19/user-input-parser

A lightweight package for parsing and validating user input with Zod, providing schemas for common user-related operations like sign-up, sign-in, user updates, and deletion.

Features

  • Sign-up Input Validation: Ensure that user registration data is valid.
  • Sign-in Input Validation: Validate credentials for login attempts.
  • Update User Input Validation: Manage optional updates to user profiles.
  • Delete User Input Validation: Verify user IDs for deletion requests.

Installation

Install the package via npm:

npm install @bharatsharma19/user-input-parser --registry=https://npm.pkg.github.com/

Usage

Import the necessary schemas and use them to validate incoming data in your application.

Sign-up Input Validation

import { signUpInput, SignUpType } from "@bharatsharma19/user-input-parser";

const userData = {
  email: "[email protected]",
  password: "password123",
  username: "testuser",
  name: "Test User",
  contact: "1234567890",
};

// Validate input
const result = signUpInput.safeParse(userData);

if (!result.success) {
  console.log(result.error); // Handle validation errors
} else {
  const validatedData: SignUpType = result.data;
  console.log("Valid user data:", validatedData);
}

Sign-in Input Validation

import { signInInput, SignInType } from "@bharatsharma19/user-input-parser";

const credentials = {
  email: "[email protected]",
  password: "password123",
};

const result = signInInput.safeParse(credentials);

if (!result.success) {
  console.log(result.error); // Handle validation errors
} else {
  const validatedData: SignInType = result.data;
  console.log("Valid credentials:", validatedData);
}

Update User Input Validation

import {
  updateUserInput,
  UpdateUserType,
} from "@bharatsharma19/user-input-parser";

const updateData = {
  userId: "550e8400-e29b-41d4-a716-446655440000",
  username: "newusername",
};

const result = updateUserInput.safeParse(updateData);

if (!result.success) {
  console.log(result.error); // Handle validation errors
} else {
  const validatedData: UpdateUserType = result.data;
  console.log("Valid update data:", validatedData);
}

Delete User Input Validation

import {
  deleteUserType,
  DeleteUserType,
} from "@bharatsharma19/user-input-parser";

const deleteData = {
  userId: "550e8400-e29b-41d4-a716-446655440000",
};

const result = deleteUserType.safeParse(deleteData);

if (!result.success) {
  console.log(result.error); // Handle validation errors
} else {
  const validatedData: DeleteUserType = result.data;
  console.log("Valid delete data:", validatedData);
}

Schemas

The following schemas are included in the package:

  • signUpInput: Validates sign-up data (email, password, username, name, contact).
  • signInInput: Validates sign-in data (email, password).
  • updateUserInput: Validates update data (userId, password, username, name, contact).
  • deleteUserType: Validates delete requests (userId).

Types

The following TypeScript types are inferred from the schemas:

  • SignUpType
  • SignInType
  • UpdateUserType
  • DeleteUserType