{"id":19584808,"url":"https://github.com/flex-development/unist-util-types","last_synced_at":"2025-04-27T11:32:53.303Z","repository":{"id":227240089,"uuid":"770854415","full_name":"flex-development/unist-util-types","owner":"flex-development","description":"unist utility types","archived":false,"fork":false,"pushed_at":"2024-10-29T10:11:59.000Z","size":2060,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-29T12:15:56.422Z","etag":null,"topics":["ast","syntax-tree","typescript","unist","unist-spec"],"latest_commit_sha":null,"homepage":"https://github.com/flex-development/unist-util-types","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flex-development.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/funding.yml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["flex-development"]}},"created_at":"2024-03-12T09:27:51.000Z","updated_at":"2024-10-28T10:51:54.000Z","dependencies_parsed_at":"2024-05-02T11:48:50.012Z","dependency_job_id":"dba5aa4d-7ab9-424c-9788-ce29cd3200dd","html_url":"https://github.com/flex-development/unist-util-types","commit_stats":null,"previous_names":["flex-development/unist-util-types"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Funist-util-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Funist-util-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Funist-util-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Funist-util-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flex-development","download_url":"https://codeload.github.com/flex-development/unist-util-types/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224069554,"owners_count":17250454,"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":["ast","syntax-tree","typescript","unist","unist-spec"],"created_at":"2024-11-11T07:49:51.068Z","updated_at":"2024-11-11T07:49:52.304Z","avatar_url":"https://github.com/flex-development.png","language":"JavaScript","readme":"# unist-util-types\n\n[![github release](https://img.shields.io/github/v/release/flex-development/unist-util-types.svg?include_prereleases\u0026sort=semver)](https://github.com/flex-development/unist-util-types/releases/latest)\n[![npm](https://img.shields.io/npm/v/@flex-development/unist-util-types.svg)](https://npmjs.com/package/@flex-development/unist-util-types)\n[![module type: esm](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)\n[![license](https://img.shields.io/github/license/flex-development/unist-util-types.svg)](LICENSE.md)\n[![conventional commits](https://img.shields.io/badge/-conventional%20commits-fe5196?logo=conventional-commits\u0026logoColor=ffffff)](https://conventionalcommits.org/)\n[![typescript](https://img.shields.io/badge/-typescript-3178c6?logo=typescript\u0026logoColor=ffffff)](https://typescriptlang.org/)\n[![vitest](https://img.shields.io/badge/-vitest-6e9f18?style=flat\u0026logo=vitest\u0026logoColor=ffffff)](https://vitest.dev/)\n[![yarn](https://img.shields.io/badge/-yarn-2c8ebb?style=flat\u0026logo=yarn\u0026logoColor=ffffff)](https://yarnpkg.com/)\n\n[unist][unist] utility types\n\n## Contents\n\n- [What is this?](#what-is-this)\n- [Install](#install)\n- [Use](#use)\n- [API](#api)\n  - [`Ancestor\u003cTree, Child\u003e`](#ancestortree-child)\n  - [`Children\u003cT\u003e`](#childrent)\n  - [`Column`](#column)\n  - [`Decrement\u003c[I]\u003e`](#decrementi)\n  - [`InclusiveDescendant\u003cTree[, Max][, Depth]\u003e`](#inclusivedescendanttree-max-depth)\n  - [`Increment\u003c[I]\u003e`](#incrementi)\n  - [`Index`](#index)\n  - [`IsAncestor\u003cTree, Child[, Max][, Depth]\u003e`](#isancestortree-child-max-depth)\n  - [`IsParent\u003cTree, Child\u003e`](#isparenttree-child)\n  - [`Line`](#line)\n  - [`Match\u003cN, Check\u003e`](#matchn-check)\n  - [`MatchChildren\u003cN[, Check]\u003e`](#matchchildrenn-check)\n  - [`MatchInclusiveDescendant\u003cTree, Check[, Max]\u003e`](#matchinclusivedescendanttree-check-max)\n  - [`MatchProperties\u003cN[, Check]\u003e`](#matchpropertiesn-check)\n  - [`MatchValue\u003cN[, Check]\u003e`](#matchvaluen-check)\n  - [`Offset`](#offset)\n  - [`Parents\u003cTree[, Child]\u003e`](#parentstree-child)\n  - [`PositionalInfo\u003c[T]\u003e`](#positionalinfot)\n  - [`Test`](#test)\n  - [`TestFunction\u003c[T][, P][, U]\u003e`](#testfunctiont-p-u)\n    - [`fn(node[, index][, parent])`](#fnnode-index-parent)\n  - [`Type\u003c[T]\u003e`](#typet)\n  - [`Uint`](#uint)\n  - [`Value\u003c[T]\u003e`](#valuet)\n- [Contribute](#contribute)\n\n## What is this?\n\nThis package contains [TypeScript][typescript] definitions for working with [unist][unist] and its [ecosystem of\nutilities][unist-utilities].\n\n## Install\n\nThis package is [ESM only][esm].\n\nIn Node.js (version 18+) with [yarn][yarn]:\n\n```sh\nyarn add @flex-development/unist-util-types\n```\n\n\u003cblockquote\u003e\n  \u003csmall\u003e\n    See \u003ca href='https://yarnpkg.com/protocol/git'\u003eGit - Protocols | Yarn\u003c/a\u003e\n    \u0026nbsp;for details regarding installing from Git.\n  \u003c/small\u003e\n\u003c/blockquote\u003e\n\n## Use\n\n```ts\nimport type {\n  Ancestor,\n  Children,\n  Column,\n  InclusiveDescendant,\n  Index,\n  Line,\n  Match,\n  MatchChildren,\n  MatchInclusiveDescendant,\n  MatchProperties,\n  MatchValue,\n  Offset,\n  Parents,\n  PositionalInfo,\n  Test,\n  TestFunction,\n  Type,\n  Value\n} from '@flex-development/unist-util-types'\n```\n\n## API\n\n### `Ancestor\u003cTree, Child\u003e`\n\nCollect nodes in [`Tree`][tree] that can be [*ancestors*][ancestor] of [`Child`][child].\n\n- `Tree` ([**`Node`**][node]): [*tree*][tree] to collect ancestors from\n- `Child` ([**`Node`**][node]): expected [*child*][child] node\n\n\u003e **source**: [`src/ancestor.ts`](src/ancestor.ts)\n\n### `Children\u003cT\u003e`\n\nExtract [*children*][child] from [*tree*][tree] `T`.\n\n- `T` ([**`Node`**][node]): tree to extract children from\n\n\u003e **source**: [`src/children.ts`](src/children.ts)\n\n### `Column`\n\nColumn in a source [*file*][file] (`1`-indexed integer).\n\n\u003e **source**: [`src/column.ts`](src/column.ts)\n\n### `Decrement\u003c[I]\u003e`\n\nSubtract `1` from `I` while `I` is in the range `[1, 10]`.\n\n- `I` ([**`Uint`**](#uint)): number to subtract from\n  - **default**: `10`\n\n\u003e **source**: [`src/decrement.ts`](src/decrement.ts)\n\n### `InclusiveDescendant\u003cTree[, Max][, Depth]\u003e`\n\nCollect all [*inclusive descendants*][descendant] of [`Tree`][tree].\n\n- `Tree` ([**`Node`**][node]): [*tree*][tree] to collect descendants from\n- `Max` ([**`Uint`**](#uint)): maximum search depth\n  - **default**: `10`\n- `Depth` ([**`Uint`**](#uint)): current search depth\n  - **default**: `0`\n\n\u003e **source**: [`src/descendant-inclusive.ts`](src/descendant-inclusive.ts)\n\n### `Increment\u003c[I]\u003e`\n\nAdd `1` to `I` while `I` is in the range `[0, 9]`.\n\n- `I` ([**`Uint`**](#uint)): number to add to\n  - **default**: `0`\n\n\u003e **source**: [`src/increment.ts`](src/increment.ts)\n\n### `Index`\n\nNumber of preceding [*siblings*][siblings] of a [*child*][child] node.\n\n\u003e **source**: [`src/index-number.ts`](src/index-number.ts)\n\n### `IsAncestor\u003cTree, Child[, Max][, Depth]\u003e`\n\nCheck if [`Tree`][tree] is an [*ancestor*][ancestor] of [`Child`][child].\n\n- `Tree` ([**`Node`**][node]): [*tree*][tree] to check\n- `Child` ([**`Node`**][node]): expected [*child*][child] node\n- `Max` ([**`Uint`**](#uint)): maximum search depth\n  - **default**: `10`\n- `Depth` ([**`Uint`**](#uint)): current search depth\n  - **default**: `0`\n\n\u003e **source**: [`src/is-ancestor.ts`](src/is-ancestor.ts)\n\n### `IsParent\u003cTree, Child\u003e`\n\nCheck if [`Tree`][tree] is the [*parent*][parent] of [`Child`][child].\n\n- `Tree` ([**`Node`**][node]): [*tree*][tree] to check\n- `Child` ([**`Node`**][node]): expected [*child*][child] node\n\n\u003e **source**: [`src/is-parent.ts`](src/is-parent.ts)\n\n### `Line`\n\nLine in a source [*file*][file] (`1`-indexed integer).\n\n\u003e **source**: [`src/line.ts`](src/line.ts)\n\n### `Match\u003cN, Check\u003e`\n\nCheck if node `N` passes a [test](#test).\n\n- `N` ([**`Node`**][node]): node to check\n- `Check` ([**`Test`**](#test)): node test\n\n\u003e **source**: [`src/match.ts`](src/match.ts)\n\n### `MatchChildren\u003cN[, Check]\u003e`\n\nExtract [*children*][child] from node `N` if it passes a [test](#test).\n\n- `N` ([**`Node`**][node]): node to check\n- `Check` ([**`Test`**](#test)): node test\n  - **default**: [`Test`](#test)\n\n\u003e **source**: [`src/match-children.ts`](src/match-children.ts)\n\n### `MatchInclusiveDescendant\u003cTree, Check[, Max]\u003e`\n\nCheck if [*inclusive descendants*][descendant] of [`Tree`][tree] pass a test.\n\n- `Tree` ([**`Node`**][node]): [*tree*][tree] to check\n- `Check` ([**`Test`**](#test)): node test\n- `Max` ([**`Uint`**](#uint)): maximum search depth\n  - **default**: `10`\n\n\u003e **source**: [`src/src/match-descendant-inclusive.ts`](src/src/match-descendant-inclusive.ts)\n\n### `MatchProperties\u003cN[, Check]\u003e`\n\nExtract properties of node `N` if it passes a [test](#test).\n\nProperties of `N` are all fields except `type`.\n\n- `N` ([**`Node`**][node]): node to check\n- `Check` ([**`Test`**](#test)): node test\n  - **default**: [`Test`](#test)\n\n\u003e **source**: [`src/match-properties.ts`](src/match-properties.ts)\n\n### `MatchValue\u003cN[, Check]\u003e`\n\nExtract the [`value`][literal] of node `N` if it passes a [test](#test).\n\n- `N` ([**`Node`**][node]): node to check\n- `Check` ([**`Test`**](#test)): node test\n  - **default**: [`Test`](#test)\n\n\u003e **source**: [`src/match-value.ts`](src/match-value.ts)\n\n### `Offset`\n\nIndex of a character in a source [*file*][file] (`0`-indexed integer).\n\n\u003e **source**: [`src/offset.ts`](src/offset.ts)\n\n### `Parents\u003cTree[, Child]\u003e`\n\nCollect nodes in [`Tree`][tree] that can be [*parents*][parent] of [`Child`][child].\n\nAll parents will be included in the resulting union if `Child` is `any`.\n\n- `Tree` ([**`Node`**][node]): [*tree*][tree] to collect parents from\n- `Child` ([**`Node`**][node]): expected [*child*][child] node\n  - **default**: `any`\n\n\u003e **source**: [`src/parents.ts`](src/parents.ts)\n\n### `PositionalInfo\u003c[T]\u003e`\n\nObject containing the [*positional information*][positional-information] of [*tree*][tree] `T`.\n\n- `T` ([**`Node`**][node]): tree to get positional information from\n  - **default**: [`Node`][node]\n\n\u003e **source**: [`src/positional-info.ts`](src/positional-info.ts)\n\n### `Test`\n\nUnion of test types for a [`Node`][node].\n\nSee [`unist-util-is`][unist-util-is] for more details.\n\n\u003e **source**: [`src/test.ts`](src/test.ts)\n\n### `TestFunction\u003c[T][, P][, U]\u003e`\n\nCheck if a node passes a test.\n\n- `T` ([**`Node`**][node]): node to check\n  - **default**: [`Node`][node]\n- `P` ([**`Parent`**][parent]): [*parent(s)*][parent] of node `T`\n  - **default**: [`Parent`][parent]\n- `U` (**`any`**): `this` context\n  - **default**: `unknown`\n\n#### `fn(node[, index][, parent])`\n\n**Parameters**:\n\n- `node` (**`T`**): node to check\n- `index` (**[`Index`](#index) | `undefined`**): index of `node` in `parent.children`\n- `parent` (**[`Parent`][parent] | `undefined`**): [*parent*][parent] of `node`\n\n**Returns**:\n\n`boolean | undefined | void` test result for `node`\n\n\u003e **source**: [`src/test-function.ts`](src/test-function.ts)\n\n### `Type\u003c[T]\u003e`\n\nExtract [*type*][type] from [*tree*][tree] `T`.\n\n- `T` ([**`Node`**][node]): tree to extract type from\n  - **default**: [`Node`][node]\n\n\u003e **source**: [`src/type.ts`](src/type.ts)\n\n### `Uint`\n\nNumber used for iteration.\n\nRange: `[0, 10]`\n\n\u003e **source**: [`src/uint.ts`](src/uint.ts)\n\n### `Value\u003c[T]\u003e`\n\nExtract the `value` of [*tree*][tree] `T`.\n\n- `T` ([**`Node`**][node]): tree to extract value from\n  - **default**: [`Literal`][literal]\n\n\u003e **source**: [`src/value.ts`](src/value.ts)\n\n## Contribute\n\nSee [`CONTRIBUTING.md`](CONTRIBUTING.md).\n\nThis project has a [code of conduct](CODE_OF_CONDUCT.md). By interacting with this repository, organization, or\ncommunity you agree to abide by its terms.\n\n[ancestor]: https://github.com/syntax-tree/unist#ancestor\n[child]: https://github.com/syntax-tree/unist#child\n[descendant]: https://github.com/syntax-tree/unist#descendant\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n[file]: https://github.com/syntax-tree/unist#file\n[literal]: https://github.com/syntax-tree/unist#literal\n[node]: https://github.com/syntax-tree/unist#node\n[parent]: https://github.com/syntax-tree/unist#parent\n[positional-information]: https://github.com/syntax-tree/unist#positional-information\n[siblings]: https://github.com/syntax-tree/unist#sibling\n[tree]: https://github.com/syntax-tree/unist#tree\n[type]: https://github.com/syntax-tree/unist#type\n[typescript]: https://www.typescriptlang.org\n[unist-util-is]: https://github.com/syntax-tree/unist-util-is\n[unist-utilities]: https://github.com/syntax-tree/unist#list-of-utilities\n[unist]: https://github.com/syntax-tree/unist\n[yarn]: https://yarnpkg.com\n","funding_links":["https://github.com/sponsors/flex-development"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflex-development%2Funist-util-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflex-development%2Funist-util-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflex-development%2Funist-util-types/lists"}