ast-is-empty1.10.10

Find out, is nested array/object/string/AST tree is empty

§ Quick Take

import { strict as assert } from "assert";
import isEmpty from "ast-is-empty";

assert.equal(
  isEmpty({
    a: "",
  }),
  true
);

assert.equal(
  isEmpty({
    a: [""],
    b: {
      c: {
        d: "",
      },
    },
  }),
  true
);

assert.equal(
  isEmpty([
    {
      a: [""],
      b: { c: { d: "" } },
    },
    "",
    ["", "", ""],
  ]),
  true
);

§ Rationale

Sometimes we need to check, does given AST contain only empty structures:

  • empty strings (those that trim to zero length)
  • arrays containing zero or more keys containing empty structures
  • plain objects with containing zero or more keys containing empty structures

This program helps with that.

§ API

isEmpty(something)

In other words, it's a function which takes one input argument which can be of any type.

It returns boolean or null (in case of non-AST structure, like a function).

§ Licence

MIT opens in a new tab

Copyright © 2010–2020 Roy Revelt and other contributors

Related packages:

📦 ast-delete-object 1.9.2
Delete all plain objects in AST if they contain a certain key/value pair
📦 ast-compare 1.13.19
Compare anything: AST, objects, arrays, strings and nested thereof
📦 ast-get-object 1.9.18
Getter/setter for nested parsed HTML AST's, querying objects by key/value pairs
📦 ast-deep-contains 1.1.21
Like t.same assert on array of objects, where element order doesn't matter.
📦 ast-monkey-traverse 1.12.20
Utility library to traverse AST
📦 ast-monkey-traverse-with-lookahead 1.1.12
Utility library to traverse AST, reports upcoming values
📦 ast-monkey-util 1.1.11
Utility library of AST helper functions