{"_id":"unist-util-flatmap","_rev":"3238681","name":"unist-util-flatmap","description":"Create a new Unist tree by mapping (to an array) and flattening","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"staltz","email":"andre+npm@staltz.com"}],"time":{"modified":"2024-03-21T08:21:04.000Z","created":"2018-07-21T19:29:06.641Z","1.0.0":"2018-07-21T19:29:06.641Z"},"users":{},"author":{"email":"contact@staltz.com"},"repository":{"type":"git","url":"git+https://gitlab.com/staltz/unist-util-flatmap.git"},"versions":{"1.0.0":{"name":"unist-util-flatmap","version":"1.0.0","description":"Create a new Unist tree by mapping (to an array) and flattening","license":"MIT","keywords":["unist","textlint","util"],"repository":{"type":"git","url":"git+https://gitlab.com/staltz/unist-util-flatmap.git"},"author":{"email":"contact@staltz.com"},"main":"index.js","devDependencies":{"mocha":"^5.0.0","object-assign":"4.1.1","prettier":"^1.12.1","remark-cli":"^5.0.0","remark-preset-wooorm":"^4.0.0"},"scripts":{"format":"remark . -qfo && prettier --write '**/*.js'","test-api":"mocha","test":"npm run format && npm run test-api"},"prettier":{"tabWidth":2,"useTabs":false,"singleQuote":true,"bracketSpacing":false,"semi":false,"trailingComma":"none"},"remarkConfig":{"plugins":["preset-wooorm"]},"gitHead":"898d82bd2072783a6869e49009b0ed24f59841c0","bugs":{"url":"https://gitlab.com/staltz/unist-util-flatmap/issues"},"homepage":"https://gitlab.com/staltz/unist-util-flatmap#README","_id":"unist-util-flatmap@1.0.0","_npmVersion":"5.6.0","_nodeVersion":"8.11.1","_npmUser":{"name":"staltz","email":"andre+npm@staltz.com"},"dist":{"shasum":"f914ed6b36ff040afce938d848f379f88b94b448","size":2468,"noattachment":false,"key":"/unist-util-flatmap/-/unist-util-flatmap-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/unist-util-flatmap/download/unist-util-flatmap-1.0.0.tgz"},"maintainers":[{"name":"staltz","email":"andre+npm@staltz.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unist-util-flatmap_1.0.0_1532201346537_0.1065009210957375"},"_hasShrinkwrap":false,"publish_time":1532201346641,"_cnpm_publish_time":1532201346641,"_cnpmcore_publish_time":"2021-12-16T20:46:41.252Z"}},"readme":"# unist-util-flatmap\n\nCreate a new Unist tree by mapping (to an array) with the provided function and\nthen flattening.\n\nHelper for creating [unist: Universal Syntax Tree](https://github.com/syntax-tree/unist).\n\n## Installation\n\n```sh\nnpm install unist-util-flatmap\n```\n\n## Usage\n\n### `flatMap(AST, (node, index, parent) => /* array */): AST`\n\nflatMap function returns new AST object, but the argument function should return\nan array of ASTs.\n\n```js\nconst assert = require('assert')\nconst assign = require('object-assign')\nconst flatMap = require('unist-util-flatmap')\n\n// Input\nconst tree = {\n  type: 'root',\n  children: [\n    {\n      type: 'node',\n      children: [{type: 'leaf', value: '1'}]\n    },\n    {type: 'leaf', value: '2'}\n  ]\n}\n\n// Transform:\nconst actual = flatMap(tree, node => {\n  if (node.type === 'leaf') {\n    return [\n      assign({}, node, {value: 'FIRST'}),\n      assign({}, node, {value: 'SECOND'})\n    ]\n  }\n  // No change\n  return [node]\n})\n\n// Expected output:\nconst expected = {\n  type: 'root',\n  children: [\n    {\n      type: 'node',\n      children: [\n        {type: 'leaf', value: 'FIRST'},\n        {type: 'leaf', value: 'SECOND'}\n      ]\n    },\n    {type: 'leaf', value: 'FIRST'},\n    {type: 'leaf', value: 'SECOND'}\n  ]\n}\n\nassert.deepEqual(actual, expected)\n```\n\n## Tests\n\n```sh\nnpm test\n```\n\n## License\n\n[MIT](LICENSE)\n","_attachments":{},"homepage":"https://gitlab.com/staltz/unist-util-flatmap#README","bugs":{"url":"https://gitlab.com/staltz/unist-util-flatmap/issues"},"license":"MIT"}