Socket
Socket
Sign inDemoInstall

unist-util-find

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-find - npm Package Compare versions

Comparing version 1.0.4 to 2.0.0

license

35

index.d.ts

@@ -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
/**
* @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

{
"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
}
}
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