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

almant-validation

v1.0.16

Published

is a validation package which helps to validate the fields from the request

Downloads

1,077

Readme

almantZod

This npm package has just been created. In the future, we plan to add more validation rules and features to enhance its functionality. Stay tuned for updates!

almantZod is a lightweight JavaScript validation library inspired by Zod, providing flexible validation rules for strings, integers, email, password and object schemas. Use StringValidator, IntegerValidator, EmailValidator, PasswordValidator and ObjectSchema to perform custom validations on your data, with easy-to-read error messages.

Installation

To install this package, use npm:

npm install almant-validation

API

1. StringValidator

Use string() to apply rules such as minimum/maximum length, regular expression matching, and email format checks to a string.

Methods

  • min(length, error): Validates that the string length is at least length characters.
  • max(length, error): Validates that the string length is at most length characters.
  • trim(): Removes leading and trailing whitespace from the string.
  • validate(value): Runs all applied rules on the string and returns either the validated data if all rules pass or an error if any rule fails.
import almantZod from 'alamnt-validation'

const stringValidator = almantZod.string()
  .min(5, { message: 'Too short!' })
  .max(10, { message: 'Too long!' })
  .trim();

const result = stringValidator.validate(" [email protected] ");
console.log(result); // { valid: true, data: "[email protected]" }

2. IntegerValidator

Use integer() to validate integer values based on minimum, maximum, and positive value constraints.

Methods

  • min(minValue, error): Ensures the integer is greater than or equal to minValue.
  • max(maxValue, error): Ensures the integer is less than or equal to maxValue.
  • positive(error): Ensures the integer is greater than 0.
  • validate(value): Runs all applied rules on the integer and returns either the validated data if all rules pass or an error if any rule fails.
import almantZod from 'alamnt-validation'

const integerValidator = almantZod.integer()
  .min(1, { message: 'Must be at least 1' })
  .positive({ message: 'Must be positive' });

const result = integerValidator.validate(10);
console.log(result); // { valid: true, data: 10 }

3. ObjectSchema

Use object() to validate complex objects based on a schema.

Methods

  • parseData(data): Validates the object against the schema and returns either an object data with success if all rules pass or an error if any rule fails.
import almantZod from 'alamnt-validation'

const userSchema = almantZod.object({
  username: almantZod.string().min(3, { message: 'Username too short' }),
  email: almantZod.string().email({ message: 'Please enter a valid email.'}),
  password: almantZod.string().min(8, { message: 'Password must be at least 8 characters long.' })
 .regex(/[0-9]/, { message: 'Password must contain at least one number.' }),
  age: almantZod.integer().min(18, { message: 'Must be at least 18' }),
});

const result = userSchema.parseData({
  username: "john",
  email: "[email protected]",
  password: "password1",
  age: 20
});

console.log(result); 
// Expected output:
// { success: true, data: { username: "john", email: "[email protected]", password: "password1", age: 20 } }