Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
ast-contains-only-empty-space
Advanced tools
Returns Boolean depending if passed AST contain only empty space
Returns Boolean depending if passed AST contain only empty space
npm i ast-contains-only-empty-space
// consume via CommonJS require():
const containsOnlyEmptySpace = require("ast-contains-only-empty-space");
// or as an ES Module:
import containsOnlyEmptySpace from "ast-contains-only-empty-space";
Here's what you'll get:
Type | Key in package.json | Path | Size |
---|---|---|---|
Main export - CommonJS version, transpiled to ES5, contains require and module.exports | main | dist/ast-contains-only-empty-space.cjs.js | 1 KB |
ES module build that Webpack/Rollup understands. Untranspiled ES6 code with import /export . | module | dist/ast-contains-only-empty-space.esm.js | 961 B |
UMD build for browsers, transpiled, minified, containing iife 's and has all dependencies baked-in | browser | dist/ast-contains-only-empty-space.umd.js | 12 KB |
const empty = require('ast-contains-only-empty-space')
...
// All values are empty, this means this object contains only empty space.
// Notice it's nested in an array, it does not matter.
console.log(empty([{ 'content': {} }]))
// => true
console.log(empty([{ 'tag': 'style' }]))
// => false
// Works on simple arrays as well:
console.log(empty([' ', ' ']))
// => true
// Works on strings as well:
console.log(empty(' '))
// => true
// Object keys that have values as null are considered empty:
console.log(empty({a: null}))
// => true
// Works no matter how deeply nested input is:
console.log(empty(
{
a: [{
x: {
y: [
{
z: [
'\n'
]
}
]
}
}],
b: ['\t\t\t '],
c: ['\n \n\n'],
d: ['\t ']
}
))
// => true
Working with parsed HTML is always a battle against the white space. Often you need to know, does certain AST piece (object/array/whatever) contain anything real, or just an empty space. That's what this library is for.
In real life, parsed HTML trees will have many levels of nested arrays, objects and strings. While it's easy to check does a plain object contain only empty space ('\n'
, ' '
, '\t'
, line break or a mix of thereof), it's not so easy when your object has arrays of empty objects. I want a solid, tested library which can identify emptiness (or lack of) in anything, nested or not nested.
By the way, weird things (like functions, which don't belong to parsed HTML structures) will yield a result false
.
Input - anything. Output - Boolean.
empty(input); // array, object or string — normally AST (which is array of nested objects/strings/arrays)
// => true/false
This library does not mutate the input arguments.
In monorepo, npm libraries are located in packages/
folder. Inside, the source code is located either in src/
folder (normal npm library) or in the root, cli.js
(if it's a command line application).
The npm script "dev
", the "dev": "rollup -c --dev --silent"
builds the development version retaining all console.log
s with row numbers. It's handy to have js-row-num-cli installed globally so you can automatically update the row numbers on all console.log
s.
MIT License
Copyright (c) 2015-2019 Roy Revelt and other contributors
FAQs
Does AST contain only empty space?
The npm package ast-contains-only-empty-space receives a total of 106 weekly downloads. As such, ast-contains-only-empty-space popularity was classified as not popular.
We found that ast-contains-only-empty-space demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.