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

@hyron/validator

v1.0.4

Published

Validate input easier used comment

Downloads

23

Readme

Build status Gitter npm

@hyron/validator is a powerful library for validate input of function for more security

Features

  • Validate by comment
  • Support validate value
  • Support validate structure
  • Support for Hyron Framework
  • High performance

Usage

Step 1 : Install

By NPM :

npm i @hyron/validator

By YARN :

yarn add @hyron/validator

Step 2 : Validate data

To check input data with complex condition, using getConditionChecker(..) function

const validator = require("@hyron/validator");

var checker = validator.getConditionChecker({
    type : "number",
    lt : 10,
    gt : 0
});

checker(4); // allow
checker("hi"); // has error
checker(12); // has error

To check input structure of input. using getStructureChecker(..) function. For more info, checkout structure parser engine

const validator = require("@hyron/validator");

var checker = validator.getStructureChecker(`
{key1(string)}
`);

checker({key1:null}); // allow
checker({key1: 34}); // has error
checker({key1:"hi"}); // allow

validator also support to used comment for validator to validate function arguments easier. View Validate by Comment for more info

function demo(arg1){
    /**
     * @check arg1 {type:string, size:20} - check if arg1 is string with max length is 20
     */
    ...
}

API Reference

function registerValidator( func, eventName ? ) : (args) => void

Used to register validate for a function by comment. Valid options include :

  • @check : Check if the input parameter meets the condition
  • @ignore : remove values from input if matched
  • @accept : filter values from input if matched
  • @valid : Only accept input parameters when it matches correctly

To know more about how to write validate condition, please visit guide

params

  • func ( function ) : target function will be used to parser validate condition
  • eventName ( string ) : a name represent for this validator. Default is func.name

return

  • validator ( function (args)=>void ) : a function that could be used to check function input data

function getValidator( eventName ) : (args) => void

Used to get a registered validator that have been registered before to check input data

params

  • eventName ( string ) : a name represent for this validator. Default is func.name

return

  • (args)=>void : a function that could be used to check function input data

function getConditionChecker( conditionMap ) : checker

get checker by condition to validate input data

params

  • argsName ( string ) : a name represent for input data

return

  • (input)=>boolean : a function that could be used to check function input data

function getStructureChecker ( struct, onChecked? ) : (input)=>void

get checker by condition to validate input structure of data used structure parser engine

params

  • struct ( string ) : a structure that defined for input data
  • onChecked ( function ) : a function that will be called for each time data was check

return

  • (input)=>void : a function that could be used to check input structure