unist-util-remove
Advanced tools
Comparing version 1.0.0 to 1.0.1
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" | ||
] | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
6355
46
107
0
7
1
1