README
apakah
Type check your variables
Installation
npm install apakah
Documentation
- apakah.string
Check if type is string
console.log(apakah.string('123')) // true
- apakah.num
Check if type is number
console.log(apakah.num(321)) // true
- apakah.bool
Check if type is boolean
console.log(apakah.bool(false)) // true
- apakah.func
Check if type is function
function hello() {
return 'world';
}
console.log(apakah.func(hello)) // true
- apakah.obj
Check if type is object
const schema = {
hello: apakah.string,
}
const match = obj(schema);
console.log(match({
hello: 'world',
})) // true
- apakah.arr
Check if type is array
const match = arr([1, 2]);
console.log(match) // true
- apakah.date
Check if type is array
const match = date(new Date());
console.log(match) // true
- apakah.and This function can be combined with any other validator. This is most useful for testing multiple condition that has to be true
const arrayWithLengthOf5 = apakah.and(apakah.arr, (item) => item.length === 5);
arrayWithLengthOf5([1, 2]) // false
arrayWithLengthOf5('string') // false
arrayWithLengthOf5([12, 3, 54, 6, 21]) // true
- apakah.or This function can be combined with other validator. This variant of function will return true if any of the validator is truthy
const stringOrNum = apakah.or(apakah.string, apakah.num)
stringOrNum(5) // true
stringOrNum('hello') // true
stringOrNum({}) // false