object-describe
A lightweight recursive object scheme validator.
For some reason, we just want to know if an object looks like what we want it to be.
Install
npm install object-describe
Usage
var describe = ; var object = hello: 'world'; ; { ; console; //worry free}
Single Object
Check a single object type.
;;
Primitive Support
All primitive type is well supported:
string, number, boolean, array, object, function, null, NaN, undefined
var target = number: 0 string: "this is string" boolean: true undefinedable: undefined nullable: null isnan: 0/0 object: {} array: 123 function: {}; ;
Nested Description
You can define a nested description for deeper check.
var target = level1: level2: level3: {} ; ;
Optional Field
To be or not to be, its not a problem.
add a question mark behind a filed make it an optional.
var target = tobe: 'exist' mybe: 'exist' //maynotbe: 'not exist'; ;
Type Variation
You can describe multiple type choices for a field.
Simply seperate each variation with vertical bar(|
)
var target0 = field: 1; var target1 = field: 'hello'; ;