Installation
Quick Take
Purpose
It is a quick utility function, to be able to detect is the input not empty.
null
,unefined
yieldsfalse
- any number (incl. zero) yields
true
- any array or string with length > 0 yields
true
, otherwisefalse
- plain objects with at least one key yields
true
, otherwisefalse
- all other types yield
false
If you want to check non-emptiness of complex nested trees of objects, arrays and strings (like parsed HTML AST), you need a library which can recursively traverse that. There are two options:
- If you want to check for strict emptiness, that is
[]
or{}
is empty, but{aaa: ' \n\n\n ', ' \t'}
is not, see ast-is-empty - If your “emptiness” definition is “everything that
String.trim()
’s to an empty string’” (this includes tabs, spaces and line breaks for example, but not letters), see ast-contains-only-empty-space, or plain objects without keys or zero-length arrays.
API — nonEmpty()
The main function nonEmpty()
is imported like this:
It’s a function which takes two input arguments:
Function will return a boolean.
API — version
You can import version
: