Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

util-nonempty

codsen17.2kMIT5.0.18TypeScript support: included

Is the input (plain object, array, string or whatever) not empty?

array, empty, is, not, object, string, util

readme

util-nonempty

Is the input (plain object, array, string or whatever) not empty?

page on codsen.com page on npm page on github Downloads per month changelog MIT Licence

Install

This package is pure ESM. If you're not ready yet, install an older version of this program, 3.1.0 (npm i util-nonempty@3.1.0).

npm i util-nonempty

Quick Take

import { strict as assert } from "assert";

import { nonEmpty } from "util-nonempty";

assert.equal(nonEmpty("z"), true);
assert.equal(nonEmpty(""), false);
assert.equal(nonEmpty(["a"]), true);
assert.equal(nonEmpty([123]), true);
assert.equal(nonEmpty([[[[[[[[[[[]]]]]]]]]]]), true);
assert.equal(nonEmpty({ a: "" }), true);
assert.equal(nonEmpty({ a: "a" }), true);
assert.equal(nonEmpty({}), false);

const f = () => {
  return "z";
};
assert.equal(nonEmpty(f), false);
// (answer is instantly false if input is not array, plain object or string)

Documentation

Please visit codsen.com for a full description of the API.

Contributing

To report bugs or request features or assistance, raise an issue on GitHub.

Licence

MIT License.

Copyright © 2010-2025 Roy Revelt and other contributors.

ok codsen star

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

5.0.0 (2022-12-01)

BREAKING CHANGES

  • Minimum supported Node version is v14.18; we're dropping v12 support

4.1.0 (2022-08-12)

Features

4.0.0 (2021-09-09)

Features

BREAKING CHANGES

  • programs now are in ES Modules and won't work with Common JS require()

3.1.0 (2021-05-24)

Features

  • config file based major bump blacklisting (e15f9bb)

3.0.15 (2021-04-11)

Reverts

  • Revert "chore: setup refresh" (23cf206)

3.0.1 (2021-01-28)

Fixed

  • add testStats to npmignore (f3c84e9)

3.0.0 (2021-01-23)

Features

  • rewrite in TS, use named exports (5cbaf96)

BREAKING CHANGES

  • previously, you'd consume like import nonEmpty from ... - now consume like import { nonEmpty } from ...

2.10.0 (2020-11-28)

Accidental version bump during migration to SourceHut. Sorry about that.

2.9.44 (2019-10-02)

Performance Improvements

  • tap Array.isArray directly, speed improvements (83cd308)

2.9.0 (2019-01-20)

  • Various documentation and setup tweaks after we migrated to monorepo
  • Setup refresh: updated dependencies and all config files using automated tools

2.3.0 (2018-10-26)

  • Update all dependencies
  • Restore coveralls.io reporting
  • Restore unit test linting

2.2.0 (2018-07-16)

GitHub sold us out. In the meantime, we:

  • Migrated to BitBucket (to host repo + perform CI) and Codacy (for code quality audit)
  • Dropped BitHound (RIP) and Travis

2.1.0 (2018-05-25)

  • Set up Prettier on a custom ESLint rule set.
  • Removed package.lock and .editorconfig
  • Wired Rollup to remove comments from non-dev builds. This means we can now leave the console.logs in the source code — there's no need to comment-out console.log statements or care about them not spilling into production. Now it's done automatically.
  • Unit tests are pointing at ES modules build, which means that code coverage is correct now, without Babel functions being missed. This is important because now code coverage is real again and now there are no excuses not to perfect it.

2.0.0 (2017-11-09)

  • Numbers are not correctly reported as "non-empty"
  • Some rebasing and improvements to the setup

1.4.0 (2017-09-23)

  • Implemented Rollup to generate 3 flavours of this package: CommonJS, UMD and ESM module with import/export

1.3.0 (2017-09-18)

  • Add this changelog
  • Switched from JS Standard to ESLint on airbnb-base preset. It's way better

1.0.0 (2016-12-23)

  • First public release