Allows you to check whether a given object is in the correct specified format.
$ npm install --save is-in-correct-format
const isInCorrectFormat = require('is-in-correct-format');
const is = isInCorrectFormat.is;
isInCorrectFormat( {
a:2
},
{
a: is.number
});
//=> true
isInCorrectFormat( {
a:{
b: 3,
c: 24
}
},
{
a: {
b: is.number
}
},is.number);
//=> true
isInCorrectFormat( {
a:{
b: 3,
c: [1,2,3]
}
},
{
a: {
b: is.number
}
},is.number);
//=> true because the arrays values all satisfy 'is.number'
Type: Object
Description: The object being checked whether is in the correct type
Cyclical objects are not allowed.
Type: Object
Description: Follows the same format as the input object to check whether the given keys are passing the tests specified.
{
a: is.function,
b: function( val ) {
return val > 10
},
c: val => is.function(val) || is.object(val)
}
These are all examples of possibilities in the check object, you can use the helper object is
to assist in checking type or define your own checker functions and arrow functions.
Type: Function
Description: Will be calculated on all values of input
object regardless of whether they show in the checked object or not.
Returns true
if argument is a Number
Returns true
if argument is a String
Returns true
if argument is a function
Returns true
if argument is true or false
Returns true
if argument is true
Returns true
if argument is a false
Returns true
if argument is an Array
Returns true
if argument is an Object
Returns true
if argument is undefined
Returns true
if argument is null
Returns true
if argument is a Promise
Returns true
if argument is a Buffer
Returns true
if argument is a Regex
Returns true
if argument is a Symbol
MIT © Nick The Sick