Introduction
Last updated
Was this helpful?
Last updated
Was this helpful?
The type
package's purpose is to determine the type of single or multiple values and guard single values. It also contains common types that can be useful for other packages.
The check
means to determine the value of type by using dedicated functions like 'isNaN()'
, methods like 'isArray()'
, and operators 'typeof'
'instanceof'
. The type
package functions for checking the values are prefixed with 'are' 'is' 'isNot' word.
The guard
means the same as a check but with an additional constrain type, and guard functions are prefixed with the 'guard' word.
The difference between prefixed with 'is' and 'are' functions is, prefixed with 'is' are used to check a single value of any type, prefixed with 'are' are used for checking multiple values of any type against one type. Additionally, checking multiple values is determined by every()
, forEach()
or some()
methods.
To make the functions more precise, besides the use of '' and '' operators, some of them use method 'toString()
' of the two objects '' and '' to detect the type.
Each function includes an optional callback function to handle the check result and an optional payload. The payload parameter of the callback function contains additional useful properties specific to the function and can be extended by the payload parameter of the core function.