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

easy-validation-js

v1.3.4

Published

javascript validation library

Downloads

13

Readme

Easy validation js

This is validation library for Javascript . You can use this library server side and front end side.

Badges

Add badges from somewhere like: shields.io

MIT License GPLv3 License AGPL License

Installation

Install easy-validation-js with npm

  npm install easy-validation-js

Features

  • Validate string
  • Validate number
  • Validate boolean
  • Validate array
  • Validate object

Usage/Examples

String and number

const { Easy } = require('easy-validation-js'); // CommonJS
import { Easy } from 'easy-validation-js'; // ESM
// for string data
const str1 = 'hello world';
const str2 = 20;
const myStr = Easy.isString(str2, {
  isRequire: true,
  message: 'string required',
  error: true, // when you enable the error you crashed server;
});
console.log(myStr); // return string required

// for number data
const num1 = 10;
const num2 = 'hello world';

const myNum = Easy.isNumber(num2, {
  isRequire: true,
  message: 'number value required',
});
console.log(myNumber);

Object use cases

const { Obj } = require('easy-validation-js'); // CommonJS
import { Obj } from 'easy-validation-js'; // ESM

const myObj = { data: 'hello world', status: '200' };
// check is object
const isObj = Obj.isObj(myObj, { isRequire: true, message: 'obj required' });

// check object key
isObj.key('data status');

// check object length
isObj.len(2);

// check this key must exist in object
const result = Obj.obj(myObj).keySome('status');
console.log(result); // return true

const result2 = Obj.obj(myObj).keySome('name');
console.log(result2); //return key same required

const result3 = Obj.obj(myObj).keySome('name', {
  message: 'need same key',
  isRequire: true,
  error: false,
});
console.log(result3); //return need same key

// check value type when all of value same type
const myObj = { data: 'hello world', status: 200 };
const result = Obj.obj(myObj).valType('string'); // you can also pass option
console.log(result); // return string type required

// check object with defining schema like this
const myObj = { data: 'hello world', status: 200, isOk: true };
const sch = { data: 'string', status: 'number' };
const result = Obj.obj(myObj).schema(sch); // return true

const sch2 = { data: 'string', status: 'string' };
const result2 = Obj.obj(myObj).schema(sch2); // return type required

// note: schema method don't check additional key type . if you need strictly check you can use schemaStrict method.
const result3 = Obj.obj(myObj).schemaStrict(sch2); //return type required

License

MIT

Contributing

Contributions are always welcome!

See contributing.md for ways to get started.

Please adhere to this project's code of conduct.