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 tree is empty

  • 2.1.2
  • Source
  • npm
  • Socket score

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

posthtml-ast-is-empty

Standard JavaScript

Find out, is nested array/object/string tree (like PostHTML-parsed AST) is empty

Link to npm page Build Status bitHound Overall Score bitHound Dependencies bitHound Dev Dependencies Coverage Status Known Vulnerabilities Downloads/Month View dependencies as 2D chart Test in browser

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 install --save posthtml-ast-is-empty

Use

// require first:
var isEmpty = require('posthtml-ast-is-empty')
...
// then, for example, feed a parsed HTML tree into it:
console.log(isEmpty(htmlAstObj))

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.

API

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

Testing

$ npm test

Unit tests use AVA, Istanbul CLI (to count test coverage) and, of course, JS Standard notation.

Contributing

All contributions are welcome. Please stick to Standard JavaScript notation and supplement the test.js with new unit tests covering your feature(s).

If you see anything incorrect whatsoever, do raise an issue. If you file a pull request, I'll do my best to help you to get it merged soon. If you have any comments on the code, including ideas how to improve things, don't hesitate to contact me by email.

Licence

MIT License (MIT)

Copyright (c) 2017 Codsen Ltd, Roy Revelt

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Package last updated on 07 Sep 2017

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