0.0.2 • Published 5 years ago

jenis v0.0.2

Weekly downloads
40
License
MIT
Repository
github
Last release
5 years ago

Jenis

Jenis is a small js utility to check your data type.

INSTALLATION

Add jenis to your project using npm or yarn: npm i jenis or yarn add jenis

API

There are two ways to check your data type using Jenis:

Using jenis.is.[type] or jenis.not.[type]

.is and .not behaves the same way. It will compare your input to the rules then return boolean result.

Example

const jenis = require('jenis')

jenis.is.array(['apple', 'banana']) // true
jenis.not.array(['apple','banana']) // false
TypeParamReturnsExample
stringanybooleanjenis.is.string('Hello world') // true
arrayanybooleanjenis.is.array([]) // true
objectanybooleanjenis.is.object({}) // true
numberanybooleanjenis.is.number(1) // true
functionanybooleanjenis.is.function(function test(){}) // true
nullanybooleanjenis.is.null(null) // true
undefinedanybooleanjenis.is.undefined() // true
booleananybooleanjenis.is.boolean(false) // true
regexpanybooleanjenis.is.regexp(new RegExp) // true
erroranybooleanjenis.is.error(new Error) // true
dateanybooleanjenis.is.date(new Date) // true
symbolanybooleanjenis.is.symbol(Symbol()) // true
promiseanybooleanjenis.is.promise(new Promise(function (resolve, reject) {})) // true

Using .check()

The check method will let you check what type of data supplied. This method return a string of data type, which can be one of the following:

  • undefined
  • string
  • array
  • object
  • number
  • function
  • null
  • boolean
  • regexp
  • error
  • date
  • symbol
  • promise

Example

const jenis = require('jenis')

jenis.check('My string') // string

TODO:

  • Create test
  • Add Travis CI