Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unist-util-remove

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-remove - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

readme.md

66

index.js

@@ -1,44 +0,62 @@

'use strict';
'use strict'
var is = require('unist-util-is');
var is = require('unist-util-is')
module.exports = remove
module.exports = function (ast, opts, predicate) {
if (arguments.length == 2) {
predicate = opts;
opts = {};
function remove(ast, opts, test) {
var cascade
if (!test) {
test = opts
opts = {}
}
opts.cascade = opts.cascade || opts.cascade === undefined;
cascade = opts.cascade
cascade = cascade === null || cascade === undefined ? true : cascade
return preorder(ast, null, null)
// Check and remove nodes recursively in preorder.
// For each composite node, modify its children array in-place.
return (function preorder (node, nodeIndex, parent) {
if (is(predicate, node, nodeIndex, parent)) {
return null;
function preorder(node, nodeIndex, parent) {
var children
var length
var index
var position
var child
if (is(test, node, nodeIndex, parent)) {
return null
}
if (!node.children || !node.children.length) {
return node;
children = node.children
if (!children || children.length === 0) {
return node
}
// Move all living children to the beginning of the children array.
position = 0
length = children.length
index = -1
var length = 0;
while (++index < length) {
child = preorder(children[index], index, node)
for (var index = 0; index < node.children.length; ++index) {
var child = preorder(node.children[index], index, node);
if (child) {
node.children[length++] = child;
children[position++] = child
}
}
if (!length && opts.cascade) {
// Cascade delete.
return null;
// Cascade delete.
if (cascade && position === 0) {
return null
}
node.children.length = length;
return node;
}(ast, null, null));
};
// Drop other nodes.
children.length = position
return node
}
}
{
"name": "unist-util-remove",
"version": "1.0.0",
"version": "1.0.1",
"description": "Remove nodes from Unist tree",
"author": "Eugene Sharygin <eush77@gmail.com>",
"license": "MIT",
"scripts": {
"test": "tape test/*.js",
"cov": "nyc --reporter lcov tape test/*.js"
},
"files": [
"index.js"
],
"homepage": "https://github.com/eush77/unist-util-remove",
"repository": "eush77/unist-util-remove",
"bugs": {
"url": "https://github.com/eush77/unist-util-remove/issues"
},
"keywords": [

@@ -32,2 +19,12 @@ "ast",

],
"repository": "syntax-tree/unist-util-remove",
"bugs": "https://github.com/syntax-tree/unist-util-remove/issues",
"author": "Eugene Sharygin <eush77@gmail.com>",
"contributors": [
"Eugene Sharygin <eush77@gmail.com>",
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)"
],
"files": [
"index.js"
],
"dependencies": {

@@ -37,5 +34,44 @@ "unist-util-is": "^2.0.0"

"devDependencies": {
"nyc": "^12.0.1",
"prettier": "^1.13.3",
"remark-cli": "^5.0.0",
"remark-preset-wooorm": "^4.0.0",
"tape": "^4.4.0",
"unist-builder": "^1.0.0"
"unist-builder": "^1.0.0",
"xo": "^0.21.1"
},
"scripts": {
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run format && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"prettier": true,
"esnext": false,
"rules": {
"guard-for-in": "off",
"no-var": "off",
"prefer-arrow-callback": "off"
}
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
}
}
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