Installation
1. Install the latest version with yarn:
yarn add ast-is-empty
or with npm:
npm install ast-is-empty
2. Import it in your code:
import { isEmpty, version } from "ast-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
);
Purpose
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()
The main function isEmpty()
is imported like this:
import { isEmpty } from "ast-is-empty";
It’s a function which takes one input arguments, of any type:
function isEmpty (input: any): boolean | null;
It returns boolean or null
(in case of non-AST structure, like a function).
API — version
You can import version
:
import { version } from "ast-is-empty";
console.log(version);
// => "4.0.3"