Package Exports
- is-funcs/is-array
- is-funcs/is-boolean
- is-funcs/is-defined
- is-funcs/is-gte
- is-funcs/is-nan
- is-funcs/is-node
- is-funcs/is-number
- is-funcs/is-object
- is-funcs/is-regexp
- is-funcs/is-string
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (is-funcs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
is-funcs
A very limited subset of is-* functions I use every day
Install
npm i is-funcsPackage on npm
API
- isArray
- isBoolean
- isDefined
- isFloat
- isFunction
- isGt
- isGte
- isInteger
- isLt
- isLte
- isNaN
- isNode
- isNumber
- isObject
- isRegexp
- isString
isArray(data, [check])
Check if data is an Array and his length is > 0
| Argument | Action |
|---|---|
| data | the tested data |
| check | optional check, default to true. If false, the length is not tested |
const isArray = require('is-funcs/is-array')
// false
isArray({a:1})
// true
isArray(['a'])
// false
isArray([])
// true
isArray([], false)isBoolean(data, [safe])
Check if data is a Boolean
| Argument | Action |
|---|---|
| data | the tested data |
| safe | optional safe, default to false. If true, validate also the new Boolean() instance |
const isBoolean = require('is-funcs/is-boolean')
// false
isBoolean({a:1})
// true
isBoolean(true)
// true
isBoolean(false)
// true
isBoolean(new Boolean(false), true)isDefined(data, [safe])
Check if data is defined
| Argument | Action |
|---|---|
| data | the tested data |
| safe | optional safe, default to false. If true, validate also the new Number() instance |
Return false if
dataisundefineddataisnulldataisNaN
Otherwise return true
const isDefined = require('is-funcs/is-defined')
// false
isDefined(undefined)
// false
isDefined(null)
// false
isDefined(NaN)
// true
isDefined(0)
// true
isDefined(false)
// true
isDefined('')
// true
isDefined(new Number(NaN))
// false
isDefined(new Number(NaN), true)isFloat(data, [safe])
Check if data is a Float Number
| Argument | Action |
|---|---|
| data | the tested data |
| safe | optional safe, default to false. If true, validate also the new Number() instance |
const isFloat = require('is-funcs/is-float')
// false
isFloat('abc')
// false
isFloat(12)
// true
isFloat(12.3)
// true
isFloat(new Number(12.3), true)isFunction(data)
Check if data is a Function
const isFunction = require('is-funcs/is-function')
// false
isFunction(12.3)
// true
isFunction(function() {})isGt(data, than, [safe])
Check if data is a greater than than
| Argument | Action |
|---|---|
| data | the tested data |
| than | the reference than |
| safe | optional safe, default to false. If true, validate also the new Number() instance |
const isGt = require('is-funcs/is-gt')
// true
isGt(2, 1)
// false
isGt(2, 3)
// true
isGt(new Number(2), 1, true)isGte(data, than, [safe])
Check if data is a greater than or equal than
| Argument | Action |
|---|---|
| data | the tested data |
| than | the reference than |
| safe | optional safe, default to false. If true, validate also the new Number() instance |
const isGte = require('is-funcs/is-gte')
// true
isGte(3, 2)
// true
isGte(2, 2)
// false
isGte(2, 3)
// true
isGte(new Number(2), 2, true)isInteger(data, [safe])
Check if data is an Integer Number
| Argument | Action |
|---|---|
| data | the tested data |
| safe | optional safe, default to false. If true, validate also the new Number() instance |
const isInteger = require('is-funcs/is-integer')
// true
isGt(2)
// false
isGt(2.34)
// true
isGt(new Number(2), true)isLt(data, than, [safe])
Check if data is a lower than than
| Argument | Action |
|---|---|
| data | the tested data |
| than | the reference than |
| safe | optional safe, default to false. If true, validate also the new Number() instance |
const isLt = require('is-funcs/is-lt')
// true
isLt(1, 2)
// false
isLt(3, 2)
// true
isLt(new Number(1), 2, true)isLte(data, than, [safe])
Check if data is a lower than or equal than
| Argument | Action |
|---|---|
| data | the tested data |
| than | the reference than |
| safe | optional safe, default to false. If true, validate also the new Number() instance |
const isLte = require('is-funcs/is-lte')
// true
isLte(1, 2)
// true
isLte(2, 2)
// false
isLte(3, 2)
// true
isLte(new Number(1), 2, true)isNaN(data, [safe])
Check if data is a real NaN Number
| Argument | Action |
|---|---|
| data | the tested data |
| safe | optional safe, default to false. If true, validate also the new Number() instance |
const isnan = require('is-funcs/is-nan')
// true
isnan(NaN)
// false
isnan('abc')
// default isNaN return true
isNaN('abc')
// true
isnan(new Number(NaN), true)isNode(data, [check])
Check if data is a Html Element landed in the document.body
- data nodeType must be 1
- non visual element like
styleorscriptare excluded
| Argument | Action |
|---|---|
| data | the tested data |
| check | optional check, default to true. If false, the following tests are ignored |
If check is false
- non visual element are ignored. Testing
styleorscriptnodes now returntrue - landed in
document.bodytest is ignored
const isNode = require('is-funcs/is-node')
// true
isNode(document.querySelector('div'))
// false
isNode(document.createElement('div'))
// true
isNode(document.createElement('script'), false)isNumber(data, [safe])
Check if data is a Number, not equals to NaN
| Argument | Action |
|---|---|
| data | the tested data |
| safe | optional safe, default to false. If true, validate also the new Number() instance |
const isNumber = require('is-funcs/is-number')
// false
isNumber([1])
// true
isNumber(1)
// true
isNumber(2.34)
// false
isNumber(NaN)
// true
isNumber(new Number(1), true)isObject(data, [check], [safe])
Check if data is an Plain Object and has at least 1 key
| Argument | Action |
|---|---|
| data | the tested data |
| check | optional check, default to true. If false, the keys count is not tested |
| safe | optional safe, default to false. If true, validate also the new Object() instance |
note: function arguments is evaluted as plain object. Set safe to true if you want exclude this possibility
const isObject = require('is-funcs/is-object')
// false
isObject([1])
// true
isObject({a:1})
// false
isObject({})
// true
isObject({}, false)
// true
isObject(new Object({a:1}), true, true)isRegexp(data)
Check if data is a RegExp
const isRegexp = require('is-funcs/is-regexp')
// false
isRegexp(true)
// false
isRegexp('/./')
// true
isRegexp(/./)
// true
isRegexp(new RegExp('/./'))isString(data, [check], [safe])
Check if data is an String and his trimmed length is > 0
| Argument | Action |
|---|---|
| data | the tested data |
| check | optional check, default to true. If false, trimmed length is not tested |
| safe | optional safe, default to false. If true, validate also the new String() instance |
const isString = require('is-funcs/is-string')
// false
isString({a:1})
// true
isString('abc')
// false
isString('')
// false
isString(' ')
// true
isString(' ', false)
// true
isString(new String('abc'), true, true)Note
The safe option, disabled by default, is here to cover extreme cases
99.99% of the time, you don't need the safe option
License
MIT