§ Quick Take

import { strict as assert } from "assert";
import { empty } from "ast-contains-only-empty-space";

assert.equal(
  empty({
    a: [
      {
        x: {
          y: [
            {
              z: ["\n"],
            },
          ],
        },
      },
    ],
    b: ["\t\t\t  "],
    c: ["\n \n\n"],
    d: ["\t   "],
  }),
  true
);

§ Examples

§ Purpose

Working with parsed HTML is always a battle against the white space. This program tells if given data structure is empty — containing only empty space or really empty.

By the way, weird things which don't belong to parsed structures (functions, for example) will yield a result false.

§ API

empty(something)

Input - anything. Output - Boolean.

This library does not mutate the input arguments.

§ Changelog

See it in the monorepo opens in a new tab, on GitHub.

§ Contributing

To report bugs or request features or assistance, raise an issue on GitHub opens in a new tab.

Any code contributions welcome! All Pull Requests will be dealt promptly.

§ Licence

MIT opens in a new tab

Copyright © 2010–2021 Roy Revelt and other contributors

Related packages:

📦 ast-get-values-by-key 3.0.16
Extract values and paths from AST by keys OR set them by keys
📦 ast-compare 2.0.16
Compare anything: AST, objects, arrays, strings and nested thereof
📦 ast-monkey-util 1.3.16
Utility library of AST helper functions
📦 ast-is-empty 2.0.16
Find out, is nested array/object/string/AST tree is empty
📦 ast-deep-contains 3.0.16
Like t.same assert on array of objects, where element order doesn't matter
📦 ast-loose-compare 2.0.16
Compare anything: AST, objects, arrays and strings
📦 ast-delete-object 2.0.16
Delete all plain objects in AST if they contain a certain key/value pair