checkvar
v1.0.1
Published
It checks if a variable is empty or not
Readme
checkvar
It checks if a variable is empty or not and returns true (not empty) or false (empty) accordingly. It also can return a CheckResponse type as response, which also includes the variable type.
type CheckResponse = {
type: CheckType
result: boolean
}This module doesn't strictly consider truthy/falsy values, so if you checks 0 or false, you'll get true as result.
Always use the === operator to check for booleans and 0 or 1, use this module just to exclude the "emptiness" of a value.
Definitions of emptiness
This module has the following rules:
nullandundefinedare always considered empty, as as such the function will returnfalse.numberwill befalseonly when the passed value isNaN.0will returntrueinstead, as it may be a desired value.- a
functionwill be considered empty only if it's body is completely empty (comments are stripped away). boolean,symbolandbigintwill always returntrue.- a
stringwill be considered empty if, after having being trimmed, its length is 0. - an
objectwill be considered empty if its JSON serialization returns{}or'""'(if it was a wrapper for a primitive type likenew String()).
