![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@lightningspirit/isempty
Advanced tools
A tiny dependency-free TS library to test for emptiness of any value. This is a missing type-safe feature for JavaScript/TypeScript.
npm i @lightningspirit/isempty
import isempty from '@lightningspirit/isempty';
const object = {};
console.log(
isempty(object) ? "Object is empty" : "Not empty"
);
isempty(false) // false
isempty(false, {
falseIsEmpty: true
}) // true
isempty.false(0) // false
isempty.false('') // false
isempty.false(false) // true
null
, undefined
, ''
are empty values.{}
is an empty object.[]
is an empty array.Map
, Array
, Set
, Object
without members are empty.false
is not empty, it holds a boolean value (see below for the reason).Infinity
, NaN
are not empty, they both have values.new Error()
, new Function()
are not empty objects, they have their semantic and are treated diferently.0
is not empty, it is an integer with a value (see below the reason).' '
is not empty, has a space character.0
not considered empty?null
is a term used to denote the empty nature of a quantity or an entity.0
as null/false. Take the following example:const position = "The lazy fox".indexOf("The"); // 0
isempty(position) // false
false
not considered empty by default?While false
is the negation of something being true, the value itself does state nothing.
It can either be considered true has it holds a meaning value or false as a result of a conditional statement.
In mathematics and logic, these kind of conditions are often called vacuous truth. We considered false
as a universal statement, which means it exists and is not empty, and the programmer must give it the semantics.
If you want to override this behaviour you can pass the falseIsEmpty
option to the function as such:
isempty(false, {
falseIsEmpty: true
}) // true
FAQs
Test for the emptiness of any value
The npm package @lightningspirit/isempty receives a total of 1 weekly downloads. As such, @lightningspirit/isempty popularity was classified as not popular.
We found that @lightningspirit/isempty demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.