is-really-empty

0.3.1 • Public • Published

is-really-empty 🌌

npm

A Small library to tell if the passed value is really empty.

Prerequisites

This library uses for in and for of so at least node 4.x is required.

What "empty" means

Marriam-Webster definition of empty

Lacking reality, substance, meaning, or value. Marked by the absence of human life, activity, or comfort

A value proves to be "empty" when we can determine it contains nothing. An object or array that has been instantiated (even with a length value being set) if no fields have been populated, then it proves to be empty. WeakMaps and WeakSets are never empty since there is no way to tell if they've ever been filled. A function is empty when it accepts no parameters. False, null, undefined, and NaN are all empty as they are the absence of value and often defaults for some cases.

Iterables

Since the way it tells if an iterable is empty is by traversing it, this will call a getter or a yield (in a generator function) if they exist as the first property.

Usage

A more comprehensive list is on the project website.

const isEmpty = require("is-really-empty");

isEmpty(undefined); // true
isEmpty(1); // false
isEmpty(NaN); // true
isEmpty(""); // true
isEmpty("1"); // false
isEmpty([]); // true
isEmpty([1]); // false
isEmpty(new Array(2)) // true
isEmpty()()()()("string"); // false

Testing

$ npm test

License

WTFPL

Readme

Keywords

Package Sidebar

Install

npm i is-really-empty

Weekly Downloads

6

Version

0.3.1

License

WTFPL

Unpacked Size

4.73 kB

Total Files

4

Last publish

Collaborators

  • overlandandseas