🎉 initiate project *astro_rewrite*

This commit is contained in:
sindrekjelsrud 2023-07-19 21:31:30 +02:00
parent ffd4d5e86c
commit 2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions

9
node_modules/mdast-util-find-and-replace/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,9 @@
export {findAndReplace} from './lib/index.js'
export type Options = import('./lib/index.js').Options
export type RegExpMatchObject = import('./lib/index.js').RegExpMatchObject
export type Find = import('./lib/index.js').Find
export type Replace = import('./lib/index.js').Replace
export type ReplaceFunction = import('./lib/index.js').ReplaceFunction
export type FindAndReplaceTuple = import('./lib/index.js').FindAndReplaceTuple
export type FindAndReplaceSchema = import('./lib/index.js').FindAndReplaceSchema
export type FindAndReplaceList = import('./lib/index.js').FindAndReplaceList

12
node_modules/mdast-util-find-and-replace/index.js generated vendored Normal file
View file

@ -0,0 +1,12 @@
/**
* @typedef {import('./lib/index.js').Options} Options
* @typedef {import('./lib/index.js').RegExpMatchObject} RegExpMatchObject
* @typedef {import('./lib/index.js').Find} Find
* @typedef {import('./lib/index.js').Replace} Replace
* @typedef {import('./lib/index.js').ReplaceFunction} ReplaceFunction
* @typedef {import('./lib/index.js').FindAndReplaceTuple} FindAndReplaceTuple
* @typedef {import('./lib/index.js').FindAndReplaceSchema} FindAndReplaceSchema
* @typedef {import('./lib/index.js').FindAndReplaceList} FindAndReplaceList
*/
export {findAndReplace} from './lib/index.js'

107
node_modules/mdast-util-find-and-replace/lib/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,107 @@
/**
* Find patterns in a tree and replace them.
*
* The algorithm searches the tree in *preorder* for complete values in `Text`
* nodes.
* Partial matches are not supported.
*
* @param tree
* Tree to change.
* @param find
* Patterns to find.
* @param replace
* Things to replace with (when `find` is `Find`) or configuration.
* @param options
* Configuration (when `find` is not `Find`).
* @returns
* Given, modified, tree.
*/
export const findAndReplace: (<Tree extends Node>(
tree: Tree,
find: Find,
replace?: Replace | null | undefined,
options?: Options | null | undefined
) => Tree) &
(<Tree_1 extends Node>(
tree: Tree_1,
schema: FindAndReplaceSchema | FindAndReplaceList,
options?: Options | null | undefined
) => Tree_1)
export type MdastParent = import('mdast').Parent
export type Root = import('mdast').Root
export type Content = import('mdast').Content
export type PhrasingContent = import('mdast').PhrasingContent
export type Text = import('mdast').Text
export type Test = import('unist-util-visit-parents').Test
export type VisitorResult = import('unist-util-visit-parents').VisitorResult
export type Node = Content | Root
export type Parent = Extract<Node, MdastParent>
export type ContentParent = Exclude<Parent, Root>
/**
* Info on the match.
*/
export type RegExpMatchObject = {
/**
* The index of the search at which the result was found.
*/
index: number
/**
* A copy of the search string in the text node.
*/
input: string
/**
* All ancestors of the text node, where the last node is the text itself.
*/
stack: [Root, ...Array<ContentParent>, Text]
}
/**
* Callback called when a search matches.
*/
export type ReplaceFunction = (
...parameters: any[]
) =>
| Array<PhrasingContent>
| PhrasingContent
| string
| false
| undefined
| null
/**
* Pattern to find.
*
* Strings are escaped and then turned into global expressions.
*/
export type Find = string | RegExp
/**
* Several find and replaces, in array form.
*/
export type FindAndReplaceList = Array<[Find, Replace]>
/**
* Several find and replaces, in object form.
*/
export type FindAndReplaceSchema = Record<string, Replace>
/**
* Find and replace in tuple form.
*/
export type FindAndReplaceTuple = [Find, Replace]
/**
* Thing to replace with.
*/
export type Replace = string | ReplaceFunction
/**
* Normalized find and replace.
*/
export type Pair = [RegExp, ReplaceFunction]
/**
* All find and replaced.
*/
export type Pairs = Array<[RegExp, ReplaceFunction]>
/**
* Configuration.
*/
export type Options = {
/**
* Test for which nodes to ignore.
*/
ignore?: Test | null | undefined
}

