{"name":"unist-util-visit-parents","version":"5.1.0","description":"unist utility to recursively walk over nodes, with ancestral information","license":"MIT","keywords":["unist","unist-util","util","utility","tree","ast","visit","traverse","walk","check","parent","parents"],"repository":{"type":"git","url":"git+https://github.com/syntax-tree/unist-util-visit-parents.git"},"bugs":{"url":"https://github.com/syntax-tree/unist-util-visit-parents/issues"},"funding":{"type":"opencollective","url":"https://opencollective.com/unified"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"sideEffects":false,"type":"module","main":"index.js","browser":{"./color.js":"./color.browser.js"},"react-native":{"./color.js":"./color.browser.js"},"types":"index.d.ts","dependencies":{"@types/unist":"^2.0.0","unist-util-is":"^5.0.0"},"devDependencies":{"@types/hast":"^2.0.0","@types/mdast":"^3.0.0","@types/tape":"^4.0.0","c8":"^7.0.0","prettier":"^2.0.0","remark":"^14.0.0","remark-cli":"^10.0.0","remark-gfm":"^2.0.0","remark-preset-wooorm":"^9.0.0","rimraf":"^3.0.0","strip-ansi":"^7.0.0","tape":"^5.0.0","tsd":"^0.17.0","type-coverage":"^2.0.0","typescript":"^4.0.0","xo":"^0.44.0"},"scripts":{"prepack":"npm run build && npm run format","build":"rimraf \"{color,color.browser,index,test}.d.ts\" && tsc && tsd && type-coverage","format":"remark . -qfo && prettier . --write --loglevel warn && xo --fix","test-api":"node test.js","test-coverage":"c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js","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,"ignoreCatch":true,"#":"needed `any`s","ignoreFiles":["complex-types.d.ts"]},"gitHead":"18d36ad5b14a15da0deb02f87d2b0e162e60d31e","homepage":"https://github.com/syntax-tree/unist-util-visit-parents#readme","_id":"unist-util-visit-parents@5.1.0","_nodeVersion":"16.9.0","_npmVersion":"7.23.0","dist":{"integrity":"sha512-y+QVLcY5eR/YVpqDsLf/xh9R3Q2Y4HxkZTp7ViLDU6WtJCEcPmRzW1gpdWDCDIqIlhuPDXOgttqPlykrHYDekg==","shasum":"44bbc5d25f2411e7dfc5cecff12de43296aa8521","tarball":"http://registry-npm.ywwl.com/unist-util-visit-parents/download/unist-util-visit-parents-5.1.0.tgz","fileCount":10,"unpackedSize":20905,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh2+/ECRA9TVsSAnZWagAADh4QAJUTK7qJCIWwChJe/qDK\n93cnxKDoAK5QJB5uydGvBaC/iP08itL7Vg9IZ3BMHLrqnKza6VBYNKSzIExQ\n35mdGzO3+tb8K1ZTCzbhfX3xL3iLh0HZXeUPjSiK6INd/GXLABZrKAq/8LIt\nOTb8SqPnSQqdTbEtEqTjFUiRGa/7fUhroTKexB/aUG4zWD9r97dPlJ6xC0UW\n2NB31iuVn55PxuxD3VM/20AHu5iv9+RgGsHbAE0jdGez8q4iywEBUOLeiguO\nY4q0SqylM6qdbuoSuz8g4I7huMgCURywJW7QkduasOOeRw6Dzl/IxAqq6VZ+\nRAT4QjlhItQjD8/RgUcOCg2yo7Wu3gl0Acw8vYKjX9DSjV+mNEcUimkZNglW\nePV/JoOim/3NRagWPL5Jcx3WKr9/6UHXhoYGATuEXfWPDT1Y/ics3jJdaoh/\ngh2DCE9IHN/eLum2kDqNIAtABJjVme2fw60gGG9tiAg/PUdg/yUVGnMV3sd9\nv+hjGVWCESM6Yclido7KtsownQAahZf8im7p/jOu16VPrJDLGfQ5+aZi8/Oq\ngTA7c+w51jomNBKCOFG776+eEDGmhmLF+M09CEUDKryWHOJAHI7dzX3Xbvw3\n5WFQ1Sm4HNJIK2O5l8/VQQfkxTfR4k8soOC1cD4mu1J6NpvvgSjgB/tjintw\n/6wR\r\n=TrBc\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCY+sHh9a1e5CQcL+WuWEYKqw5NPzkWZeXeBwEpZQbChQIgPGApLXh5KbFIHBnkork233v1GrrGRgPux/uXhpbsbW4="}],"size":6867,"noattachment":false,"key":"/unist-util-visit-parents/-/unist-util-visit-parents-5.1.0.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"},{"name":"kmck","email":"keith@mcknig.ht"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unist-util-visit-parents_5.1.0_1632208952061_0.033979467001623354"},"_hasShrinkwrap":false,"readme":"# unist-util-visit-parents\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[unist][] utility to walk the tree with a stack of parents.\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    *   [`visitParents(tree[, test], visitor[, reverse])`](#visitparentstree-test-visitor-reverse)\n    *   [`CONTINUE`](#continue)\n    *   [`EXIT`](#exit)\n    *   [`SKIP`](#skip)\n    *   [`Action`](#action)\n    *   [`ActionTuple`](#actiontuple)\n    *   [`BuildVisitor`](#buildvisitor)\n    *   [`Index`](#index)\n    *   [`Test`](#test)\n    *   [`Visitor`](#visitor)\n    *   [`VisitorResult`](#visitorresult)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis is a very important utility for working with unist as it lets you walk the\ntree.\n\n## When should I use this?\n\nYou can use this utility when you want to walk the tree and want to know about\nevery parent of each node.\nYou can use [`unist-util-visit`][unist-util-visit] if you don’t care about the\nentire stack of parents.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install unist-util-visit-parents\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {visitParents} from 'https://esm.sh/unist-util-visit-parents@6'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {visitParents} from 'https://esm.sh/unist-util-visit-parents@6?bundle'\n</script>\n```\n\n## Use\n\n```js\nimport {visitParents} from 'unist-util-visit-parents'\nimport {fromMarkdown} from 'mdast-util-from-markdown'\n\nconst tree = fromMarkdown('Some *emphasis*, **strong**, and `code`.')\n\nvisitParents(tree, 'strong', function (node, ancestors) {\n  console.log(node.type, ancestors.map(ancestor => ancestor.type))\n})\n```\n\nYields:\n\n```js\nstrong ['root', 'paragraph']\n```\n\n## API\n\nThis package exports the identifiers [`CONTINUE`][api-continue],\n[`EXIT`][api-exit], [`SKIP`][api-skip], and [`visitParents`][api-visitparents].\nThere is no default export.\n\n### `visitParents(tree[, test], visitor[, reverse])`\n\nVisit nodes, with ancestral information.\n\nThis algorithm performs *[depth-first][]* *[tree traversal][tree-traversal]*\nin *[preorder][]* (**NLR**) or if `reverse` is given, in *reverse preorder*\n(**NRL**).\n\nYou can choose for which nodes `visitor` is called by passing a `test`.\nFor complex tests, you should test yourself in `visitor`, as it will be\nfaster and will have improved type information.\n\nWalking the tree is an intensive task.\nMake use of the return values of the visitor when possible.\nInstead of walking a tree multiple times, walk it once, use\n[`unist-util-is`][unist-util-is] to check if a node matches, and then perform\ndifferent operations.\n\nYou can change the tree.\nSee [`Visitor`][api-visitor] for more info.\n\n###### Parameters\n\n*   `tree` ([`Node`][node])\n    — tree to traverse\n*   `test` ([`Test`][api-test], optional)\n    — [`unist-util-is`][unist-util-is]-compatible test\n*   `visitor` ([`Visitor`][api-visitor])\n    — handle each node\n*   `reverse` (`boolean`, default: `false`)\n    — traverse in reverse preorder (NRL) instead of the default preorder (NLR)\n\n###### Returns\n\nNothing (`undefined`).\n\n### `CONTINUE`\n\nContinue traversing as normal (`true`).\n\n### `EXIT`\n\nStop traversing immediately (`false`).\n\n### `SKIP`\n\nDo not traverse this node’s children (`'skip'`).\n\n### `Action`\n\nUnion of the action types (TypeScript type).\n\n###### Type\n\n```ts\ntype Action = typeof CONTINUE | typeof EXIT | typeof SKIP\n```\n\n### `ActionTuple`\n\nList with one or two values, the first an action, the second an index\n(TypeScript type).\n\n###### Type\n\n```ts\ntype ActionTuple = [\n  (Action | null | undefined | void)?,\n  (Index | null | undefined)?\n]\n```\n\n### `BuildVisitor`\n\nBuild a typed `Visitor` function from a tree and a test (TypeScript type).\n\nIt will infer which values are passed as `node` and which as `parents`.\n\n###### Type parameters\n\n*   `Tree` ([`Node`][node], default: `Node`)\n    — tree type\n*   `Check` ([`Test`][api-test], default: `Test`)\n    — test type\n\n###### Returns\n\n[`Visitor`][api-visitor].\n\n### `Index`\n\nMove to the sibling at `index` next (after node itself is completely\ntraversed) (TypeScript type).\n\nUseful if mutating the tree, such as removing the node the visitor is currently\non, or any of its previous siblings.\nResults less than `0` or greater than or equal to `children.length` stop\ntraversing the parent.\n\n###### Type\n\n```ts\ntype Index = number\n```\n\n### `Test`\n\n[`unist-util-is`][unist-util-is] compatible test (TypeScript type).\n\n### `Visitor`\n\nHandle a node (matching `test`, if given) (TypeScript type).\n\nVisitors are free to transform `node`.\nThey can also transform the parent of node (the last of `ancestors`).\n\nReplacing `node` itself, if `SKIP` is not returned, still causes its\ndescendants to be walked (which is a bug).\n\nWhen adding or removing previous siblings of `node` (or next siblings, in\ncase of reverse), the `Visitor` should return a new `Index` to specify the\nsibling to traverse after `node` is traversed.\nAdding or removing next siblings of `node` (or previous siblings, in case\nof reverse) is handled as expected without needing to return a new `Index`.\n\nRemoving the children property of an ancestor still results in them being\ntraversed.\n\n###### Parameters\n\n*   `node` ([`Node`][node])\n    — found node\n*   `parents` ([`Array<Node>`][node])\n    — ancestors of `node`\n\n###### Returns\n\nWhat to do next.\n\nAn `Index` is treated as a tuple of `[CONTINUE, Index]`.\nAn `Action` is treated as a tuple of `[Action]`.\n\nPassing a tuple back only makes sense if the `Action` is `SKIP`.\nWhen the `Action` is `EXIT`, that action can be returned.\nWhen the `Action` is `CONTINUE`, `Index` can be returned.\n\n### `VisitorResult`\n\nAny value that can be returned from a visitor (TypeScript type).\n\n###### Type\n\n```ts\ntype VisitorResult =\n  | Action\n  | ActionTuple\n  | Index\n  | null\n  | undefined\n  | void\n```\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`Action`][api-action],\n[`ActionTuple`][api-actiontuple], [`BuildVisitor`][api-buildvisitor],\n[`Index`][api-index], [`Test`][api-test], [`Visitor`][api-visitor], and\n[`VisitorResult`][api-visitorresult].\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`unist-util-visit-parents@^6`, compatible with Node.js 16.\n\n## Related\n\n*   [`unist-util-visit`](https://github.com/syntax-tree/unist-util-visit)\n    — walk the tree with one parent\n*   [`unist-util-filter`](https://github.com/syntax-tree/unist-util-filter)\n    — create a new tree with all nodes that pass a test\n*   [`unist-util-map`](https://github.com/syntax-tree/unist-util-map)\n    — create a new tree with all nodes mapped by a given function\n*   [`unist-util-flatmap`](https://gitlab.com/staltz/unist-util-flatmap)\n    — create a new tree by mapping (to an array) with the given function\n*   [`unist-util-remove`](https://github.com/syntax-tree/unist-util-remove)\n    — remove nodes from a tree that pass a test\n*   [`unist-util-select`](https://github.com/syntax-tree/unist-util-select)\n    — select 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, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n<!-- Definition -->\n\n[build-badge]: https://github.com/syntax-tree/unist-util-visit-parents/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/unist-util-visit-parents/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-visit-parents.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/unist-util-visit-parents\n\n[downloads-badge]: https://img.shields.io/npm/dm/unist-util-visit-parents.svg\n\n[downloads]: https://www.npmjs.com/package/unist-util-visit-parents\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=unist-util-visit-parents\n\n[size]: https://bundlejs.com/?q=unist-util-visit-parents\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/HEAD/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md\n\n[unist]: https://github.com/syntax-tree/unist\n\n[node]: https://github.com/syntax-tree/unist#node\n\n[depth-first]: https://github.com/syntax-tree/unist#depth-first-traversal\n\n[tree-traversal]: https://github.com/syntax-tree/unist#tree-traversal\n\n[preorder]: https://github.com/syntax-tree/unist#preorder\n\n[unist-util-visit]: https://github.com/syntax-tree/unist-util-visit\n\n[unist-util-is]: https://github.com/syntax-tree/unist-util-is\n\n[api-visitparents]: #visitparentstree-test-visitor-reverse\n\n[api-continue]: #continue\n\n[api-exit]: #exit\n\n[api-skip]: #skip\n\n[api-action]: #action\n\n[api-actiontuple]: #actiontuple\n\n[api-buildvisitor]: #buildvisitor\n\n[api-index]: #index\n\n[api-test]: #test\n\n[api-visitor]: #visitor\n\n[api-visitorresult]: #visitorresult\n","publish_time":1632208952203,"_cnpm_publish_time":1632208952203,"dist-tags":{"latest":"6.1.0"}}