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

levity-validator

v0.6.4

Published

Javascript Data Validator

Downloads

6

Readme

levity-validator

Javascript Data Validation Library

Installation and Usage

Server Side

$ npm install levity-validator
import validator from 'levity-validator';

let isValid = validator.isAlphaNum("Test1234");

console.log(isValid); // true

Client Side

Working on it

Documentation

Validators

isAlpha(str [,options])

only letters

options defaults: options={min: 0, max: 10000, locale: 'en-US', case: ''} locale: ['en-US',''] - * for any letters in any language case: ['upper','lower','*'] - * for upper and lower case

isAlphaNum(str [,options])

only letters and numbers

options defaults: options={min: 0, max: 10000, locale: 'en-US', case: ''} locale: ['en-US',''] - * for any letters in any language case: ['upper','lower','*'] - * for upper and lower case

isAlphaNumSpace(str [,options])

only letters and numbers and spaces

options defaults: options={min: 0, max: 10000, locale: 'en-US', case: ''} locale: ['en-US',''] - * for any letters in any language case: ['upper','lower','*'] - * for upper and lower case

isUsername(str [,options])

only letters and numbers [underscores, dots]

options defaults: options={min: 1, max: 15, hasUnderscore: true, hasDot: false} options.hasUnderscore: to allow underscores options.hasDot: to allow dots

isPass(str [,options])

letters + numbers + spaces + !#$%&"'`()*+-,./:;<=>?@[]^_{|}~

options defaults: options={min: 6, max: 255}

isEmail(str)

Matches any Email Max Length: 10000 character

isText(str [,options])

Letters and Numbers from any language + Spaces + Punctuation + Marks (e.g. accents, umlauts, ...)

options defaults: options={min: 0, max: 10000}

isPattern(str, pattern [,options])

true if the str matches the pattern

pattern (string): regular expression (RegExp) options defaults: options={min: 0, max: 10000}

isStringNum(str [,options])

String that only contains numbers from any language

options defaults: options={min: 0, max: 10000}

isNum(num [,options])

Numbers without NaN or -NaN (variables with type numbers not strings that contains numbers) examples: 4,-20,1.5,-2.5

options defaults: options={min: null, max: null}

isInt(num [,options])

Integers examples: 4,-20

options defaults: options={min: null, max: null}

isDefined(data)

check if variable is defined

isString(data)

check if variable is string

isEmptyString(str)

check if string is empty

isOneOf(data, includeArray)

Checks if the data is one of the array values

let isOneOf = validator.isOneOf("Pewdiepie", ['Casey','David','Pewdiepie']);
console.log('isOneOf', isOneOf); // true

isEqualTo(data, value)

just like === operator

let isEqualTo = validator.isEqualTo('David', 'David');
console.log('isEqualTo', isEqualTo); // true

isArray(data, [,options])

Check it data is array and checks it's length

let isArray = validator.isArray([1,2,3], {min: 1, max: 5});
console.log('isArray', isArray); // true

isArrayEvery(array, conditionFunction)

Check if every item in the array meet the condition function

let isArrayEvery = validator.isArrayEvery([1,2,3,4], (item)=>item<5);
console.log('isArrayEvery', isArrayEvery); // true

isArraySome(array, conditionFunction)

Check if any one of the array items meets the condition function

let isArraySome = validator.isArraySome([1,2,3,4], (item)=>item==3);
console.log('isArraySome', isArraySome); // true

checkStringLength(str [, min, max])

check if string is empty

min (int): default: 0 max (int): default: null (for any max length)

Operations

multiple(...validators)

examples:

validator.multiple(validator.isAlphaNum("test123"), validator.isAlpha("test")); // true

validate({})

data: object the object keys contains: {value: dataToVerify, valid: validator [,required: false]}

valid (validator): the validator function value (any): the data to validate params (any): the validator function params (second argument) required (boolean): is the parameter required, default false (optional) convertStrToNum (boolean): if the value is string and can be converted to number then it will convert it, default false (optional)

returns object {status: true|false [,paramName: 'paramName', err: 'err msg']}

examples:

// optional: changing the error messages
validator.errMsgs.isInvalid = '$ Is Wrong !';

let trueValidate = validator.validate({
	firstName: {valid: validator.isAlpha, value: 'David', params: {min: 3}, required: true},
	age: {valid: validator.isInt, value: 25, params: {min: 1, max: 100}}
});
// console.log(trueValidate); // {status: true}

// this one with a parameter that is not required so it can be undefined and still true
let trueValidate2 = validator.validate({
	firstName: {valid: validator.isAlpha, value: 'David', params: {min: 3}, required: true},
	age: {valid: validator.isInt, value: undefined, params: {min: 1, max: 100}}	
});
// console.log('trueValidate2', trueValidate2); // {status: true}

// this one with a parameter age that can be converted form str to number and still true
let trueValidate3 = validator.validate({
	firstName: {valid: validator.isAlpha, value: 'David', params: {min: 3}, required: true},
	age: {valid: validator.isInt, value: '25', params: {min: 1, max: 100}, convertStrToNum: true}
});
// console.log('trueValidate2', trueValidate2); // {status: true}

let falseValidate = validator.validate({
	firstName: {valid: validator.isAlpha, value: 'David4', params: {min: 3}, required: true},
	age: {valid: validator.isInt, value: '25', params: {min: 1, max: 100}, convertStrToNum: true}
});
// console.log('falseValidate', falseValidate); // {status: false, param: 'firstName, err: 'firstName is Wrong !'}