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

verifierjs

v0.5.2

Published

functions for validation

Downloads

82

Readme

Verifier

A tiny js library for Form validation.

Node Version License Min Size codecov build semantic-release code style: prettier

Installation

npm install verifierjs --save
yarn add verifierjs

Import

import { Verifier, anyone } from 'verifierjs';
// CommonJS
const {Verifier, anyone} = require('verifierjs');
<!-- Vanilla JS -->
<!-- Minified Version-->
<script src="https://unpkg.com/verifierjs"></script>
<!-- UnMinified Version-->
<script src="https://unpkg.com/verifierjs/dist/index.umd.js"></script>
<script>
	const { Verifier, anyone } = verifierjs;
</script>

Note

Color conversion functions are transferred to color-converter

Usage

// isUsername
new Verifier('username').isUsername().correct// returns true
new Verifier('$username').isUsername().correct// returns false
new Verifier('username').isUsername(/\w{4,}/).correct// returns true
new Verifier('username').isUsername({length: /\w{4,}/}).details// returns {lenght:true}

// isPassword
new Verifier('secret').isPassword().correct // returns false
new Verifier('secreT@123').isPassword().correct // returns true
new Verifier('secret').isPassword(/.{1,}/).correct // returns true
new Verifier('secret').isPassword({length: /.{1,}/}).details // returns{lenght:true}

// isEmail
new Verifier('[email protected]').isEmail().correct // returns false
new Verifier('[email protected]').isEmail().correct// returns true

// isLengthen
new Verifier('exact').isLengthen(5).correct // returns true
new Verifier('greaterthan').isLengthen('gt10').correct // returns true
new Verifier('lowerthan').isLengthen('lt10').correct // returns true

// excludes
new Verifier("hello").excludes("bye").correct //returns true
new Verifier("hello").excludes(anyone("bye")).correct //returns false
new Verifier("hey!hello").excludes("hello").details.excludes //returns false

// includes
new Verifier("hello").includes("bye").correct //returns false
new Verifier("hello").includes(anyone("bye")).correct //returns true
new Verifier("hey!hello").includes("hello").details.includes //returns true

// startsWith
new Verifier("Hey Buddy").startsWith("Hey").correct // return true
new Verifier("Hey Buddy").startsWith("hehe").correct // return false
new Verifier("Hey Buddy").startsWith(anyone("Hey")).details.startsWith // return true
new Verifier("Hey Buddy").startsWith(/[hello]/i).details.startsWith // return true

// endsWith
new Verifier("Hey Buddy").endsWith("uddy").correct // return true
new Verifier("Hey Buddy").endsWith("hehe").correct // return false
new Verifier("Hey Buddy").endsWith(anyone("Hey")).details.endsWith // return true
new Verifier("Hey Buddy").endsWith(/[hello]$/i).details.endsWith // return false

// isLink
new Verifier('https://google.com').isLink().correct // returns true
new Verifier('https://www.google.com').isLink().correct // returns true
new Verifier('http://example.com').isLink(/^(http|https)/).details.link // returns true
new Verifier('google.com').isLink().details.link // returns false

// consistOf
new Verifier("helloG").consistOf({
    uppercaseAlpha: true,
    lowercaseAlpha: true
}).correct //returns true
new Verifier("hello_G").consistOf({
    uppercaseAlpha: true,
    lowercaseAlpha: true,
    custom: "_-"
}).correct //returns true
new Verifier("hello_G").consistOf({
    uppercaseAlpha: true,
    lowercaseAlpha: true,
}).correct //returns false


// ageCalc
new Verifier('2005-02-22').ageCalc() //  16
new Verifier('WrongFormat').ageCalc() //  Error Verifier.ageCalc:Invalid Date


// array - Can be use on any chaineble method
new Verifier('hello').isLengthen(5).array() //  returns [[length],[true]]
new Verifier('username').isUsername().isLengthen("gt4 lt30").array() // returns[["start", "syntax", "length"],[true, true, true]]

Verifier Class Properties

{
    correct: true If all the validation is successful,
    details: detail version of `correct`,
    ... All methods
}

Username Default syntax

  • Username must start with alphabetic characters
  • Username should only contain letters, numbers,underscores,dashes,dots

Password Default syntax

  • must contain at least one lowercase letter
  • must contain at least one uppercase letter
  • must contain at least one symbol or number
  • length must be at least 8 characters long

Age

  • DOB Format : YY-MM-DD

Chainable Functions

  1. isUsername
  2. isPassword
  3. isEmail
  4. isLengthen
  5. includes
  6. excludes
  7. startsWith
  8. endsWith
  9. isLink
  10. consistOf

Non Chainable Methods

  1. array : returns array in which first element is array of properties(validation) names and second element is array of properties(validation) values
  2. ageCalc : Calculates Age

Helper Function

  1. anyone:
 new Verifier("HeyThere").includes(anyone("hello")).correct // return true
  • What it basically does is that it tells the includes function that if string(which is to verify) contains "h" or "e" or "l" or "o" if anyone of them does then just check if remaining functions in the chain are passed if they had then just set correct to true

  • Same goes for excludes func check if "h" or "e" or "l" or "o" is present in the string if anyone of them does then just set correct to false

Contributing

See CONTRIBUTING.md.

Bugs and Issues

If you encounter any bugs or issues, feel free to open an issue at github or email me to [email protected]. I also always like to hear from you, if you’re using my code.