apakah

Type check your variables

Usage no npm install needed!

<script type="module">
  import apakah from 'https://cdn.skypack.dev/apakah';
</script>

README

Thinking Meme Png - Thinking Meme With Cup@seekpng.com

apakah

Type check your variables

Installation

npm install apakah

Documentation

  1. apakah.string

Check if type is string

console.log(apakah.string('123')) // true
  1. apakah.num

Check if type is number

console.log(apakah.num(321)) // true
  1. apakah.bool

Check if type is boolean

console.log(apakah.bool(false)) // true
  1. apakah.func

Check if type is function

function hello() {
   return 'world';
}
console.log(apakah.func(hello)) // true
  1. apakah.obj

Check if type is object

const schema = {
   hello: apakah.string,
}

const match = obj(schema);

console.log(match({
  hello: 'world',
})) // true
  1. apakah.arr

Check if type is array


const match = arr([1, 2]);

console.log(match) // true
  1. apakah.date

Check if type is array


const match = date(new Date());

console.log(match) // true
  1. 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
  1. 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