unist-util-find
Advanced tools
Comparing version 1.0.2 to 1.0.3
39
index.js
@@ -7,21 +7,33 @@ /** | ||
* @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' | ||
import { visit } from 'unist-util-visit' | ||
import iteratee from 'lodash.iteratee' | ||
var visit = require('unist-util-visit') | ||
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') | ||
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,5 +50,2 @@ visit(tree, function (node) { | ||
/* | ||
* Expose. | ||
*/ | ||
module.exports = find | ||
export default find |
{ | ||
"name": "unist-util-find", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"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" | ||
"test": "standard && node test.js", | ||
"build": "tsc", | ||
"prepare": "npm run build", | ||
"release": "release-it" | ||
}, | ||
"engines": { | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
"type": "module", | ||
"keywords": [ | ||
@@ -24,10 +37,14 @@ "unist", | ||
"devDependencies": { | ||
"remark": "^7.0.0", | ||
"standard": "^8.0.0", | ||
"tape": "^4.6.0" | ||
"@types/lodash.iteratee": "^4.7.7", | ||
"@types/unist": "^2.0.6", | ||
"release-it": "^15.11.0", | ||
"remark": "^14.0.1", | ||
"standard": "^16.0.4", | ||
"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": "^4.1.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
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
6783
Yes
7
5
73
+ Added@types/unist@2.0.11(transitive)
+ Addedunist-util-is@5.2.1(transitive)
+ Addedunist-util-visit@4.1.2(transitive)
+ Addedunist-util-visit-parents@5.1.3(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@^4.1.0