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-is-empty 3.0.1
Find out, is nested array/object/string/AST tree is empty
📦 ast-get-values-by-key 4.0.1
Extract values and paths from AST by keys OR set them by keys
📦 ast-delete-object 3.0.1
Delete all plain objects in AST if they contain a certain key/value pair
📦 ast-monkey-traverse-with-lookahead 3.0.1
Utility library to traverse AST, reports upcoming values
📦 ast-compare 3.0.1
Compare anything: AST, objects, arrays, strings and nested thereof
📦 ast-monkey-traverse 3.0.1
Utility library to traverse AST
📦 ast-monkey 8.0.1
Traverse and edit AST