{"name":"unist-util-visit-parents","version":"3.0.0","description":"Recursively walk over unist nodes, with ancestral information","license":"MIT","keywords":["unist","walk","util","utility"],"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"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"types":"types/index.d.ts","dependencies":{"@types/unist":"^2.0.3","unist-util-is":"^4.0.0"},"devDependencies":{"browserify":"^16.0.0","dtslint":"^0.9.0","nyc":"^14.0.0","prettier":"^1.0.0","remark":"^11.0.0","remark-cli":"^7.0.0","remark-preset-wooorm":"^6.0.0","tape":"^4.0.0","tinyify":"^2.0.0","typescript":"^3.5.3","unified":"^8.3.2","xo":"^0.24.0"},"scripts":{"format":"remark . -qfo && prettier --write \"**/*.{js,ts}\" && xo --fix","build-bundle":"browserify index.js -s unistUtilVisitParents > unist-util-visit-parents.js","build-mangle":"browserify index.js -s unistUtilVisitParents -p tinyify > unist-util-visit-parents.min.js","build":"npm run build-bundle && npm run build-mangle","test-api":"node test","test-coverage":"nyc --reporter lcov tape test.js","test-types":"dtslint types","test":"npm run format && npm run build && npm run test-coverage && npm run test-types"},"nyc":{"check-coverage":true,"lines":100,"functions":100,"branches":100},"prettier":{"tabWidth":2,"useTabs":false,"singleQuote":true,"bracketSpacing":false,"semi":false,"trailingComma":"none"},"xo":{"prettier":true,"esnext":false,"ignores":["unist-util-visit-parents.js"]},"remarkConfig":{"plugins":["preset-wooorm"]},"gitHead":"4acb9aa2d4142f19d54c7e27fe62d0067de8139c","homepage":"https://github.com/syntax-tree/unist-util-visit-parents#readme","_id":"unist-util-visit-parents@3.0.0","_nodeVersion":"12.2.0","_npmVersion":"6.10.2","dist":{"integrity":"sha512-H3K8d81S4V3XVXVwLvrLGk+R5VILryfUotD06/R/rLsTsPLGjkn6gIP8qEEVITcuIySNYj0ocJLsePjm9F/Vcg==","shasum":"dd4cdcd86d505ec7a81bdc01bc790f9def742bee","tarball":"http://registry-npm.ywwl.com/unist-util-visit-parents/download/unist-util-visit-parents-3.0.0.tgz","fileCount":5,"unpackedSize":15757,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdQTxBCRA9TVsSAnZWagAAhPgP/2SI8voRQ499RVyB0YVo\ntRGTyCPOLcrcqH5bXD3LNw+lVClb6gFpNt4ieaDuNV8H/KPv2GJDp0R2xHh5\npPWuFpFVQC15IQrcKJ3SViwNlwQyt0i4RVaQWpqoZ4sM0W/Dj2lKRdz35DNE\nwYh5FWgetHayzdsoGU41Mz+zs5GdHm5fmQYSnIP32xRUrAgrmSyJGLZPHc8S\npEgLXIT21sqB575bn/KeoA6Z8VfIEIS0VEGtWcSOCIK92CdcNlhZUodkhu1q\nZrMZNwDdsu13UHqopxNNn/9+1GLapEH2J4xIBaXVoqlXBLtmQe/bySZQqaPC\njZyq9ke+kcDp+JBRMFfY6KXLjUfxh2J56vFGPVAvMl46gjpJKVnQ1IizgA1z\n4+KPFNbMYlpMeJ3oUucNTQJ/qIrUPjy76bRVBaqB44+5nuCLnrhTPdutDBe6\nYRYYExEwSMZr12CLsEbKGebvXPHFj1w4RP3NhVPk2eU9bihdf0meDgbLfx4e\nNLpMrhNzPiMvvHCJYkd2IH1eMtrxjgiSCGu6LrEdtUqHNFh8BROtz5atkQbz\ncvluPkv5sOFADIAhBeq9maktFQf7Liu5vJ8oouJmkIQHNiymAvdZkhmllBhP\nv1GBzKXhtkFsvhQZDjoiCjAWhttB5Luq629mmw4jG0x0xOHT7ihmgmX1o30E\nR1wf\r\n=B1Ml\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCN7V0GWZeBiLkAtHGphIzgvxLfI43olpEj9DTGM4GF4QIgWywtEAcwsUmHdVAkDuZ/o4C2JEp24drBdo0XFycwGDk="}],"size":5531,"noattachment":false,"key":"/unist-util-visit-parents/-/unist-util-visit-parents-3.0.0.tgz"},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"}],"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unist-util-visit-parents_3.0.0_1564556352965_0.37883152745749427"},"_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":1564556353159,"_cnpm_publish_time":1564556353159,"dist-tags":{"latest":"6.1.0"}}