@hyron/validator is a powerful library for validate input of function for more security
- Validate by comment
- Support validate value
- Support validate structure
- Support for Hyron Framework
- High performance
By NPM :
npm i @hyron/validator
By YARN :
yarn add @hyron/validator
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
*/
...
}
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
- func ( function ) : target function will be used to parser validate condition
- eventName ( string ) : a name represent for this validator. Default is func.name
- validator ( function (args)=>void ) : a function that could be used to check function input data
Used to get a registered validator that have been registered before to check input data
- eventName ( string ) : a name represent for this validator. Default is func.name
- (args)=>void : a function that could be used to check function input data
get checker by condition to validate input data
- argsName ( string ) : a name represent for input data
- (input)=>boolean : a function that could be used to check function input data
get checker by condition to validate input structure of data used structure parser engine
- struct ( string ) : a structure that defined for input data
- onChecked ( function ) : a function that will be called for each time data was check
- (input)=>void : a function that could be used to check input structure