ast-contains-only-empty-space1.10.1

Returns Boolean depending if passed AST contain only empty space

§ Quick Take

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

assert.equal(
  containsOnlyEmptySpace({
    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 Sourcehut.

§ Licence

MIT opens in a new tab

Copyright © 2010–2020 Roy Revelt and other contributors

Related packages:

📦 ast-get-object 1.10.1
Getter/setter for nested parsed HTML AST's, querying objects by key/value pairs
📦 ast-monkey-traverse 1.13.1
Utility library to traverse AST
📦 ast-monkey-traverse-with-lookahead 1.2.1
Utility library to traverse AST, reports upcoming values
📦 ast-deep-contains 2.0.1
Like t.same assert on array of objects, where element order doesn't matter
📦 ast-delete-object 1.10.1
Delete all plain objects in AST if they contain a certain key/value pair
📦 ast-compare 1.14.1
Compare anything: AST, objects, arrays, strings and nested thereof
📦 ast-monkey 7.12.1
Traverse and edit AST