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

v_rifier

v1.1.0

Published

Simple to use and quite flexible Data Validator/Verifier for Web and Node.js applications.

Downloads

13

Readme

v_rifier

Data V[a]rifier => v_rifier 😁

📚 How to use

const v_rifier = require('v_rifier');
let myVerifier = v_rifier();

or use import

import v_rifier from 'v_rifier';
let myVerifier = v_rifier();

Built-in functions

NOTE: Don't forget to add await before any of the following verification methods are called.

  1. array
    Array Checker

     myVerifier.isArray([1,2,3]) //> true
  2. bool
    Boolean Checker

     myVerifier.isBool(true) //> true
     myVerifier.isBool(false) //> true
    
     myVerifier('bool', true) //> true
     myVerifier('bool', false) //> true
    
     myVerifier.isBool(112) //> false
     myVerifier('bool', 0) //> false
     myVerifier.isBool("true") //> false
     myVerifier('bool', "true") //> false
  3. color
    Color Checker that will verify if provided string is valid color in RGB, RGBA and hex format.

     // RGB
     myVerifier.isColor("25,25,25") //> true
     // RGBA
     myVerifier.isColor("25,25,25,.58") //> true
        
     // Hex
     myVerifier.isColor("#CBA") //> true
     myVerifier.isColor("#CBA5") //> true
     myVerifier.isColor("#FF00CC") //> true
     myVerifier.isColor("#FF00CC50") //> true
        
     // Invalid Colors
     myVerifier.isColor("0,0,0,-.58") //> true
     myVerifier.isColor("FF00CC50") //> false
  4. email
    Email Checker

     myVerifier.isEmail('[email protected]') //> true
     myVerifier('email','[email protected]') //> true
  5. function
    Function Checker

     const sampleFunc = async () => {
       return console.log('yea');
     };
    
     myVerifier.isFunction(sampleFunc) //> true
     myVerifier('function', sampleFunc ) //> true
  6. hexadecimal
    Hexadecimal Checker - returns true if provided string is a hexadecimal number.

     myVerifier.isHexadecimal( 'FAc0516' ) //> true
     myVerifier('hexadecimal', 1561313 ) //> false
  7. integer
    Integer Checker

     myVerifier.isInteger( 123 ) //> true
     myVerifier('integer', 984351 ) //> true
  8. name
    Name Checker

     myVerifier.isName( "Slavko Vuletic" ) //> true
     myVerifier('name', 123 ) //> false
  9. npmVersion
    npmVersion Checker

     myVerifier.isNull( "1.2.1" ) //> true
     myVerifier('null', "55.798.15" ) //> true
    
     myVerifier.isNull( 123 ) //> false
     myVerifier('null', "55.-798.15" ) //> false
     myVerifier('null', "55.-798.15-" ) //> false
  10. null
    Null Checker

    myVerifier.isNull( null ) //> true
    myVerifier('null', null ) //> true
  11. number
    Number Checker

    myVerifier.isNumber( 123 ) //> true
    myVerifier('number', 123 ) //> true
  12. object
    object Checker

    myVerifier.isObject( { name: "yea" } ) //> true
    myVerifier('object', 123 ) //> false
  13. password
    password Checker - Verify password with confirmation password and returns true if password is valid [length & characters].

    myVerifier.isPassword( 'MyPassword123', 'MyPassword123' ) //> true
    myVerifier('password', 'MyPassword123', 'MyPassword123' ) //> true
    
    myVerifier.isPassword( 'MyPassword123', 123 ) //> false
    myVerifier('password', 'MyPassword123' ) //> false
  14. port
    PORT Checker

    myVerifier.isPort( 8000 ) //> true
    myVerifier('port', 8000 ) //> true
    
    myVerifier.isPort( -8000 ) //> false
    myVerifier('port', 8000000 ) //> false
  15. string
    string Checker

    myVerifier.isString( "random String" ) //> true
    myVerifier('string', "random String" ) //> true
    
    myVerifier.isString( 123 ) //> false
    myVerifier('string', 123 ) //> false
  16. undefined
    undefined Checker

    myVerifier.isUndefined(  ) //> true
    myVerifier('undefined', undefined ) //> true
    
    myVerifier.isUndefined( 11 ) //> false
    myVerifier('undefined', "undefined" ) //> false
  17. username
    username Checker

    myVerifier.isUsername( 123 ) //> true
    myVerifier('username', 123 ) //> true

🚀 Advanced Usage

1. Register Custom Type

    await myVerifier.register("myType", (value) =>  value > 100 );

So now you can use myVerifier.**isMyType**(val) to check if value is greater than 100.

    await myVerifier.isMyType(200) //> true

Or you can use myVerifier("**myType**", val) to check if value is greater than 100.

    await myVerifier('myType', 200) //> true

2. Unregister Custom Type

await myVerifier.unregister("myType");

3. Disable Loading of the Built-in Verification Functions

let myEmptyVerifier = await v_rifier({ builtIns: false });

4. Only Custom Types

After loading module, you can create your custom validation type without even loading built-ins. This provides the ability to create and use only your own custom types.

const v_rifier = require('..');

(async () => {
  let sampleVerifier = await v_rifier({ builtIns: false });

  console.log(await sampleVerifier.listTypes()); //> []

  // Create a custom type
  console.log(await sampleVerifier.register('customType', async (value) => (!isNaN(value) && value > 0))); //> true

  console.log(await sampleVerifier.listTypes()); //> [ 'customtype' ]

  // Use it

  // One way...
  console.log(await sampleVerifier('customType', 123)); //> true
  console.log(await sampleVerifier('customType', -123)); //> false

  // Or other way...
  console.log(await sampleVerifier.isCustomType(123)); //> true
  console.log(await sampleVerifier.isCustomType(-123)); //> false

  // Or Unregister It (if you want)
  console.log(await sampleVerifier.unregister('customType')); //> true

  console.log(await sampleVerifier.listTypes()); //> []

})();

Example Location: Example is located in /tests/_README.advanced.js

5. Or a combination of built-ins and custom types

Main usecase basically, where you would want to check on something like a value being a number and also greather than some other value...while not caring about it being empty/undefined/anything else.

const v_rifier = require('..');

(async () => {
  let demoVerifier = await v_rifier();

  // Create a custom type
  console.log(await demoVerifier.register('customType', async (value) => (await demoVerifier('number', value) && value > 0))); //> true

  // Or other way...
  console.log(await demoVerifier.isCustomType(123)); //> true
  console.log(await demoVerifier.isCustomType(-123)); //> false

  console.log(await demoVerifier.isCustomType("-123")); //> false

})();

Example Location: Example is located in /tests/_README.advanced-combined.js