307
node_modules/mdast-util-find-and-replace/lib/index.js generated vendored Normal file
View file

@ -0,0 +1,307 @@
/**
* @typedef {import('mdast').Parent} MdastParent
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast').Content} Content
* @typedef {import('mdast').PhrasingContent} PhrasingContent
* @typedef {import('mdast').Text} Text
* @typedef {import('unist-util-visit-parents').Test} Test
* @typedef {import('unist-util-visit-parents').VisitorResult} VisitorResult
*/
/**
* @typedef {Content | Root} Node
* @typedef {Extract<Node, MdastParent>} Parent
* @typedef {Exclude<Parent, Root>} ContentParent
*
* @typedef RegExpMatchObject
* Info on the match.
* @property {number} index
* The index of the search at which the result was found.
* @property {string} input
* A copy of the search string in the text node.
* @property {[Root, ...Array<ContentParent>, Text]} stack
* All ancestors of the text node, where the last node is the text itself.
*
* @callback ReplaceFunction
* Callback called when a search matches.
* @param {...any} parameters
* The parameters are the result of corresponding search expression:
*
* * `value` (`string`) whole match
* * `...capture` (`Array<string>`) matches from regex capture groups
* * `match` (`RegExpMatchObject`) info on the match
* @returns {Array<PhrasingContent> | PhrasingContent | string | false | undefined | null}
* Thing to replace with.
*
* * when `null`, `undefined`, `''`, remove the match
* * or when `false`, do not replace at all
* * or when `string`, replace with a text node of that value
* * or when `Node` or `Array<Node>`, replace with those nodes
*
* @typedef {string | RegExp} Find
* Pattern to find.
*
* Strings are escaped and then turned into global expressions.
*
* @typedef {Array<FindAndReplaceTuple>} FindAndReplaceList
* Several find and replaces, in array form.
* @typedef {Record<string, Replace>} FindAndReplaceSchema
* Several find and replaces, in object form.
* @typedef {[Find, Replace]} FindAndReplaceTuple
* Find and replace in tuple form.
* @typedef {string | ReplaceFunction} Replace
* Thing to replace with.
* @typedef {[RegExp, ReplaceFunction]} Pair
* Normalized find and replace.
* @typedef {Array<Pair>} Pairs
* All find and replaced.
*
* @typedef Options
* Configuration.
* @property {Test | null | undefined} [ignore]
* Test for which nodes to ignore.
*/
import escape from 'escape-string-regexp'
import {visitParents} from 'unist-util-visit-parents'
import {convert} from 'unist-util-is'
const own = {}.hasOwnProperty
/**
* Find patterns in a tree and replace them.
*
* The algorithm searches the tree in *preorder* for complete values in `Text`
* nodes.
* Partial matches are not supported.
*
* @param tree
* Tree to change.
* @param find
* Patterns to find.
* @param replace
* Things to replace with (when `find` is `Find`) or configuration.
* @param options
* Configuration (when `find` is not `Find`).
* @returns
* Given, modified, tree.
*/
// To do: next major: remove `find` & `replace` combo, remove schema.
export const findAndReplace =
/**
* @type {(
* (<Tree extends Node>(tree: Tree, find: Find, replace?: Replace | null | undefined, options?: Options | null | undefined) => Tree) &
* (<Tree extends Node>(tree: Tree, schema: FindAndReplaceSchema | FindAndReplaceList, options?: Options | null | undefined) => Tree)
* )}
**/
(
/**
* @template {Node} Tree
* @param {Tree} tree
* @param {Find | FindAndReplaceSchema | FindAndReplaceList} find
* @param {Replace | Options | null | undefined} [replace]
* @param {Options | null | undefined} [options]
* @returns {Tree}
*/
function (tree, find, replace, options) {
/** @type {Options | null | undefined} */
let settings
/** @type {FindAndReplaceSchema|FindAndReplaceList} */
let schema
if (typeof find === 'string' || find instanceof RegExp) {
// @ts-expect-error dont expect options twice.
schema = [[find, replace]]
settings = options
} else {
schema = find
// @ts-expect-error dont expect replace twice.
settings = replace
}
if (!settings) {
settings = {}
}
const ignored = convert(settings.ignore || [])
const pairs = toPairs(schema)
let pairIndex = -1
while (++pairIndex < pairs.length) {
visitParents(tree, 'text', visitor)
}
// To do next major: dont return the given tree.
return tree
/** @type {import('unist-util-visit-parents/complex-types.js').BuildVisitor<Root, 'text'>} */
function visitor(node, parents) {
let index = -1
/** @type {Parent | undefined} */
let grandparent
while (++index < parents.length) {
const parent = parents[index]
if (
ignored(
parent,
// @ts-expect-error: TS doesnt understand but its perfect.
grandparent ? grandparent.children.indexOf(parent) : undefined,
grandparent
)
) {
return
}
grandparent = parent
}
if (grandparent) {
return handler(node, parents)
}
}
/**
* Handle a text node which is not in an ignored parent.
*
* @param {Text} node
* Text node.
* @param {Array<Parent>} parents
* Parents.
* @returns {VisitorResult}
* Result.
*/
function handler(node, parents) {
const parent = parents[parents.length - 1]
const find = pairs[pairIndex][0]
const replace = pairs[pairIndex][1]
let start = 0
// @ts-expect-error: TS is wrong, some of these children can be text.
const index = parent.children.indexOf(node)
let change = false
/** @type {Array<PhrasingContent>} */
let nodes = []
find.lastIndex = 0
let match = find.exec(node.value)
while (match) {
const position = match.index
/** @type {RegExpMatchObject} */
const matchObject = {
index: match.index,
input: match.input,
// @ts-expect-error: stack is fine.
stack: [...parents, node]
}
let value = replace(...match, matchObject)
if (typeof value === 'string') {
value = value.length > 0 ? {type: 'text', value} : undefined
}
// It wasnt a match after all.
if (value !== false) {
if (start !== position) {
nodes.push({
type: 'text',
value: node.value.slice(start, position)
})
}
if (Array.isArray(value)) {
nodes.push(...value)
} else if (value) {
nodes.push(value)
}
start = position + match[0].length
change = true
}
if (!find.global) {
break
}
match = find.exec(node.value)
}
if (change) {
if (start < node.value.length) {
nodes.push({type: 'text', value: node.value.slice(start)})
}
parent.children.splice(index, 1, ...nodes)
} else {
nodes = [node]
}
return index + nodes.length
}
}
)
/**
* Turn a schema into pairs.
*
* @param {FindAndReplaceSchema | FindAndReplaceList} schema
* Schema.
* @returns {Pairs}
* Clean pairs.
*/
function toPairs(schema) {
/** @type {Pairs} */
const result = []
if (typeof schema !== 'object') {
throw new TypeError('Expected array or object as schema')
}
if (Array.isArray(schema)) {
let index = -1
while (++index < schema.length) {
result.push([
toExpression(schema[index][0]),
toFunction(schema[index][1])
])
}
} else {
/** @type {string} */
let key
for (key in schema) {
if (own.call(schema, key)) {
result.push([toExpression(key), toFunction(schema[key])])
}
}
}
return result
}
/**
* Turn a find into an expression.
*
* @param {Find} find
* Find.
* @returns {RegExp}
* Expression.
*/
function toExpression(find) {
return typeof find === 'string' ? new RegExp(escape(find), 'g') : find
}
/**
* Turn a replace into a function.
*
* @param {Replace} replace
* Replace.
* @returns {ReplaceFunction}
* Function.
*/
function toFunction(replace) {
return typeof replace === 'function' ? replace : () => replace
}

