@eoln/is
v1.1.0
Published
eoln's type recognition utility
Downloads
7
Readme
@eoln/is
install mantra
npm install @eoln/is --save
TL;DR
run time type/class discovery by value inspection
and custom class checkers registry (scoped)
usage examples:
iz = require '@eoln/is'
name
- class/type name discovery from instance/value
class NewClass
iz.name new NewClass
#=> 'NewClass'
register
- checkers registry
register custom NewClass
in global
scope instance/value
iz.register new NewClass
iz.NewClass new NewClass
#=> true
register custom NewestClass
in custom scope eoln
class NewestClass
iz.register new NewestClass, 'eoln'
iz.eoln.NewestClass new NewestClass
#=> true
checkers
do we have Array
?
iz.Array []
#=> true
do we have Object
?
iz.Object {}
#=> true
iz.Function Object
#=> true
do we have String
?
iz.String 'the-string'
#=> true
do we have RegExp
?
iz.RegExp /^i-am-regexp$/g
#=> true
do we have Date
?
iz.Date new Date()
#=> true
do we have Number
?
iz.Number 3.14
#=> true
iz.Number 1
#=> true
do we have Function
?
iz.Function (x) => x*x
#=> true
do we have Boolean
iz.Boolean 1 == 2
#=> true
iz.Boolean false
#=> true
do we have Undefined
?
iz.Undefined undefined
#=> true
do we have Null
?
iz.Null null
#=> true
do we have Symbol
?
iz.Symbol Symbol()
#=> true
not
- checker negator
prefix not
will negate checker
we don't have Function
on global
scope
iz.not.Symbol Symbol()
#=> false
iz.not.Symbol []
#=> true
negators in custom scope eoln
iz.eoln.not.NewestClass {}
#=> true
iz.eoln.not.NewestClass new NewestClass
#=> false