unist-util-find
Advanced tools
Comparing version 1.0.4 to 2.0.0
@@ -1,17 +0,30 @@ | ||
declare const _exports: <V extends import("unist").Node<import("unist").Data>>(tree: Node, condition: TestStr | TestObj | TestFn) => V | undefined; | ||
export = _exports; | ||
export type Node = import('unist').Node; | ||
/** | ||
* Finds first node with a truthy property matching string. | ||
* Find a node in `tree` matching `condition`. | ||
* | ||
* @template {Node} V | ||
* Node to search for. | ||
* @param {Node} tree | ||
* Tree to search in. | ||
* @param {TestFn | TestObj | TestStr} condition | ||
* Condition used to test each node, which matches `V`. | ||
* @returns {V | undefined} | ||
* The first node that matches condition, or `undefined` if no node matches. | ||
*/ | ||
export type TestStr = string; | ||
export function find<V extends import('unist').Node<import('unist').Data>>( | ||
tree: Node, | ||
condition: TestFn | TestObj | TestStr | ||
): V | undefined | ||
export type Node = import('unist').Node | ||
/** | ||
* Finds first node that has matching values for all properties of object. | ||
* Find the first node for which function returns `true` when passed node as | ||
* argument. | ||
*/ | ||
export type TestObj = { | ||
[x: string]: unknown; | ||
}; | ||
export type TestFn = (node: Node) => boolean | ||
/** | ||
* Finds first node for which function returns true when passed node as argument. | ||
* Find the first node that has matching values for all properties of object. | ||
*/ | ||
export type TestFn = <V extends import("unist").Node<import("unist").Data>>(node: V) => boolean; | ||
export type TestObj = Record<string, unknown> | ||
/** | ||
* Find the first node with a truthy property matching `string`. | ||
*/ | ||
export type TestStr = string |
50
index.js
/** | ||
* @author Richard Smith-Unna | ||
* @copyright 2016 Richard Smith-Unnar | ||
* @license MIT | ||
* @module unist:find | ||
* @fileoverview Unist node finder | ||
* | ||
* @typedef {import('unist').Node} Node | ||
*/ | ||
/** | ||
* @callback TestFn | ||
* Find the first node for which function returns `true` when passed node as | ||
* argument. | ||
* @param {Node} node | ||
* Node to check. | ||
* @returns {boolean} | ||
* Whether `node` matches your condition. | ||
* | ||
* @typedef {Record<string, unknown>} TestObj | ||
* Find the first node that has matching values for all properties of object. | ||
* | ||
* @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. | ||
* Find the first node with a truthy property matching `string`. | ||
*/ | ||
var visit = require('unist-util-visit') | ||
var iteratee = require('lodash.iteratee') | ||
import {visit} from 'unist-util-visit' | ||
import iteratee from 'lodash.iteratee' | ||
/** | ||
* Unist node finder utility. | ||
* Find a node in `tree` matching `condition`. | ||
* | ||
* @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} | ||
* @template {Node} V | ||
* Node to search for. | ||
* @param {Node} tree | ||
* Tree to search in. | ||
* @param {TestFn | TestObj | TestStr} condition | ||
* Condition used to test each node, which matches `V`. | ||
* @returns {V | undefined} | ||
* The first node that matches condition, or `undefined` if no node matches. | ||
*/ | ||
module.exports = function find (tree, condition) { | ||
export function find(tree, condition) { | ||
if (!tree) throw new Error('unist-util-find requires a tree to search') | ||
@@ -37,2 +41,3 @@ if (!condition) throw new Error('unist-util-find requires a condition') | ||
const predicate = iteratee(condition) | ||
/** @type {V | undefined} */ | ||
let result | ||
@@ -42,2 +47,3 @@ | ||
if (predicate(node)) { | ||
// @ts-expect-error: assume `predicate` checks for `V`. | ||
result = node | ||
@@ -44,0 +50,0 @@ return false |
107
package.json
{ | ||
"name": "unist-util-find", | ||
"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": { | ||
"prepack": "npm run build", | ||
"test": "standard && node test.js", | ||
"build": "tsc" | ||
}, | ||
"type": "commonjs", | ||
"version": "2.0.0", | ||
"description": "unist utility to find a node", | ||
"license": "MIT", | ||
"keywords": [ | ||
"unist", | ||
"remark", | ||
"retext", | ||
"rehype", | ||
"find", | ||
"hast", | ||
"mdast", | ||
"nlcst", | ||
"find", | ||
"search" | ||
"node", | ||
"rehype", | ||
"remark", | ||
"retext", | ||
"search", | ||
"unist", | ||
"unist-util", | ||
"util", | ||
"utility" | ||
], | ||
"repository": "syntax-tree/unist-util-find", | ||
"bugs": "https://github.com/syntax-tree/unist-util-find/issues", | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/unified" | ||
}, | ||
"author": "Richard Smith-Unna <rik@fathomlabs.io> @blahah", | ||
"license": "MIT", | ||
"contributors": [ | ||
"Richard Smith-Unna <rik@fathomlabs.io> @blahah", | ||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)" | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"files": [ | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"@types/unist": "^2.0.0", | ||
"lodash.iteratee": "^4.0.0", | ||
"unist-util-visit": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/lodash.iteratee": "^4.7.7", | ||
"@types/unist": "^2.0.6", | ||
"remark": "^13.0.0", | ||
"standard": "^8.0.0", | ||
"tape": "^5.3.1", | ||
"typescript": "^4.6.4" | ||
"@types/lodash.iteratee": "^4.0.0", | ||
"@types/tape": "^5.0.0", | ||
"c8": "^8.0.0", | ||
"mdast-util-from-markdown": "^1.0.0", | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^11.0.0", | ||
"remark-preset-wooorm": "^9.0.0", | ||
"tape": "^5.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^5.0.0", | ||
"xo": "^0.54.0" | ||
}, | ||
"dependencies": { | ||
"lodash.iteratee": "^4.7.0", | ||
"unist-util-visit": "^2.0.0" | ||
"scripts": { | ||
"prepack": "npm run build && npm run format", | ||
"build": "tsc --build --clean && tsc --build && type-coverage", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node --conditions development test.js", | ||
"test-coverage": "c8 --100 --reporter lcov npm run test-api", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
}, | ||
"prettier": { | ||
"bracketSpacing": false, | ||
"semi": false, | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "none", | ||
"useTabs": false | ||
}, | ||
"remarkConfig": { | ||
"plugins": [ | ||
"remark-preset-wooorm" | ||
] | ||
}, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"ignoreCatch": true, | ||
"strict": true | ||
}, | ||
"xo": { | ||
"prettier": true | ||
} | ||
} |
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 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
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 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
11865
77
276
0
Yes
3
11
+ Added@types/unist@^2.0.0
+ 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@4.1.0(transitive)
- Removedunist-util-visit@2.0.3(transitive)
- Removedunist-util-visit-parents@3.1.1(transitive)
Updatedlodash.iteratee@^4.0.0
Updatedunist-util-visit@^4.0.0