22
node_modules/mdast-util-find-and-replace/license generated vendored Normal file
View file

@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2020 Titus Wormer <tituswormer@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1,16 @@
/**
Escape RegExp special characters.
You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class.
@example
```
import escapeStringRegexp from 'escape-string-regexp';
const escapedString = escapeStringRegexp('How much $ for a 🦄?');
//=> 'How much \\$ for a 🦄\\?'
new RegExp(escapedString);
```
*/
export default function escapeStringRegexp(string: string): string;

View file

@ -0,0 +1,11 @@
export default function escapeStringRegexp(string) {
if (typeof string !== 'string') {
throw new TypeError('Expected a string');
}
// Escape characters with special meaning either inside or outside character sets.
// Use a simple backslash escape when its always valid, and a `\xnn` escape when the simpler form would be disallowed by Unicode patterns stricter grammar.
return string
.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
.replace(/-/g, '\\x2d');
}

View file

@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1,40 @@
{
"name": "escape-string-regexp",
"version": "5.0.0",
"description": "Escape RegExp special characters",
"license": "MIT",
"repository": "sindresorhus/escape-string-regexp",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=12"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"escape",
"regex",
"regexp",
"regular",
"expression",
"string",
"special",
"characters"
],
"devDependencies": {
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}

View file

@ -0,0 +1,34 @@
# escape-string-regexp
> Escape RegExp special characters
## Install
```
$ npm install escape-string-regexp
```
## Usage
```js
import escapeStringRegexp from 'escape-string-regexp';
const escapedString = escapeStringRegexp('How much $ for a 🦄?');
//=> 'How much \\$ for a 🦄\\?'
new RegExp(escapedString);
```
You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class.
---
<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-escape-string-regexp?utm_source=npm-escape-string-regexp&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>

