Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

syntax-tree/unist-util-stringify-position

BuildCoverageDownloadsSizeSponsorsBackersChat

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

Contents

What is this?

This package is a utility that takes anyunist (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 originaldocument, in one standard way, for humans.For example, when throwing errors or warning messages about something.

Install

This package isESM only.In Node.js (version 16+), install withnpm:

npm install unist-util-stringify-position

In Deno withesm.sh:

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

In browsers withesm.sh:

<scripttype="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 identifierstringifyPosition.There is no default export.

stringifyPosition(node|position|point)

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

Parameters
  • node (Node)— node whoseposition fields to serialize
  • position (Position)— position whosestart andend points to serialize
  • point (Point)— point whoseline andcolumn fields to serialize
Returns

Pretty printed positional info of a node (string).

In the format of a rangels:cs-le:ce (when givennode orposition) or apointl:c (when givenpoint), wherel stands for line,c for column,sforstart, ande for end.An empty string ('') is returned if the given value is neithernode,position, norpoint.

Types

This package is fully typed withTypeScript.It exports no additional types.

Compatibility

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

When we cut a new major release, we drop support for unmaintained versions ofNode.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.

Related

Contribute

Seecontributing.md insyntax-tree/.github for ways to getstarted.Seesupport.md for ways to get help.

This project has acode of conduct.By interacting with this repository, organization, or community you agree toabide by its terms.

License

MIT ©Titus Wormer

About

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

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp