{"name":"unist-util-map","repository":{"type":"git","url":"git+https://github.com/azu/unist-util-map.git"},"author":{"name":"azu"},"email":"azuciao@gmail.com","homepage":"https://github.com/azu/unist-util-map","license":"MIT","files":["lib/"],"bugs":{"url":"https://github.com/azu/unist-util-map/issues"},"version":"1.0.1","description":"Create a new Unist tree with all nodes that mapped by the provided function","main":"lib/unist-util-map.js","directories":{"test":"test"},"scripts":{"test":"mocha"},"keywords":["unist","textlint","util"],"devDependencies":{"mocha":"^2.4.5","txt-to-ast":"^1.1.0","unist-builder":"^1.0.1"},"dependencies":{"object-assign":"^4.0.1"},"gitHead":"d746df6a259dacb008b9fb5de0214ff7c1728ad6","_id":"unist-util-map@1.0.1","_shasum":"177f97e281ab931d0b6c818e5fac4f809da3ef88","_from":".","_npmVersion":"3.7.3","_nodeVersion":"5.8.0","_npmUser":{"name":"azu","email":"azuciao@gmail.com"},"maintainers":[{"name":"azu","email":"azuciao@gmail.com"}],"dist":{"shasum":"177f97e281ab931d0b6c818e5fac4f809da3ef88","tarball":"http://registry-npm.ywwl.com/unist-util-map/download/unist-util-map-1.0.1.tgz","integrity":"sha512-fSdnOtSkjtg9IXJ0GLhyCMpKsJn5LPOWdOl5rlhkrsju+ffxjYA9E947sipghc9UqVD88TZ6RsT4L8i1sXnswQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC/KfERPw5YiDOKW0RfT+Ih9qHF8SM7upKU38a1M4fd0AIhAMW3Y4UduBjpl5r/dfX4Kg+Hbmlo172nrNTM3x9chYQP"}],"size":1857,"noattachment":false,"key":"/unist-util-map/-/unist-util-map-1.0.1.tgz"},"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/unist-util-map-1.0.1.tgz_1458451730149_0.14777341508306563"},"readme":"# unist-util-map\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 create a new tree by mapping all nodes with a given\nfunction.\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    *   [`map(tree, mapFunction)`](#maptree-mapfunction)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis is a small utility that helps you make new trees.\n\n## When should I use this?\n\nYou can use this utility to create a new tree by mapping all nodes with a given\nfunction.\nCreating new trees like this can lead to performance problems, as it creates\nnew objects for every node.\nWhen dealing with potentially large trees, and relatively few changes, use\n[`unist-util-visit`][unist-util-visit] (or\n[`unist-util-visit-parents`][unist-util-visit-parents]) instead.\n\nTo remove certain nodes, you can also walk the tree with `unist-util-visit`, or\nuse [`unist-util-filter`][unist-util-filter] (clones the tree instead of\nmutating) or [`unist-util-remove`][unist-util-remove] (mutates).\nTo create trees, use [`unist-builder`][unist-builder].\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-map\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {map} from 'https://esm.sh/unist-util-map@4'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {map} from 'https://esm.sh/unist-util-map@4?bundle'\n</script>\n```\n\n## Use\n\n```js\nimport {u} from 'unist-builder'\nimport {map} from 'unist-util-map'\n\nconst tree = u('tree', [\n  u('leaf', 'leaf 1'),\n  u('node', [u('leaf', 'leaf 2')]),\n  u('void'),\n  u('leaf', 'leaf 3')\n])\n\nconst next = map(tree, function (node) {\n  return node.type === 'leaf'\n    ? Object.assign({}, node, {value: 'CHANGED'})\n    : node\n})\n\nconsole.dir(next, {depth: undefined})\n```\n\nYields:\n\n```js\n{\n  type: 'tree',\n  children: [\n    {type: 'leaf', value: 'CHANGED'},\n    {type: 'node', children: [{type: 'leaf', value: 'CHANGED'}]},\n    {type: 'void'},\n    {type: 'leaf', value: 'CHANGED'}\n  ]\n}\n```\n\n> 👉 **Note**: `next` is a changed clone and `tree` is not mutated.\n\n## API\n\nThis package exports the identifier [`map`][api-map].\nThere is no default export.\n\n### `map(tree, mapFunction)`\n\nCreate a new tree by mapping all nodes with the given function.\n\n###### Parameters\n\n*   `tree` ([`Node`][node])\n    — tree to map\n*   `mapFunction` ([`MapFunction`][api-mapfunction])\n    — function called with a node, its index, and its parent to produce a new\n    node\n\n###### Returns\n\nNew mapped tree ([`Node`][node]).\n\n#### `MapFunction`\n\nFunction called with a node, its index, and its parent to produce a new\nnode (TypeScript type).\n\n###### Parameters\n\n*   `node` ([`Node`][node])\n    — node to map\n*   `index` (`number` or `undefined`)\n    — index of `node` in `parent` (if any)\n*   `parent` ([`Node`][node] or `undefined`)\n    — parent of `node`\n\n###### Returns\n\nNew mapped node ([`Node`][node]).\n\nThe children on the returned node are not used.\nIf the original node has children, those are mapped instead.\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional type [`MapFunction`][api-mapfunction].\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, `unist-util-map@^4`,\ncompatible with Node.js 16.\n\n## Related\n\n*   [`unist-util-filter`](https://github.com/syntax-tree/unist-util-filter)\n    — create a new tree with all nodes that pass the given function\n*   [`unist-util-flatmap`](https://gitlab.com/staltz/unist-util-flatmap)\n    — create a new tree by expanding a node into many\n*   [`unist-util-remove`](https://github.com/syntax-tree/unist-util-remove)\n    — remove nodes from trees\n*   [`unist-util-select`](https://github.com/syntax-tree/unist-util-select)\n    — select nodes with CSS-like selectors\n*   [`unist-util-visit`](https://github.com/syntax-tree/unist-util-visit)\n    — walk trees\n*   [`unist-builder`](https://github.com/syntax-tree/unist-builder)\n    — create trees\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] © [azu][author]\n\n<!-- Definitions -->\n\n[build-badge]: https://github.com/syntax-tree/unist-util-map/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/unist-util-map/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-map.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/unist-util-map\n\n[downloads-badge]: https://img.shields.io/npm/dm/unist-util-map.svg\n\n[downloads]: https://www.npmjs.com/package/unist-util-map\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-map\n\n[size]: https://bundlejs.com/?q=unist-util-map\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://efcl.info\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[unist]: https://github.com/syntax-tree/unist\n\n[node]: https://github.com/syntax-tree/unist#node\n\n[unist-util-visit]: https://github.com/syntax-tree/unist-util-visit\n\n[unist-util-visit-parents]: https://github.com/syntax-tree/unist-util-visit-parents\n\n[unist-util-filter]: https://github.com/syntax-tree/unist-util-filter\n\n[unist-util-remove]: https://github.com/syntax-tree/unist-util-remove\n\n[unist-builder]: https://github.com/syntax-tree/unist-builder\n\n[api-map]: #maptree-mapfunction\n\n[api-mapfunction]: #mapfunction\n","publish_time":1458451730610,"_cnpm_publish_time":1458451730610,"dist-tags":{"latest":"4.0.0"}}