is-funcs
A very limited subset of is-* functions I use every day
Install
npm i is-funcs
Package on npm
API
- is-array-filled
- is-boolean
- is-buffer
- is-date
- is-date-string
- is-float
- is-function
- is-gt
- is-gte
- is-integer
- is-lt
- is-lte
- is-nan
- is-node
- is-node-landed
- is-number-defined
- is-number-string
- is-object
- is-plain-object
- is-regexp
- is-string-filled
is-array-filled(data)
Check if data
is an Array and is length is > 0
Argument | Action |
---|---|
data | the tested data |
const isArrayFilled = // false // true // false
is-boolean(data)
Check if data
is a Boolean
Argument | Action |
---|---|
data | the tested data |
const isBoolean = // false // true // true
is-buffer(data)
Check if data
is a node Buffer
Argument | Action |
---|---|
data | the tested data |
const isBuffer = // false // false // true
is-date(data)
Check if data
is a valid instance of new Date
Argument | Action |
---|---|
data | the tested data |
const isDate = // true // false, invalid date // false // false
is-date-string(data)
Check if data
is a valid date string representation
Argument | Action |
---|---|
data | the tested data |
Date string validation is a nightmare. The browsers have differents behaviors
This function validates the patterns that return a correct date in the following case
// valid dateconsole
Valid patterns are:
YYYY/M/D
andYYYY-M-D
YYYY/MM/DD
andYYYY-MM-DD
YYYY/M/D H:M
andYYYY-M-D H:M
YYYY/M/D HH:MM
andYYYY-M-D HH:MM
YYYY/M/D H:M:S
andYYYY-M-D H:M:S
YYYY/M/D HH:MM:SS
andYYYY-M-D HH:MM:SS
YYYY-M-DTHH:MM:SSZ
andYYYY-M-DTHH:MM:SS.LLLZ
This function also test the date validity:
- No 29 february if this is not a leap year
- No 31 april
const isDateString = // true // true // false, because invalid iso date // false, because april has 30 days // false, because 2015 is not a leap year
is-float(data)
Check if data
is a Float Number
Argument | Action |
---|---|
data | the tested data |
const isFloat = // false // false // true /* Attention: Javascript returns wrong results with extreme values*/// true // false
is-function(data)
Check if data
is a Function defined by the developper. Standard built-in objects are excluded
Use it if you really need this full test, otherwise just write typeof data === 'function'
const isFunction = // true // false // false // false
is-gt(data, than)
Check if data
is a greater than than
Argument | Action |
---|---|
data | the tested data |
than | the reference than |
const isGt = // true // false
is-gte(data, than)
Check if data
is a greater or equal than than
Argument | Action |
---|---|
data | the tested data |
than | the reference than |
const isGte = // true // true // false
is-integer(data)
Check if data
is an Integer Number
Argument | Action |
---|---|
data | the tested data |
const isInteger = // true // false /* Attention: Javascript returns wrong results with extreme values*/// false // true
is-lt(data, than)
Check if data
is a lower than than
Argument | Action |
---|---|
data | the tested data |
than | the reference than |
const isLt = // true // false
is-lte(data, than)
Check if data
is a lower or equal than than
Argument | Action |
---|---|
data | the tested data |
than | the reference than |
const isLte = // true // true // false
is-nan(data)
Check if data
is a real NaN
Number
Argument | Action |
---|---|
data | the tested data |
const isnan = // true // true // false // default isNaN return true
is-node(data)
Check if data
is a Html Element with a nodeType of 1
Argument | Action |
---|---|
data | the tested data |
const isNode = // true // true
is-node-landed(data)
Check if data
is a visual Html Element with a nodeType of 1 landed in the document.body
Elements like style
or script
are excluded
Argument | Action |
---|---|
data | the tested data |
const isNodeLanded = // true // falsevar div = document // truedocumentbody
is-number-defined(data)
Check if data
is a defined Number, not equals to NaN
Argument | Action |
---|---|
data | the tested data |
const isNumberDefined = // true // true // false // false
is-number-string(data)
Check if data
is a valid number string representation
Argument | Action |
---|---|
data | the tested data |
This function validates the patterns that return a correct number in the following case
// valid numberconsole
const isNumberString = // true // true // true // true // false // false // false
is-object(data)
Simplest and fastest way to check if data
is an Object
We just wants to know if data
is an object where we can define a property, excluding Functions
Technically functions
should be true
but what we want here is just a not so exact but quick test to know if data
is like a Plain Object
See is-plain-object for stricter but slower object test
Argument | Action |
---|---|
data | the tested data |
const isObject = // true // true // true // true, typeof Math JSON Reflect Intl and WebAssembly is "object" // false // false
is-plain-object(data)
Check if data
is a Plain Object
Argument | Action |
---|---|
data | the tested data |
const isPlainObject = // true // true // false // false // false
is-regexp(data)
Check if data
is a RegExp
const isRegexp = // false // false // true // true
is-string-filled(data)
Check if data
is an String and his trimmed length is > 0
All possible unicode blank chars are trimmed
Argument | Action |
---|---|
data | the tested data |
const isStringFilled = // true // false // false // false // false
License
MIT