Find out, is nested array/object/string/AST tree is empty
Table of Contents
npm i ast-is-empty
The default is exported, so instead of "
isEmpty" below, you can name the consumed function however you want.
Consume via a
const isEmpty = ;
or as an ES Module:
or for web pages, as a production-ready minified script file (so-called "UMD build"), straight from CDN:
// in which case you get a global variable "astIsEmpty" which you consume like this:const isEmpty = astIsEmpty;
This package has three builds in
|Main export - CommonJS version, transpiled to ES5, contains
|ES module build that Webpack/Rollup understands. Untranspiled ES6 code with
|UMD build for browsers, transpiled, minified, containing
Imagine, that you have a nested array which contains plain objects, arrays and strings. Huge tree. This library can tell if it consists of only empty things, by which I mean:
- Arrays or objects with no keys, or
- Arrays or objects that have all keys equal to zero-length strings
- Arrays or objects that have all keys equal to strings that
- Zero-length strings
- Or strings that would
.trim()to zero-length (this includes tabs, line breaks, spaces or mix thereof)
These are empty things, for example:
a: "";b:c:d: "";
a: ''b: c: d: '''''' '' ''
Practically speaking, when you work with AST's, all the mentioned empty things are a noise which probably doesn't need to be processed (or needs to be removed altogether).
Functions are not considered to be empty and this library will return
null if it encounters one anywhere within the
input. Same with as
null inputs — both will yield
Default function is exported.
Its API is "Anything-in, Boolean-out".
Also, when inappropriate things are given that don't belong to AST's,
;// => true||false||null
- 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 GitLab, then write code, then file a pull request on GitLab. 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": "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
Copyright (c) 2015-2019 Roy Revelt and other contributors