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 🙏

© 2025 – Pkg Stats / Ryan Hefner

visorjs

v2.0.1

Published

A Validation Framework.

Readme

VisorJS

A Validation Framework.

Visorjs doesn't attempt to tell you what rules you have to make and what rules you have to follow. It comes with only with two rules required and notRequired

This allows you to use a different library like validator. This is a highly popular and tested library.

Usage

    import Validator from "visorjs";
    // Extends this class


    class UserValidation extends Validator{
        constructor(){
            super();
            this.setConfig({
                name:"username"
            })
        }


        username(key,value){
            if(value.length < 6){
                throw new Error(`username needs 6 characters`)
            }
        }
    }


    let v = new UserValidation()

    v.validate({
        name:"short"
    })
    //throws error

Best Practice

You only want to use a Validation instance once. So you will be creating a new one each time. Use extend to create Base Classes that has common validations that you want to run.

You can pass parameters to the function easily by adding params.


    class UserValidation extends Validator{
        constructor(){
            super();
            this.setConfig({
                name:"username:6,20"
            })
        }


        username(key,value,min,max){
            //All parameters are going to be passed as a string
            //So they need to be parsed

            if(value.length < parseInt(min) || value.length > parseInt(max)){
                throw new Error(`username needs 6 characters`)
            }
        }
    }


required notRequired

These two functions are very important. They allow you to do something very nice with validation.

Imaging this possibility.


    class UserValidation extends Validator{
        constructor(){
            super();
            this.setConfig({
                name:"username:6,20",
                "address":"notRequired",
                "address.street":"required",
                "address.number":"required"
            })
        }


        username(key,value,min,max){
            //All parameters are going to be passed as a string
            //So they need to be parsed

            if(value.length < parseInt(min) || value.length > parseInt(max)){
                throw new Error(`username needs 6 characters`)
            }
        }
    }

This allows you to have a parameter that is missing. Like address, however if the address is present it forces certain elements to be required.

    //Valid against the rule above
    {
        name:"shavy"
    }


    //not valid missing number
    {
        name:"shavy",
        address:{
            street:"home"
        }
    }


    //valid
    {
        name:"shavy",
        address:{
            number:10,
            street:"home"
        }
    }

Config

The config allows a certain amount of flexibility. For example you can use these different combination in your rules.

    //single string value that must be a method that accepts key and value
    "rulename"

    //multiple rules
    "rulename|other_rulename"

    //Array rule 
    ["rulename","other_rulename"]


    //function
    (key:string,value:any)=>{
        //throw error here if you need be
    }

    //mixture of string and arrays
    ["rulename",(key:string,value:any)=>{

    }]


    //passing parameters
    "rulename:arg1,arg2"

    //this will call the method with args as such

    class Example extends Validator{
        rulename(key:string,value:any,arg1:string,arg2:string){
        //all passed args will always be a string

        //throw if error
            
        }
    }

All other functions that are required will need to be created on your own.

Future

I plan on adding a different class that will have some basic validation.

Concepts

Rules are validated in the order that they are written. It fails on the first one.

Dependencies

This is simple. None.

Typescript

Hell yea!!!