New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

posthtml-ast-is-empty

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

posthtml-ast-is-empty

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

  • 3.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

posthtml-ast-is-empty

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

Minimum Node version required Build Status Coverage bitHound Overall Score bitHound Dependencies View dependencies as 2D chart bitHound Dev Dependencies Known Vulnerabilities Downloads/Month Test in browser Code style: prettier MIT License

This is not a PostHTML plugin but a regular JS library. It is meant to work with anything, including nested array/object trees, like parsed HTML, that is, AST (abstract syntax trees) that come out of the PostHTML-parser. Hence the name, posthtml-ast-.

Table of Contents

Install

npm i posthtml-ast-is-empty
// consume as CommonJS require:
const isEmpty = require("posthtml-ast-is-empty");
// or as a ES Module:
import isEmpty from "posthtml-ast-is-empty";
// then, for example, feed a parsed HTML tree into it:
console.log(isEmpty(htmlAstObj));

Here's what you'll get:

TypeKey in package.jsonPathSize
Main export - CommonJS version, transpiled to ES5, contains require and module.exportsmaindist/posthtml-ast-is-empty.cjs.js1 KB
ES module build that Webpack/Rollup understands. Untranspiled ES6 code with import/export.moduledist/posthtml-ast-is-empty.esm.js875 B
UMD build for browsers, transpiled, minified, containing iife's and has all dependencies baked-inbrowserdist/posthtml-ast-is-empty.umd.js1 KB

⬆  back to top

Rationale

Imagine, that you have a nested array which contains plain objects, arrays and strings. Huge tree. This library can tell if it consists of only empty things.

These are empty things, for example:

{
  a: "";
}

or

{
  a: [""];
  b: {
    c: {
      d: "";
    }
  }
}

or

[
  {
    a: ['']
    b: {c: {d: ''}}
  },
  '',
  ['', '', '']
]

Here's how we judge if things are empty:

  • Plain object is empty if each of its keys has empty string or a nested tree of empty things (arrays/plain objects/strings) OR if it has no keys
  • Array is empty if each of its elements has empty string or a nested tree of empty things(arrays/plain objects/strings) OR if it has no elements
  • A string is empty if it's equal to ''.

Functions are not considered to be empty and this library will return null if it encounters one anywhere within the input. Same with as undefined or null inputs.

⬆  back to top

API

Anything-in, Boolean-out.

isEmpty(
  input // AST tree, or object or array or whatever. Can be deeply-nested.
);
// => true||false

Contributing

  • If you want a new feature in this package or you would like us to change some of its functionality, raise an issue on this repo.

  • If you tried to use this library but it misbehaves, or you need advice setting it up, and its readme doesn't make sense, just document it and raise an issue on this repo.

  • If you would like to add or change some features, just fork it, hack away, and file a pull request. We'll do our best to merge it quickly. Prettier is enabled, so you don't need to worry about the code style.

⬆  back to top

Licence

MIT License (MIT)

Copyright © 2018 Codsen Ltd, Roy Revelt

Keywords

FAQs

Package last updated on 26 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc