CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
readme.md244 linesDownload Raw Back to unist-util-position
1# unist-util-position2 3[![Build][build-badge]][build]4[![Coverage][coverage-badge]][coverage]5[![Downloads][downloads-badge]][downloads]6[![Size][size-badge]][size]7[![Sponsors][sponsors-badge]][collective]8[![Backers][backers-badge]][collective]9[![Chat][chat-badge]][chat]10 11[unist][] utility to get positional info of nodes.12 13## Contents14 15*   [What is this?](#what-is-this)16*   [When should I use this?](#when-should-i-use-this)17*   [Install](#install)18*   [Use](#use)19*   [API](#api)20    *   [`position(node)`](#positionnode)21    *   [`pointEnd(node)`](#pointendnode)22    *   [`pointStart(node)`](#pointstartnode)23*   [Types](#types)24*   [Compatibility](#compatibility)25*   [Related](#related)26*   [Contribute](#contribute)27*   [License](#license)28 29## What is this?30 31This utility helps with accessing positional info on a potentially dirty tree.32 33## When should I use this?34 35The positional info is typically consistent and proper in unist trees generated36by our ecosystem, but, user plugins could mess that up.37If you’re making a reusable plugin, and accessing the positional info often, you38might want to guard against that by using this utility.39 40You might also find the utility [`unist-util-generated`][unist-util-generated]41useful to check whether a node is considered to be generated (not in the42original input file).43 44You might also enjoy45[`unist-util-stringify-position`][unist-util-stringify-position] when you want46to display positional info to users.47 48## Install49 50This package is [ESM only][esm].51In Node.js (version 16+), install with [npm][]:52 53```sh54npm install unist-util-position55```56 57In Deno with [`esm.sh`][esmsh]:58 59```js60import {pointEnd, pointStart, position} from 'https://esm.sh/unist-util-position@5'61```62 63In browsers with [`esm.sh`][esmsh]:64 65```html66<script type="module">67  import {pointEnd, pointStart, position} from 'https://esm.sh/unist-util-position@5?bundle'68</script>69```70 71## Use72 73```js74import {fromMarkdown} from 'mdast-util-from-markdown'75import {pointEnd, pointStart, position} from 'unist-util-position'76 77const tree = fromMarkdown('# foo\n\n* bar\n')78 79console.log(position(tree))80console.log(pointStart(tree))81console.log(pointEnd(tree))82```83 84Yields:85 86```js87{start: {line: 1, column: 1, offset: 0}, end: {line: 4, column: 1, offset: 13}}88{line: 1, column: 1, offset: 0}89{line: 4, column: 1, offset: 13}90```91 92## API93 94This package exports the identifiers [`pointEnd`][pointend],95[`pointStart`][pointstart], and [`position`][position].96There is no default export.97 98### `position(node)`99 100Get the positional info of `node`.101 102###### Parameters103 104*   `node` ([`Node`][node])105    — node106 107###### Returns108 109Position, if valid ([`Position`][unist-position] or `undefined`).110 111### `pointEnd(node)`112 113Get the ending point of `node`.114 115###### Parameters116 117*   `node` ([`Node`][node])118    — node119 120###### Returns121 122Point, if valid ([`Point`][unist-point] or `undefined`).123 124### `pointStart(node)`125 126Get the starting point of `node`.127 128###### Parameters129 130*   `node` ([`Node`][node])131    — node132 133###### Returns134 135Point, if valid ([`Point`][unist-point] or `undefined`).136 137## Types138 139This package is fully typed with [TypeScript][].140It exports no additional types.141 142## Compatibility143 144Projects maintained by the unified collective are compatible with maintained145versions of Node.js.146 147When we cut a new major release, we drop support for unmaintained versions of148Node.149This means we try to keep the current release line, `unist-util-position@^5`,150compatible with Node.js 16.151 152## Related153 154*   [`unist-util-stringify-position`](https://github.com/syntax-tree/unist-util-stringify-position)155    — serialize a node, position, or point as a human readable location156*   [`unist-util-position-from-estree`](https://github.com/syntax-tree/unist-util-position-from-estree)157    — get a position from an estree node158*   [`unist-util-remove-position`](https://github.com/syntax-tree/unist-util-remove-position)159    — remove positions from tree160*   [`unist-util-generated`](https://github.com/syntax-tree/unist-util-generated)161    — check if a node is generated162*   [`unist-util-source`](https://github.com/syntax-tree/unist-util-source)163    — get the source of a node164 165## Contribute166 167See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for168ways to get started.169See [`support.md`][support] for ways to get help.170 171This project has a [code of conduct][coc].172By interacting with this repository, organization, or community you agree to173abide by its terms.174 175## License176 177[MIT][license] © [Titus Wormer][author]178 179<!-- Definitions -->180 181[build-badge]: https://github.com/syntax-tree/unist-util-position/workflows/main/badge.svg182 183[build]: https://github.com/syntax-tree/unist-util-position/actions184 185[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-position.svg186 187[coverage]: https://codecov.io/github/syntax-tree/unist-util-position188 189[downloads-badge]: https://img.shields.io/npm/dm/unist-util-position.svg190 191[downloads]: https://www.npmjs.com/package/unist-util-position192 193[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=unist-util-position194 195[size]: https://bundlejs.com/?q=unist-util-position196 197[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg198 199[backers-badge]: https://opencollective.com/unified/backers/badge.svg200 201[collective]: https://opencollective.com/unified202 203[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg204 205[chat]: https://github.com/syntax-tree/unist/discussions206 207[npm]: https://docs.npmjs.com/cli/install208 209[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c210 211[esmsh]: https://esm.sh212 213[typescript]: https://www.typescriptlang.org214 215[license]: license216 217[author]: https://wooorm.com218 219[health]: https://github.com/syntax-tree/.github220 221[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md222 223[support]: https://github.com/syntax-tree/.github/blob/main/support.md224 225[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md226 227[unist]: https://github.com/syntax-tree/unist228 229[node]: https://github.com/syntax-tree/unist#node230 231[unist-position]: https://github.com/syntax-tree/unist#position232 233[unist-point]: https://github.com/syntax-tree/unist#point234 235[unist-util-generated]: https://github.com/syntax-tree/unist-util-generated236 237[unist-util-stringify-position]: https://github.com/syntax-tree/unist-util-stringify-position238 239[position]: #positionnode240 241[pointend]: #pointendnode242 243[pointstart]: #pointstartnode244