{"id":29423715,"url":"https://github.com/syntax-tree/unist-util-modify-children","last_synced_at":"2025-12-12T04:23:21.751Z","repository":{"id":36942032,"uuid":"41249475","full_name":"syntax-tree/unist-util-modify-children","owner":"syntax-tree","description":"utility to modify direct children of a parent","archived":false,"fork":false,"pushed_at":"2023-07-07T11:29:59.000Z","size":126,"stargazers_count":11,"open_issues_count":0,"forks_count":4,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-07-11T22:41:42.271Z","etag":null,"topics":["modify","syntax-tree","unist","unist-util","util"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syntax-tree.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":"unifiedjs","open_collective":"unified"}},"created_at":"2015-08-23T12:51:40.000Z","updated_at":"2024-05-02T00:00:20.000Z","dependencies_parsed_at":"2023-07-13T22:16:52.852Z","dependency_job_id":null,"html_url":"https://github.com/syntax-tree/unist-util-modify-children","commit_stats":{"total_commits":86,"total_committers":4,"mean_commits":21.5,"dds":"0.046511627906976716","last_synced_commit":"2df81afccc959755f75e5ad5be9fe0d1b80774d0"},"previous_names":["wooorm/unist-util-modify-children"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/unist-util-modify-children","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-modify-children","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-modify-children/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-modify-children/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-modify-children/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/unist-util-modify-children/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-modify-children/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264958203,"owners_count":23689012,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["modify","syntax-tree","unist","unist-util","util"],"created_at":"2025-07-12T07:37:52.895Z","updated_at":"2025-12-12T04:23:21.708Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","readme":"# unist-util-modify-children\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 change children of a parent.\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    *   [`modifyChildren(modifier)`](#modifychildrenmodifier)\n    *   [`Modifier`](#modifier)\n    *   [`Modify`](#modify)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis is a tiny utility that you can use to create a reusable function that\nmodifies children.\n\n## When should I use this?\n\nProbably never!\nUse [`unist-util-visit`][unist-util-visit].\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-modify-children\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {modifyChildren} from 'https://esm.sh/unist-util-modify-children@4'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {modifyChildren} from 'https://esm.sh/unist-util-modify-children@4?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport u from 'unist-builder'\nimport {modifyChildren} from 'unist-util-modify-children'\n\nconst tree = u('root', [\n  u('leaf', '1'),\n  u('parent', [u('leaf', '2')]),\n  u('leaf', '3')\n])\nconst modify = modifyChildren(function (node, index, parent) {\n  if (node.type === 'parent') {\n    parent.children.splice(index, 1, {type: 'subtree', children: parent.children})\n    return index + 1\n  }\n})\n\nmodify(tree)\n\nconsole.dir(tree, {depth: undefined})\n```\n\nYields:\n\n```js\n{\n  type: 'root',\n  children: [\n    {type: 'leaf', value: '1'},\n    {type: 'subtree', children: [{type: 'leaf', value: '2'}]},\n    {type: 'leaf', value: '3'}\n  ]\n}\n```\n\n## API\n\nThis package exports the identifier [`modifyChildren`][api-modifychildren].\nThere is no default export.\n\n### `modifyChildren(modifier)`\n\nWrap `modifier` to be called for each child in the nodes later given to\n`modify`.\n\n###### Parameters\n\n*   `modifier` ([`Modifier`][api-modifier])\n    — callback called for each `child` in `parent` later given to `modify`\n\n###### Returns\n\nModify children of `parent` ([`Modify`][api-modify]).\n\n### `Modifier`\n\nCallback called for each `child` in `parent` later given to `modify`\n(TypeScript type).\n\n###### Parameters\n\n*   `child` ([`Node`][node])\n    — child of `parent`\n*   `index` (`number`)\n    — position of `child` in `parent`\n*   `parent` ([`Node`][node])\n    — parent node\n\n###### Returns\n\nPosition to move to next (optional) (`number` or `undefined`).\n\n### `Modify`\n\nModify children of `parent` (TypeScript type).\n\n###### Parameters\n\n*   `parent` ([`Node`][node])\n    — parent node\n\n###### Returns\n\nNothing (`undefined`).\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`Modifier`][api-modifier] and\n[`Modify`][api-modify].\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-modify-children@^4`, 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\n*   [`unist-util-visit-parents`](https://github.com/syntax-tree/unist-util-visit-parents)\n    — walk the tree with a stack of parents\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-find-after`](https://github.com/syntax-tree/unist-util-find-after)\n    — find a node after another node\n*   [`unist-util-find-before`](https://github.com/syntax-tree/unist-util-find-before)\n    — find a node before another node\n*   [`unist-util-find-all-after`](https://github.com/syntax-tree/unist-util-find-all-after)\n    — find all nodes after another node\n*   [`unist-util-find-all-before`](https://github.com/syntax-tree/unist-util-find-all-before)\n    — find all nodes before another node\n*   [`unist-util-find-all-between`](https://github.com/mrzmmr/unist-util-find-all-between)\n    — find all nodes between two nodes\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\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/syntax-tree/unist-util-modify-children/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/unist-util-modify-children/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-modify-children.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/unist-util-modify-children\n\n[downloads-badge]: https://img.shields.io/npm/dm/unist-util-modify-children.svg\n\n[downloads]: https://www.npmjs.com/package/unist-util-modify-children\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=unist-util-modify-children\n\n[size]: https://bundlejs.com/?q=unist-util-modify-children\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/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#nodes\n\n[unist-util-visit]: https://github.com/syntax-tree/unist-util-visit\n\n[api-modifychildren]: #modifychildrenmodifier\n\n[api-modifier]: #modifier\n\n[api-modify]: #modify\n","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Funist-util-modify-children","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Funist-util-modify-children","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Funist-util-modify-children/lists"}