posthtml-ast-is-empty

Find out, is nested array/object/string tree (like PostHTML-parsed AST) is empty

Install
$ npm install --save posthtml-ast-is-empty
Use
var isEmpty = require('posthtml-ast-is-empty')
...
console.log(isEmpty(htmlAstObj))
Test
$ npm test
Uses AVA.
Rationale
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.
Here's how we judge if things are empty:
- Plain object is empty if each of its keys has empty string or a nested tree of empty things (arrays/plain objects/strings) OR if it has no keys
- Array is empty if each of its elements has empty string or a nested tree of empty things(arrays/plain objects/strings) OR if it has no elements
- A string is empty if it's equal to
''
.
Functions are not considered to be empty and this library will throw if it encounters one anywhere within the input
.
API
isEmpty (
input
);
Contributing & testing
All contributions welcome. This library uses Standard JavaScript notation. See test.js
. It's very minimalistic testing setup using AVA.
npm test
If you see anything incorrect whatsoever, raise an issue. PR's welcome too.
Licence
MIT © Roy Reveltas