Introduction
Validator Framework, write once and use anywhere.
Install
$ npm install vfw
Demo
var vfw = // check objectvar ruleSet = vfwruleSet // => trueruleSet // => false // check arrayruleSet = vfwruleSet // => trueruleSet // => false // check multidimensional arrayruleSet = vfwruleSet // => true // your can parse and check any js objectruleSet = vfwruleSet // with logic element, $and ,$or and $xor is supported, and your can extend moreruleSet = vfwruleSet // => trueruleSet // => true // with expressionruleSet = vfwruleSet // => 1 // use without parse apivfwtype'String' 'as' // => truevar a = 1vfw // => true// $ is short for expressionvfw // => true // everything in vfw is extendable // extend your own typevfwvfwtype'Word' 'azAZ_09' // => trueruleSet = vfwruleSet // => true // extend your own expressionvfwvar b = 1 2vfw // => trueruleSet = vfwruleSet // => true // extend your own structvfwvfw // => truevfw // => falsevfw // => false
API
vfw.type(Type, target)
vfwtype'String' 'asd' // => truevfwtype'Number' 'asd' // => false
vfw.express or vfw.$
vfw // => true
vfw.struct(StructName, target)
vfw
vfw.extendRule(opts)
- extend your own RuleType. type, expression, struct are all instanceof RuleType.
vfw// if name supportedvfw// and you can write rule like thisvfw
vfw.extendParser(Function)
// extend a new RuleType, the rule '#xxx' will be handled by isXxx// for example, #string will be handled by isStringvfwvar _ = vfw// use _.isPlainObjectvar struct = vfwstruct // => true
vfw.extend(type, extends)
- type
String
name of RuleType, like 'type', 'expression' - extends
Object
the functions you want to extend
vfwvfw// once extended, those rules can be used anywhere
vfw.include(type, obj)
- type
String
name of RuleType, like 'type', 'expression' - obj
Object
- you can include a lib like lodash, validator or others and use the functions they supported
var _ = vfw// use _.isPlainObjectvar struct = vfwstruct // => true