84
node_modules/mdast-util-find-and-replace/package.json generated vendored Normal file
View file

@ -0,0 +1,84 @@
{
"name": "mdast-util-find-and-replace",
"version": "2.2.2",
"description": "mdast utility to find and replace text in a tree",
"license": "MIT",
"keywords": [
"unist",
"mdast",
"mdast-util",
"util",
"utility",
"markdown",
"find",
"replace"
],
"repository": "syntax-tree/mdast-util-find-and-replace",
"bugs": "https://github.com/syntax-tree/mdast-util-find-and-replace/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/mdast": "^3.0.0",
"escape-string-regexp": "^5.0.0",
"unist-util-is": "^5.0.0",
"unist-util-visit-parents": "^5.0.0"
},
"devDependencies": {
"@types/node": "^18.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"unist-builder": "^3.0.0",
"xo": "^0.53.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 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"prettier": true
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreFiles": [
"lib/index.d.ts"
]
}
}

390
node_modules/mdast-util-find-and-replace/readme.md generated vendored Normal file
View file

@ -0,0 +1,390 @@
# mdast-util-find-and-replace
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
[mdast][] utility to find and replace things.
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`findAndReplace(tree, find, replace[, options])`](#findandreplacetree-find-replace-options)
* [`Find`](#find)
* [`FindAndReplaceList`](#findandreplacelist)
* [`FindAndReplaceSchema`](#findandreplaceschema)
* [`FindAndReplaceTuple`](#findandreplacetuple)
* [`Options`](#options)
* [`RegExpMatchObject`](#regexpmatchobject)
* [`Replace`](#replace)
* [`ReplaceFunction`](#replacefunction)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package is a utility that lets you find patterns (`string`, `RegExp`) in
text and replace them with nodes.
## When should I use this?
This utility is typically useful when you have regexes and want to modify mdast.
One example is when you have some form of “mentions” (such as
`/@([a-z][_a-z0-9])\b/gi`) and want to create links to persons from them.
A similar package, [`hast-util-find-and-replace`][hast-util-find-and-replace]
does the same but on [hast][].
## Install
This package is [ESM only][esm].
In Node.js (version 14.14+ and or 16.0+), install with [npm][]:
```sh
npm install mdast-util-find-and-replace
```
In Deno with [`esm.sh`][esmsh]:
```js
import {findAndReplace} from 'https://esm.sh/mdast-util-find-and-replace@2'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {findAndReplace} from 'https://esm.sh/mdast-util-find-and-replace@2?bundle'
</script>
```
## Use
```js
import {u} from 'unist-builder'
import {inspect} from 'unist-util-inspect'
import {findAndReplace} from 'mdast-util-find-and-replace'
const tree = u('paragraph', [
u('text', 'Some '),
u('emphasis', [u('text', 'emphasis')]),
u('text', ' and '),
u('strong', [u('text', 'importance')]),
u('text', '.')
])
findAndReplace(tree, [
[/and/gi, 'or'],
[/emphasis/gi, 'em'],
[/importance/gi, 'strong'],
[
/Some/g,
function ($0) {
return u('link', {url: '//example.com#' + $0}, [u('text', $0)])
}
]
])
console.log(inspect(tree))
```
Yields:
```txt
paragraph[8]
├─0 link[1]
│ │ url: "//example.com#Some"
│ └─0 text "Some"
├─1 text " "
├─2 emphasis[1]
│ └─0 text "em"
├─3 text " "
├─4 text "or"
├─5 text " "
├─6 strong[1]
│ └─0 text "strong"
└─7 text "."
```
## API
This package exports the identifier [`findAndReplace`][api-findandreplace].
There is no default export.
### `findAndReplace(tree, find, replace[, options])`
Find patterns in a tree and replace them.
The algorithm searches the tree in *[preorder][]* for complete values in
[`Text`][text] nodes.
Partial matches are not supported.
###### Signatures
* `findAndReplace(tree, find, replace[, options])`
* `findAndReplace(tree, search[, options])`
###### Parameters
* `tree` ([`Node`][node])
— tree to change
* `find` ([`Find`][api-find])
— value to find and remove
* `replace` ([`Replace`][api-replace])
— thing to replace with
* `search` ([`FindAndReplaceSchema`][api-findandreplaceschema] or
[`FindAndReplaceList`][api-findandreplacelist])
— several find and replaces
* `options` ([`Options`][api-options])
— configuration
###### Returns
Given, modified, tree ([`Node`][node]).
### `Find`
Pattern to find (TypeScript type).
Strings are escaped and then turned into global expressions.
###### Type
```ts
type Find = string | RegExp
```
### `FindAndReplaceList`
Several find and replaces, in array form (TypeScript type).
###### Type
```ts
type FindAndReplaceList = Array<FindAndReplaceTuple>
```
See [`FindAndReplaceTuple`][api-findandreplacetuple].
### `FindAndReplaceSchema`
Several find and replaces, in object form (TypeScript type).
###### Type
```ts
type FindAndReplaceSchema = Record<string, Replace>
```
See [`Replace`][api-replace].
### `FindAndReplaceTuple`
Find and replace in tuple form (TypeScript type).
###### Type
```ts
type FindAndReplaceTuple = [Find, Replace]
```
See [`Find`][api-find] and [`Replace`][api-replace].
### `Options`
Configuration (TypeScript type).
###### Fields
* `ignore` ([`Test`][test], optional)
— test for which elements to ignore
### `RegExpMatchObject`
Info on the match (TypeScript type).
###### Fields
* `index` (`number`)
— the index of the search at which the result was found
* `input` (`string`)
— a copy of the search string in the text node
* `stack` ([`Array<Node>`][node])
— all ancestors of the text node, where the last node is the text itself
### `Replace`
Thing to replace with (TypeScript type).
###### Type
```ts
type Replace = string | ReplaceFunction
```
See [`ReplaceFunction`][api-replacefunction].
### `ReplaceFunction`
Callback called when a search matches (TypeScript type).
###### Parameters
The parameters are the result of corresponding search expression:
* `value` (`string`)
— whole match
* `...capture` (`Array<string>`)
— matches from regex capture groups
* `match` ([`RegExpMatchObject`][api-regexpmatchobject])
— info on the match
###### Returns
Thing to replace with:
* when `null`, `undefined`, `''`, remove the match
* …or when `false`, do not replace at all
* …or when `string`, replace with a text node of that value
* …or when `Node` or `Array<Node>`, replace with those nodes
## Types
This package is fully typed with [TypeScript][].
It exports the additional types [`Find`][api-find],
[`FindAndReplaceList`][api-findandreplacelist],
[`FindAndReplaceSchema`][api-findandreplaceschema],
[`FindAndReplaceTuple`][api-findandreplacetuple],
[`Options`][api-options],
[`RegExpMatchObject`][api-regexpmatchobject],
[`Replace`][api-replace], and
[`ReplaceFunction`][api-replacefunction].
## Compatibility
Projects maintained by the unified collective are compatible with all maintained
versions of Node.js.
As of now, that is Node.js 14.14+ and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
## Security
Use of `mdast-util-find-and-replace` does not involve [hast][] or user content
so there are no openings for [cross-site scripting (XSS)][xss] attacks.
## Related
* [`hast-util-find-and-replace`](https://github.com/syntax-tree/hast-util-find-and-replace)
— find and replace in hast
* [`hast-util-select`](https://github.com/syntax-tree/hast-util-select)
`querySelector`, `querySelectorAll`, and `matches`
* [`unist-util-select`](https://github.com/syntax-tree/unist-util-select)
— select unist nodes with CSS-like selectors
## Contribute
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
ways to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
<!-- Definition -->
[build-badge]: https://github.com/syntax-tree/mdast-util-find-and-replace/workflows/main/badge.svg
[build]: https://github.com/syntax-tree/mdast-util-find-and-replace/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-find-and-replace.svg
[coverage]: https://codecov.io/github/syntax-tree/mdast-util-find-and-replace
[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-find-and-replace.svg
[downloads]: https://www.npmjs.com/package/mdast-util-find-and-replace
[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-find-and-replace.svg
[size]: https://bundlephobia.com/result?p=mdast-util-find-and-replace
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[collective]: https://opencollective.com/unified
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/syntax-tree/unist/discussions
[npm]: https://docs.npmjs.com/cli/install
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[typescript]: https://www.typescriptlang.org
[license]: license
[author]: https://wooorm.com
[health]: https://github.com/syntax-tree/.github
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
[hast]: https://github.com/syntax-tree/hast
[mdast]: https://github.com/syntax-tree/mdast
[node]: https://github.com/syntax-tree/mdast#nodes
[preorder]: https://github.com/syntax-tree/unist#preorder
[text]: https://github.com/syntax-tree/mdast#text
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
[test]: https://github.com/syntax-tree/unist-util-is#api
[hast-util-find-and-replace]: https://github.com/syntax-tree/hast-util-find-and-replace
[api-findandreplace]: #findandreplacetree-find-replace-options
[api-options]: #options
[api-find]: #find
[api-replace]: #replace
[api-replacefunction]: #replacefunction
[api-findandreplacelist]: #findandreplacelist
[api-findandreplaceschema]: #findandreplaceschema
[api-findandreplacetuple]: #findandreplacetuple
[api-regexpmatchobject]: #regexpmatchobject