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

gm-validate

v1.0.9

Published

gm-validate simple library to validate data

Readme

gm-validator

A simple library to validate Data.

Easy to use just a few steps

Easy to custom error message

Esay install and use

Install

Install the library with npm install gm-validate

Use

import gm from "gm-validate";

In this version will use " new " keyword

Create required validation schema for validate input data

import gm, { schema, useValidate } from "gm-validate";

const form = schema({
    name: new gm()
        .required()
        .type("string")
        .min(3)
        .pattern(/^[a-zA-Z]+$/)
        .collect(),
    age: new gm()
        .required()
        .type("number")
        .pattern(/^[0-9]+$/)
        .min(18)
        .max(60)
        .collect(),
    email: new gm().required().isEmail().collect(),
    password: new gm().required().min(6).trim().collect(),
});
// collect method in end of the chain to collect required data .

Create required validation schema with custom message and some options

Exsample for signup form

import gm, { useValidate, schema } from "gm-validate";
// schema
const regex = /^[a-zA-Z]+$/g;
const signupValdite = schema({
    first_name: new gm()
        // Message if field is required
        .required("Please fill input First Name")
        // choose field type
        .type("string")
        // minimum field length is 3 with custom message
        .min(3, "First name must be 3 character or more")
        // regular expression to custom the input pattern
        .pattern(/^[a-zA-Z]+$/g, "Numbers and symbols not support in input field")
        .collect(),
    last_name: new gm()
        .required("Please fill input Last Name")
        .pattern(regex, "Numbers and symbol not support in input field")
        .type("string")
        .min(3)
        .collect(),
    age: new gm().required("Please fill input Age").type("number").min(18, "Age must be +18").collect(),
    email: new gm()
        .required("Please fill input Email")
        // Support email domain
        .isEmail("please provide a valid email", ["@gmail.com", "@gmail.io", "@hotmail.com"])
        // Chech if field has space, you can write error message
        .trim()
        .collect(),
    password: new gm().required("Please fill input Password").min(6).trim().collect(),
    // use match method to check if current field like password field
    confirm_password: new gm().match("password", "Password not match").collect(),
});

// Signup Form
const form = {
    first_name: "mohamed",
    last_name: "ali",
    age: 30,
    email: "[email protected]",
    password: "123456",
    confirm_password: "123456",
};

// Validate and return error
const signupError = useValidate(signupValdite, form);

Exsample for validate image file before upload, note "example from react project"

import gm, { useValidate, schema } from "gm-validate";
// schema
const imageValidate = schema({
        avatar: new gm()
            .required("Please select image first!")
            .isFile({ maxSize: 5154521, extension: ["png"] })
            .collect(),
    });

/*
    maxSize : number | string    default:0
    can use like :
    maxSize : 512545521
    maxSize : "500BYTES"
    maxSize : "300KB"
    maxSize : "5MB"
    maxSize : "1GB"
    maxSize : "1TB"

    write it with lowercase or uppercase -> 10kb  or 10KB

    ----------------------
    extension : array | undefined   default:undefined
    can use like :
    extension :["png", "jpge",more...]
*/
    // Some reactjs code
    const [avatar, setAvatar] = useState<FileList | null | undefined | any>();
    const file = useRef<HTMLInputElement>(null);


// Validate and return error
const imageError = useValidate(imageValidate, { avatar });

const changeAvatar = () => {
        const form = new FormData();

        if (!imageError) {
            form.append("avatar", avatar[0]);

            // Code to dispatch avatar to server....
        }
    };

Exsample Color validate using isColor method

import gm, { useValidate, schema } from "gm-validate";
// schema
const formSchema = schema({
    color: new gm().required("color is required").isColor("Please provid a valid color").collect(),
});

// form
const form = {
    color: "green",
};

/*
color : string
can use like :
color:"red"
color:"#f00"
color:"#f00f00"
color:"#f00f0005"
*/

const formError = useValidate(formSchema, form);

Method

  • schema(input : {})

  • useValidate(gmSchema : {}, input : {})

  • required(message : string)

  • type(type : string, message : string)

  • min(number : number, message : string)

  • max(number : number, message : string)

  • isEmail(message : string , support : [])

  • trim(message : string )

  • pattern(pattern : RegExp , message : string)

  • match(field : string , message : string)

  • isColor(message : string)

  • isFile(options{extension : [] , maxSize : number | string})

  • collect( )