{"id":13339493,"url":"https://github.com/syntax-tree/mdast-util-find-and-replace","last_synced_at":"2026-02-03T19:14:33.646Z","repository":{"id":43380536,"uuid":"304857459","full_name":"syntax-tree/mdast-util-find-and-replace","owner":"syntax-tree","description":"mdast utility to find and replace text in a tree","archived":false,"fork":false,"pushed_at":"2025-01-03T12:27:33.000Z","size":147,"stargazers_count":12,"open_issues_count":0,"forks_count":4,"subscribers_count":7,"default_branch":"main","last_synced_at":"2026-01-28T00:58:51.305Z","etag":null,"topics":["find","markdown","mdast","mdast-util","replace","search","unist"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syntax-tree.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"unifiedjs","open_collective":"unified","thanks_dev":"u/gh/syntax-tree"}},"created_at":"2020-10-17T10:58:59.000Z","updated_at":"2025-12-04T02:04:06.000Z","dependencies_parsed_at":"2024-06-18T15:27:08.211Z","dependency_job_id":"76b02418-227d-4154-b7d6-a85ab5c30f0f","html_url":"https://github.com/syntax-tree/mdast-util-find-and-replace","commit_stats":{"total_commits":63,"total_committers":4,"mean_commits":15.75,"dds":0.06349206349206349,"last_synced_commit":"af7d1effa7a3fd1bf124150e509a1faa956790c0"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/mdast-util-find-and-replace","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-find-and-replace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-find-and-replace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-find-and-replace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-find-and-replace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/mdast-util-find-and-replace/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-find-and-replace/sbom","scorecard":{"id":863477,"data":{"date":"2025-08-11","repo":{"name":"github.com/syntax-tree/mdast-util-find-and-replace","commit":"fd73ef856ab4f7b6326e3255aea36f439b75e2d5"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.1,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: third-party GitHubAction not pinned by hash: .github/workflows/bb.yml:5: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/mdast-util-find-and-replace/bb.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:6: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/mdast-util-find-and-replace/main.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:7: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/mdast-util-find-and-replace/main.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/mdast-util-find-and-replace/main.yml/main?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/main.yml:11","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned","Info:   0 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Code-Review","score":0,"reason":"Found 1/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/bb.yml:1","Warn: no topLevel permission defined: .github/workflows/main.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: license:0","Info: FSF or OSI recognized license: MIT License: license:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/syntax-tree/.github/security.md:1","Info: Found linked content: github.com/syntax-tree/.github/security.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/syntax-tree/.github/security.md:1","Info: Found text in security policy: github.com/syntax-tree/.github/security.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 1 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-24T02:00:48.429Z","repository_id":43380536,"created_at":"2025-08-24T02:00:48.429Z","updated_at":"2025-08-24T02:00:48.429Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29054204,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T15:43:47.601Z","status":"ssl_error","status_checked_at":"2026-02-03T15:43:46.709Z","response_time":96,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["find","markdown","mdast","mdast-util","replace","search","unist"],"created_at":"2024-07-29T19:20:04.121Z","updated_at":"2026-02-03T19:14:30.059Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","readme":"# mdast-util-find-and-replace\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[mdast][] utility to find and replace things.\n\n## Contents\n\n* [What is this?](#what-is-this)\n* [When should I use this?](#when-should-i-use-this)\n* [Install](#install)\n* [Use](#use)\n* [API](#api)\n  * [`findAndReplace(tree, list[, options])`](#findandreplacetree-list-options)\n  * [`Find`](#find)\n  * [`FindAndReplaceList`](#findandreplacelist)\n  * [`FindAndReplaceTuple`](#findandreplacetuple)\n  * [`Options`](#options)\n  * [`RegExpMatchObject`](#regexpmatchobject)\n  * [`Replace`](#replace)\n  * [`ReplaceFunction`](#replacefunction)\n* [Types](#types)\n* [Compatibility](#compatibility)\n* [Security](#security)\n* [Related](#related)\n* [Contribute](#contribute)\n* [License](#license)\n\n## What is this?\n\nThis package is a utility that lets you find patterns (`string`, `RegExp`) in\ntext and replace them with nodes.\n\n## When should I use this?\n\nThis utility is typically useful when you have regexes and want to modify mdast.\nOne example is when you have some form of “mentions” (such as\n`/@([a-z][_a-z0-9])\\b/gi`) and want to create links to persons from them.\n\nA similar package, [`hast-util-find-and-replace`][hast-util-find-and-replace]\ndoes the same but on [hast][].\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install mdast-util-find-and-replace\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {findAndReplace} from 'https://esm.sh/mdast-util-find-and-replace@3'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {findAndReplace} from 'https://esm.sh/mdast-util-find-and-replace@3?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport {findAndReplace} from 'mdast-util-find-and-replace'\nimport {u} from 'unist-builder'\nimport {inspect} from 'unist-util-inspect'\n\nconst tree = u('paragraph', [\n  u('text', 'Some '),\n  u('emphasis', [u('text', 'emphasis')]),\n  u('text', ' and '),\n  u('strong', [u('text', 'importance')]),\n  u('text', '.')\n])\n\nfindAndReplace(tree, [\n  [/and/gi, 'or'],\n  [/emphasis/gi, 'em'],\n  [/importance/gi, 'strong'],\n  [\n    /Some/g,\n    function ($0) {\n      return u('link', {url: '//example.com#' + $0}, [u('text', $0)])\n    }\n  ]\n])\n\nconsole.log(inspect(tree))\n```\n\nYields:\n\n```txt\nparagraph[8]\n├─0 link[1]\n│   │ url: \"//example.com#Some\"\n│   └─0 text \"Some\"\n├─1 text \" \"\n├─2 emphasis[1]\n│   └─0 text \"em\"\n├─3 text \" \"\n├─4 text \"or\"\n├─5 text \" \"\n├─6 strong[1]\n│   └─0 text \"strong\"\n└─7 text \".\"\n```\n\n## API\n\nThis package exports the identifier [`findAndReplace`][api-find-and-replace].\nThere is no default export.\n\n### `findAndReplace(tree, list[, options])`\n\nFind patterns in a tree and replace them.\n\nThe algorithm searches the tree in *[preorder][]* for complete values in\n[`Text`][text] nodes.\nPartial matches are not supported.\n\n###### Parameters\n\n* `tree` ([`Node`][node])\n  — tree to change\n* `list` ([`FindAndReplaceList`][api-find-and-replace-list] or\n  [`FindAndReplaceTuple`][api-find-and-replace-tuple])\n  — one or more find-and-replace pairs\n* `options` ([`Options`][api-options])\n  — configuration\n\n###### Returns\n\nNothing (`undefined`).\n\n### `Find`\n\nPattern to find (TypeScript type).\n\nStrings are escaped and then turned into global expressions.\n\n###### Type\n\n```ts\ntype Find = RegExp | string\n```\n\n### `FindAndReplaceList`\n\nSeveral find and replaces, in array form (TypeScript type).\n\n###### Type\n\n```ts\ntype FindAndReplaceList = Array\u003cFindAndReplaceTuple\u003e\n```\n\nSee [`FindAndReplaceTuple`][api-find-and-replace-tuple].\n\n### `FindAndReplaceTuple`\n\nFind and replace in tuple form (TypeScript type).\n\n###### Type\n\n```ts\ntype FindAndReplaceTuple = [Find, Replace?]\n```\n\nSee [`Find`][api-find] and [`Replace`][api-replace].\n\n### `Options`\n\nConfiguration (TypeScript type).\n\n###### Fields\n\n* `ignore` ([`Test`][test], optional)\n  — test for which elements to ignore\n\n### `RegExpMatchObject`\n\nInfo on the match (TypeScript type).\n\n###### Fields\n\n* `index` (`number`)\n  — the index of the search at which the result was found\n* `input` (`string`)\n  — a copy of the search string in the text node\n* `stack` ([`Array\u003cNode\u003e`][node])\n  — all ancestors of the text node, where the last node is the text itself\n\n### `Replace`\n\nThing to replace with (TypeScript type).\n\n###### Type\n\n```ts\ntype Replace = ReplaceFunction | string\n```\n\nSee [`ReplaceFunction`][api-replace-function].\n\n### `ReplaceFunction`\n\nCallback called when a search matches (TypeScript type).\n\n###### Parameters\n\nThe parameters are the result of corresponding search expression:\n\n* `value` (`string`)\n  — whole match\n* `...capture` (`Array\u003cstring\u003e`)\n  — matches from regex capture groups\n* `match` ([`RegExpMatchObject`][api-regexp-match-object])\n  — info on the match\n\n###### Returns\n\nThing to replace with:\n\n* when `null`, `undefined`, `''`, remove the match\n* …or when `false`, do not replace at all\n* …or when `string`, replace with a text node of that value\n* …or when `Node` or `Array\u003cNode\u003e`, replace with those nodes\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`Find`][api-find],\n[`FindAndReplaceList`][api-find-and-replace-list],\n[`FindAndReplaceTuple`][api-find-and-replace-tuple],\n[`Options`][api-options],\n[`RegExpMatchObject`][api-regexp-match-object],\n[`Replace`][api-replace], and\n[`ReplaceFunction`][api-replace-function].\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line,\n`mdast-util-find-and-replace@^3`, compatible with Node.js 16.\n\n## Security\n\nUse of `mdast-util-find-and-replace` does not involve [hast][] or user content\nso there are no openings for [cross-site scripting (XSS)][xss] attacks.\n\n## Related\n\n* [`hast-util-find-and-replace`](https://github.com/syntax-tree/hast-util-find-and-replace)\n  — find and replace in hast\n* [`hast-util-select`](https://github.com/syntax-tree/hast-util-select)\n  — `querySelector`, `querySelectorAll`, and `matches`\n* [`unist-util-select`](https://github.com/syntax-tree/unist-util-select)\n  — select unist nodes with CSS-like selectors\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organisation, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definition --\u003e\n\n[build-badge]: https://github.com/syntax-tree/mdast-util-find-and-replace/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/mdast-util-find-and-replace/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-find-and-replace.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/mdast-util-find-and-replace\n\n[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-find-and-replace.svg\n\n[downloads]: https://www.npmjs.com/package/mdast-util-find-and-replace\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=mdast-util-find-and-replace\n\n[size]: https://bundlejs.com/?q=mdast-util-find-and-replace\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[typescript]: https://www.typescriptlang.org\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[hast]: https://github.com/syntax-tree/hast\n\n[mdast]: https://github.com/syntax-tree/mdast\n\n[node]: https://github.com/syntax-tree/mdast#nodes\n\n[preorder]: https://github.com/syntax-tree/unist#preorder\n\n[text]: https://github.com/syntax-tree/mdast#text\n\n[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n\n[test]: https://github.com/syntax-tree/unist-util-is#api\n\n[hast-util-find-and-replace]: https://github.com/syntax-tree/hast-util-find-and-replace\n\n[api-find-and-replace]: #findandreplacetree-list-options\n\n[api-options]: #options\n\n[api-find]: #find\n\n[api-replace]: #replace\n\n[api-replace-function]: #replacefunction\n\n[api-find-and-replace-list]: #findandreplacelist\n\n[api-find-and-replace-tuple]: #findandreplacetuple\n\n[api-regexp-match-object]: #regexpmatchobject\n","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified","https://thanks.dev/u/gh/syntax-tree"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fmdast-util-find-and-replace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Fmdast-util-find-and-replace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fmdast-util-find-and-replace/lists"}