unist-util-stringify-position

中文文档
4.0.0发布于 2023/07/07MITTypeScriptES Module近 30 天下载 2.9亿

unist utility to serialize a node, position, or point as a human readable location

原始使用文档
文档目录13 节
  1. Contents
  2. What is this?
  3. When should I use this?
  4. Install
  5. Use
  6. API
  7. stringifyPosition(node|position|point)
  8. Types
  9. Compatibility
  10. Security
  11. Related
  12. Contribute
  13. License

unist-util-stringify-position

Build Coverage Downloads Size Sponsors Backers Chat

unist utility to pretty print the positional info of a node.

Contents

What is this?

This package is a utility that takes any unist (whether mdast, hast, etc) node, position, or point, and serializes its positional info.

When should I use this?

This utility is useful to display where something occurred in the original document, in one standard way, for humans. For example, when throwing errors or warning messages about something.

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install unist-util-stringify-position

In Deno with esm.sh:

import {stringifyPosition} from 'https://esm.sh/unist-util-stringify-position@4'

In browsers with esm.sh:

<script type="module">
  import {stringifyPosition} from 'https://esm.sh/unist-util-stringify-position@4?bundle'
</script>

Use

import {stringifyPosition} from 'unist-util-stringify-position'

stringifyPosition({line: 2, column: 3}) // => '2:3' (point)
stringifyPosition({start: {line: 2}, end: {line: 3}}) // => '2:1-3:1' (position)
stringifyPosition({
  type: 'text',
  value: '!',
  position: {
    start: {line: 5, column: 11},
    end: {line: 5, column: 12}
  }
}) // => '5:11-5:12' (node)

API

This package exports the identifier stringifyPosition. There is no default export.

stringifyPosition(node|position|point)

Serialize the positional info of a point, position (start and end points), or node.

Parameters
  • node (Node) — node whose position fields to serialize
  • position (Position) — position whose start and end points to serialize
  • point (Point) — point whose line and column fields to serialize
Returns

Pretty printed positional info of a node (string).

In the format of a range ls:cs-le:ce (when given node or position) or a point l:c (when given point), where l stands for line, c for column, s for start, and e for end. An empty string ('') is returned if the given value is neither node, position, nor point.

Types

This package is fully typed with TypeScript. It exports no additional types.

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, unist-util-stringify-position@^4, compatible with Node.js 16.

Security

This project is safe.

Contribute

See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer

版本与发布记录

unist-util-stringify-position 共发布 13 个版本,首次发布于 2016/04/16;过去 12 个月发布了 0 个版本。

版本发布日期距今
4.0.0latest2023/07/073 年前
3.0.32023/01/233 年前
3.0.22022/03/034 年前
3.0.12022/03/024 年前
3.0.02021/04/135 年前
2.0.32020/02/286 年前

关于 unist-util-stringify-position 的常见问题

unist-util-stringify-position 是什么?

unist utility to serialize a node, position, or point as a human readable location

如何安装 unist-util-stringify-position?

在项目目录运行 npm install unist-util-stringify-position,或使用 pnpm add / yarn add / bun add。

unist-util-stringify-position 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

unist-util-stringify-position 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

unist-util-stringify-position 可以商用吗?

unist-util-stringify-position 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

unist-util-stringify-position 的下载量有多少?

根据 npm 官方下载统计,unist-util-stringify-position 在 2026/10/05 – 2026/11/03 这 30 天内被下载 293,237,719 次,日均约 9,774,591 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

unist-util-stringify-position 还在维护吗?

最新版本 4.0.0 发布于 2023/07/07(3 年前);至今共发布 13 个版本,其中过去 12 个月发布了 0 个;首次发布于 2016/04/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。