unist-util-find
Advanced tools
Comparing version 1.0.2 to 1.0.4
37
index.js
@@ -7,6 +7,13 @@ /** | ||
* @fileoverview Unist node finder | ||
* | ||
* @typedef {import('unist').Node} Node | ||
* | ||
* @typedef {string} TestStr | ||
* Finds first node with a truthy property matching string. | ||
* @typedef {Object.<string, unknown>} TestObj | ||
* Finds first node that has matching values for all properties of object. | ||
* @typedef {<V extends Node>(node: V) => boolean} TestFn | ||
* Finds first node for which function returns true when passed node as argument. | ||
*/ | ||
'use strict' | ||
var visit = require('unist-util-visit') | ||
@@ -16,13 +23,18 @@ var iteratee = require('lodash.iteratee') | ||
/** | ||
* Find | ||
* Unist node finder utility. | ||
* | ||
* @param {Node} tree - Root node | ||
* @param {string|object|function} [condition] - Condition to match node. | ||
* @param tree | ||
* Node to search. | ||
* @param condition | ||
* Condition used to test each node. | ||
* @returns | ||
* The first node that matches condition, or undefined if no node matches. | ||
* @type {<V extends Node>(tree: Node, condition: TestStr | TestObj | TestFn) => V | undefined} | ||
*/ | ||
function find (tree, condition) { | ||
if (!tree) throw new Error('unist-find requires a tree to search') | ||
if (!condition) throw new Error('unist-find requires a condition') | ||
module.exports = function find (tree, condition) { | ||
if (!tree) throw new Error('unist-util-find requires a tree to search') | ||
if (!condition) throw new Error('unist-util-find requires a condition') | ||
var predicate = iteratee(condition) | ||
var result | ||
const predicate = iteratee(condition) | ||
let result | ||
@@ -38,6 +50,1 @@ visit(tree, function (node) { | ||
} | ||
/* | ||
* Expose. | ||
*/ | ||
module.exports = find |
{ | ||
"name": "unist-util-find", | ||
"version": "1.0.2", | ||
"version": "1.0.4", | ||
"description": "Unist node finder utility. Useful for working with remark, rehype and retext.", | ||
"repository": "https://github.com/blahah/unist-util-find", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"sideEffects": false, | ||
"scripts": { | ||
"test": "standard && node test.js" | ||
"prepack": "npm run build", | ||
"test": "standard && node test.js", | ||
"build": "tsc" | ||
}, | ||
"type": "commonjs", | ||
"keywords": [ | ||
@@ -24,10 +33,13 @@ "unist", | ||
"devDependencies": { | ||
"remark": "^7.0.0", | ||
"@types/lodash.iteratee": "^4.7.7", | ||
"@types/unist": "^2.0.6", | ||
"remark": "^13.0.0", | ||
"standard": "^8.0.0", | ||
"tape": "^4.6.0" | ||
"tape": "^5.3.1", | ||
"typescript": "^4.6.4" | ||
}, | ||
"dependencies": { | ||
"lodash.iteratee": "^4.5.0", | ||
"unist-util-visit": "^1.1.0" | ||
"lodash.iteratee": "^4.7.0", | ||
"unist-util-visit": "^2.0.0" | ||
} | ||
} |
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
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
6279
6
5
59
1
+ Added@types/unist@2.0.11(transitive)
+ Addedunist-util-is@4.1.0(transitive)
+ Addedunist-util-visit@2.0.3(transitive)
+ Addedunist-util-visit-parents@3.1.1(transitive)
- Removedunist-util-is@3.0.0(transitive)
- Removedunist-util-visit@1.4.1(transitive)
- Removedunist-util-visit-parents@2.1.2(transitive)
Updatedlodash.iteratee@^4.7.0
Updatedunist-util-visit@^2.0.0