Skip to content

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

License

Notifications You must be signed in to change notification settings

syntax-tree/unist-util-stringify-position

Repository files navigation

unist-util-stringify-position

Build Coverage Downloads Size Sponsors Backers Chat

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

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

npm:

npm install unist-util-stringify-position

Use

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

// Point
stringifyPosition({line: 2, column: 3}) // => '2:3'

// Position
stringifyPosition({start: {line: 2}, end: {line: 3}}) // => '2:1-3:1'

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

API

This package exports the following identifiers: stringifyPosition. There is no default export.

stringifyPosition(node|position|point)

Stringify one point, a position (start and end points), or a node’s positional information.

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

string? — 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.

Related

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy