{"_id":"mdast-util-find-and-replace@3.0.3","bugs":{"url":"https://github.com/syntax-tree/mdast-util-find-and-replace/issues"},"dist":{"shasum":"5c3ab1d8f9827285dfa71f1deba6de6b8b154e5b","tarball":"http://registry-npm.ywwl.com/mdast-util-find-and-replace/download/mdast-util-find-and-replace-3.0.3.tgz","fileCount":9,"integrity":"sha512-xPgpDNl0/OXHsI7TlaIs22lWnH3KlpvZdXG1ET/m/YT2Hhdkx8lJV4kLphE6l9simyM4KPDFBwas08BgEob6Jw==","signatures":[{"sig":"MEQCIAkoEEwJ2w0U+hUZR8Lx6C8L+Z8QvxSSnpYeH7mByR3WAiACBwFLLf2/lzWx2jZrc531+DfiLMcUF5znG7fw4XT11g==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDp+eFzQVuEpjVgDpJHez1VtLmmxenolQ8JpO/kvjvEmAIhAPETT45xkVKFSbNFResKBZ9HLHah3cNJTvES1wB/g/vI"}],"unpackedSize":23753,"size":7587,"noattachment":false,"key":"/mdast-util-find-and-replace/-/mdast-util-find-and-replace-3.0.3.tgz"},"name":"mdast-util-find-and-replace","type":"module","types":"./index.d.ts","author":{"url":"https://wooorm.com","name":"Titus Wormer","email":"tituswormer@gmail.com"},"exports":"./index.js","funding":{"url":"https://opencollective.com/unified","type":"opencollective"},"gitHead":"6c4850c7c0d714886e3e2a8ae0a26bed736b3dbd","license":"MIT","scripts":{"test":"npm run build && npm run format && npm run test-coverage","build":"tsc --build --clean && tsc --build && type-coverage","format":"remark --frail --output --quiet -- . && prettier --log-level warn --write -- . && xo --fix","test-api":"node --conditions development test.js","test-coverage":"c8 --100 --reporter lcov -- npm run test-api"},"version":"3.0.3","_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"homepage":"https://github.com/syntax-tree/mdast-util-find-and-replace#readme","keywords":["find","markdown","mdast-util","mdast","unist","utility","util","replace"],"prettier":{"semi":false,"useTabs":false,"tabWidth":2,"singleQuote":true,"trailingComma":"none","bracketSpacing":false},"repository":{"url":"git+https://github.com/syntax-tree/mdast-util-find-and-replace.git","type":"git"},"_npmVersion":"12.0.2","description":"mdast utility to find and replace text in a tree","directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"},{"name":"kmck","email":"keith@mcknig.ht"}],"sideEffects":false,"_nodeVersion":"26.3.0","contributors":[{"url":"https://wooorm.com","name":"Titus Wormer","email":"tituswormer@gmail.com"}],"dependencies":{"@types/mdast":"^4.0.0","unist-util-is":"^6.0.0","escape-string-regexp":"^5.0.0","unist-util-visit-parents":"^6.0.0"},"remarkConfig":{"plugins":["remark-preset-wooorm"]},"typeCoverage":{"strict":true,"atLeast":100,"ignoreFiles":["lib/index.d.ts"]},"_hasShrinkwrap":false,"devDependencies":{"c8":"^12.0.0","xo":"^5.0.0","prettier":"^3.0.0","remark-cli":"^12.0.0","typescript":"^6.0.0","@types/node":"^26.0.0","type-coverage":"^2.0.0","remark-preset-wooorm":"^11.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/mdast-util-find-and-replace_3.0.3_1791106124891_0.11499524434013253"},"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<script type=\"module\">\n  import {findAndReplace} from 'https://esm.sh/mdast-util-find-and-replace@3?bundle'\n</script>\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```text\nparagraph[6]\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 \" or \"\n├─4 strong[1]\n│   └─0 text \"strong\"\n└─5 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<FindAndReplaceTuple>\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<Node>`][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<string>`)\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<Node>`, 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`][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<!-- Definition -->\n\n[api-find]: #find\n\n[api-find-and-replace]: #findandreplacetree-list-options\n\n[api-find-and-replace-list]: #findandreplacelist\n\n[api-find-and-replace-tuple]: #findandreplacetuple\n\n[api-options]: #options\n\n[api-regexp-match-object]: #regexpmatchobject\n\n[api-replace]: #replace\n\n[api-replace-function]: #replacefunction\n\n[author]: https://wooorm.com\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[build]: https://github.com/syntax-tree/mdast-util-find-and-replace/actions\n\n[build-badge]: https://github.com/syntax-tree/mdast-util-find-and-replace/workflows/main/badge.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[collective]: https://opencollective.com/unified\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[coverage]: https://codecov.io/github/syntax-tree/mdast-util-find-and-replace\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-find-and-replace.svg\n\n[downloads]: https://www.npmjs.com/package/mdast-util-find-and-replace\n\n[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-find-and-replace.svg\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[hast]: https://github.com/syntax-tree/hast\n\n[hast-util-find-and-replace]: https://github.com/syntax-tree/hast-util-find-and-replace\n\n[health]: https://github.com/syntax-tree/.github\n\n[license]: license\n\n[mdast]: https://github.com/syntax-tree/mdast\n\n[node]: https://github.com/syntax-tree/mdast#nodes\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[preorder]: https://github.com/syntax-tree/unist#preorder\n\n[size]: https://bundlejs.com/?q=mdast-util-find-and-replace\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-find-and-replace\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[test]: https://github.com/syntax-tree/unist-util-is#api\n\n[text]: https://github.com/syntax-tree/mdast#text\n\n[typescript]: https://www.typescriptlang.org\n\n[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n","publish_time":1791106124981,"_cnpm_publish_time":1791106124981,"dist-tags":{"latest":"3.0.4"}}