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.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
21
increased by950%
Maintainers
1
Weekly downloads
 
Created
Source

posthtml-ast-is-empty

ESLint on airbnb-base with caveats

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

Minimum Node version required Link to npm page Build Status Coverage bitHound Overall Score bitHound Dependencies View dependencies as 2D chart bitHound Dev Dependencies Known Vulnerabilities Downloads/Month Test in browser 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.js893 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

Hi! 99% of people in the society are passive - consumers. They wait for others to take action, they prefer to blend in. The remaining 1% are proactive citizens who will do something rather than wait. If you are one of that 1%, you're in luck because I am the same and together we can make something happen.

  • If you want a new feature in this package or you would like to change some of its functionality, raise an issue on this repo. Also, you can email me. Just let it out.

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

  • If you don't like the code in here and would like to give advice about how something could be done better, please do. Same drill - GitHub issues or email, your choice.

  • If you would like to add or change some features, just fork it, hack away, and file a pull request. I'll do my best to merge it quickly. Code style is airbnb-base, only without semicolons. If you use a good code editor, it will pick up the established ESLint setup.

⬆  back to top

Licence

MIT License (MIT)

Copyright © 2018 Codsen Ltd, Roy Revelt

Keywords

FAQs

Package last updated on 14 Jan 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