{"id":19584790,"url":"https://github.com/flex-development/unist-util-stringify-position","last_synced_at":"2026-02-14T15:31:55.827Z","repository":{"id":246611154,"uuid":"821641708","full_name":"flex-development/unist-util-stringify-position","owner":"flex-development","description":"unist utility to serialize the positional info of a node, point, position, or range","archived":false,"fork":false,"pushed_at":"2025-02-19T22:05:53.000Z","size":2156,"stargazers_count":0,"open_issues_count":15,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-13T19:55:37.139Z","etag":null,"topics":["point","position","range","stringify","syntax-tree","unist","unist-util"],"latest_commit_sha":null,"homepage":"https://github.com/flex-development/unist-util-stringify-position","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-06-29T03:18:56.000Z","updated_at":"2024-11-21T22:07:43.000Z","dependencies_parsed_at":"2024-07-30T03:17:16.041Z","dependency_job_id":"309d0447-dc69-40e8-8d70-c148c174ac1b","html_url":"https://github.com/flex-development/unist-util-stringify-position","commit_stats":{"total_commits":190,"total_committers":3,"mean_commits":"63.333333333333336","dds":"0.052631578947368474","last_synced_commit":"a57b114bdafd3a38d8c69d620fa0491b9443553f"},"previous_names":["flex-development/unist-util-stringify-position"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/flex-development/unist-util-stringify-position","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Funist-util-stringify-position","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Funist-util-stringify-position/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Funist-util-stringify-position/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Funist-util-stringify-position/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flex-development","download_url":"https://codeload.github.com/flex-development/unist-util-stringify-position/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Funist-util-stringify-position/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29447987,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T14:10:32.461Z","status":"ssl_error","status_checked_at":"2026-02-14T14:09:49.945Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["point","position","range","stringify","syntax-tree","unist","unist-util"],"created_at":"2024-11-11T07:49:45.768Z","updated_at":"2026-02-14T15:31:55.808Z","avatar_url":"https://github.com/flex-development.png","language":"JavaScript","readme":"# unist-util-stringify-position\n\n[![github release](https://img.shields.io/github/v/release/flex-development/unist-util-stringify-position.svg?include_prereleases\u0026sort=semver)](https://github.com/flex-development/unist-util-stringify-position/releases/latest)\n[![npm](https://img.shields.io/npm/v/@flex-development/unist-util-stringify-position.svg)](https://npmjs.com/package/@flex-development/unist-util-stringify-position)\n[![codecov](https://codecov.io/gh/flex-development/unist-util-stringify-position/graph/badge.svg?token=oB6Ip38ZJt)](https://codecov.io/gh/flex-development/unist-util-stringify-position)\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-stringify-position.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 to serialize the positional info of a node, point, position, or range\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  - [`stringifyPosition([info][, options])`](#stringifypositioninfo-options)\n- [Types](#types)\n  - [`Info`](#info)\n  - [`LiteralLike`](#literallike)\n  - [`NodeLike`](#nodelike)\n  - [`Options`](#options)\n  - [`ParentLike`](#parentlike)\n  - [`PointLike`](#pointlike)\n  - [`PositionLike`](#positionlike)\n  - [`Range`](#range)\n- [Related](#related)\n- [Contribute](#contribute)\n\n## What is this?\n\nThis is a tiny, but useful, package that takes any [unist][unist] node, point, position, or range and serializes its\npositional info.\n\n## When should I use this?\n\nUse this package when you want a standard format for serialized positional info, such as when inspecting trees, or\nthrowing errors.\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-stringify-position\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\nIn Deno with [`esm.sh`][esmsh]:\n\n```ts\nimport { stringifyPosition } from 'https://esm.sh/@flex-development/unist-util-stringify-position'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import { stringifyPosition } from 'https://esm.sh/@flex-development/unist-util-stringify-position'\n\u003c/script\u003e\n```\n\n## Use\n\n```ts\nimport { u } from '@flex-development/unist-util-builder'\nimport {\n  stringifyPosition,\n  type LiteralLike,\n  type PointLike,\n  type PositionLike,\n  type Range\n} from '@flex-development/unist-util-stringify-position'\n\nconst node: LiteralLike = u('text', {\n  position: {\n    end: { column: 13, line: 1, offset: 12 },\n    start: { column: 1, line: 1, offset: 0 }\n  },\n  value: 'hello world!'\n})\n\nconst point: PointLike = { column: 9, line: 6 }\n\nconst position: PositionLike = { end: { line: 8 }, start: { line: 7 } }\n\nconst range: Range = [{ column: 2, line: 3 }, { column: 2, line: 5 }]\n\nconsole.log('node:', stringifyPosition(node, { offsets: true }))\nconsole.log('point:', stringifyPosition(point))\nconsole.log('position:', stringifyPosition(position))\nconsole.log('range:', stringifyPosition(range))\n```\n\n...yields\n\n```sh\nnode: 1:1-1:13, 0-12\npoint: 6:9\nposition: 7:1-8:1\nrange: 3:2-5:2\n```\n\n## API\n\nThis package exports the identifier [`stringifyPosition`](#stringifypositioninfo-options).\n\nThere is no default export.\n\n### `stringifyPosition([info][, options])`\n\nSerialize the positional info of a node, point, position, or range.\n\nThe serialized info is returned in one the following formats:\n\n- `ls:cs-le:ce, os-oe` (node, position, range)\n- `ls:cs-le:ce` (node, position, range)\n- `l:c` (point)\n\nwhere `l` stands for line, `c` for column, `o` for offset, `s` for `start`, and `e` for end.\n\nAn empty string (`''`) is returned if the given info is neither node, point, position, nor range.\n\n#### Parameters\n\n- `info` ([`Info`](#info) | `null` | `undefined`) \u0026mdash; node, point, position, or range\n- `options` ([`Options`](#options) | `null` | `undefined`) \u0026mdash; configuration options\n  - `options.offsets` (`boolean | null | undefined`) \u0026mdash; serialize offsets if `info` is a node, position, or range\n\n#### Returns\n\n(`string`) Pretty printed positional info.\n\n## Types\n\nThis package is fully typed with [TypeScript][typescript].\n\n### `Info`\n\nUnion of positional info objects (TypeScript type).\n\n```ts\ntype Info =\n  | Literal\n  | LiteralLike\n  | Node\n  | NodeLike\n  | Parent\n  | ParentLike\n  | Point\n  | PointLike\n  | Position\n  | PositionLike\n  | Range\n```\n\n### `LiteralLike`\n\nLoose [literal][literal] (TypeScript type).\n\n### `NodeLike`\n\nLoose [node][node] (TypeScript type).\n\n### `Options`\n\nConfiguration options (TypeScript type).\n\n```ts\ntype Options = {\n  offsets?: boolean | null | undefined\n}\n```\n\n#### Fields\n\n- `offsets` (`boolean | null | undefined`) \u0026mdash; serialize offsets if positional info is a node, position, or range\n\n### `ParentLike`\n\nLoose [parent][parent] (TypeScript type).\n\n### `PointLike`\n\nLoose [point][point] (TypeScript type).\n\n### `PositionLike`\n\nLoose [position][position] (TypeScript type).\n\n### `Range`\n\nList, where the first value is the place of the first character in a source region, and the last is the place of the\nlast character in the region. (TypeScript type).\n\n```ts\ntype Range = [\n  start?: Point | PointLike | null | undefined,\n  end?: Point | PointLike | null | undefined\n]\n```\n\n## Related\n\n- [`unist-util-generated`][unist-util-generated] \u0026mdash; check if a node is generated\n- [`unist-util-position`][unist-util-position] \u0026mdash; get positional info of nodes\n- [`unist-util-remove-position`][unist-util-remove-position] \u0026mdash; remove positional info from trees\n- [`unist-util-source`][unist-util-source] \u0026mdash; get the source of a value (node or position) in a file\n- [`unist-util-types`][unist-util-types] \u0026mdash; utility types\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[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n[esmsh]: https://esm.sh/\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[point]: https://github.com/syntax-tree/unist#point\n[position]: https://github.com/syntax-tree/unist#position\n[typescript]: https://www.typescriptlang.org\n[unist-util-generated]: https://github.com/syntax-tree/unist-util-generated\n[unist-util-position]: https://github.com/syntax-tree/unist-util-position\n[unist-util-remove-position]: https://github.com/syntax-tree/unist-util-remove-position\n[unist-util-source]: https://github.com/syntax-tree/unist-util-source\n[unist-util-types]: https://github.com/flex-development/unist-util-types\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-stringify-position","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflex-development%2Funist-util-stringify-position","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflex-development%2Funist-util-stringify-position/lists"}