JSPM

  • Created
  • Published
  • Downloads 7358
  • Score
    100M100P100Q132089F
  • License MIT

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

Package Exports

  • util-nonempty

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (util-nonempty) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

util-nonempty

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

Minimum Node version required Repository is on BitBucket Coverage View dependencies as 2D chart Downloads/Month Test in browser Code style: prettier MIT License

Table of Contents

Install

npm i util-nonempty
// consume as a CommonJS require:
const nonEmpty = require("util-nonempty");
// or as ES module:
import nonEmpty from "util-nonempty";

// then call as a function, pass it anything:
console.log(nonEmpty("a"));

Here's what you'll get:

Type Key in package.json Path Size
Main export - CommonJS version, transpiled to ES5, contains require and module.exports main dist/util-nonempty.cjs.js 1002 B
ES module build that Webpack/Rollup understands. Untranspiled ES6 code with import/export. module dist/util-nonempty.esm.js 849 B
UMD build for browsers, transpiled, minified, containing iife's and has all dependencies baked-in browser dist/util-nonempty.umd.js 1 KB

⬆ back to top

Purpose

I want a quick utility function, to be able to detect is the input not empty.

nonEmpty("z");
// => true

nonEmpty("");
// => false

nonEmpty(["a"]);
// => true

nonEmpty([123]);
// => true

nonEmpty([[[[[[[[[[[]]]]]]]]]]]);
// => false

nonEmpty({ a: "a" });
// => true

nonEmpty({});
// => false

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

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.

⬆ back to top

API

Anything-in, Boolean-out.

Contributing

  • If you see an error, raise an issue.
  • If you want a new feature but can't code it up yourself, also raise an issue. Let's discuss it.
  • If you tried to use this package, but something didn't work out, also raise an issue. We'll try to help.
  • If you want to contribute some code, fork the monorepo via BitBucket, then write code, then file a pull request via BitBucket. We'll merge it in and release.

In monorepo, npm libraries are located in packages/ folder. Inside, the source code is located either in src/ folder (normal npm library) or in the root, cli.js (if it's a command line application).

The npm script "dev", the "dev": "rollup -c --dev --silent" builds the development version retaining all console.logs with row numbers. It's handy to have js-row-num-cli installed globally so you can automatically update the row numbers on all console.logs.

⬆ back to top

Licence

MIT License

Copyright (c) 2015-2019 Roy Revelt and other contributors