Socket
Socket
Sign inDemoInstall

unist-util-stringify-position

Package Overview
Dependencies
1
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0 to 3.0.1

28

index.d.ts
/**
* @typedef {import('unist').Node} Node
* @typedef {import('unist').Point} Point
* @typedef {import('unist').Position} Position
* @typedef {import('unist').Point} Point
* @typedef {Record<string, unknown> & {type: string, position?: Position|undefined}} NodeLike
*/

@@ -10,8 +10,24 @@ /**

*
* @param {Node|Position|Point} [value]
* @param {NodeLike|Position|Point|null} [value]
* @returns {string}
*/
export function stringifyPosition(value?: Node | Position | Point): string
export type Node = import('unist').Node
export function stringifyPosition(
value?:
| import('unist').Point
| import('unist').Position
| NodeLike
| null
| undefined
): string
export type Point = import('unist').Point
export type Position = import('unist').Position
export type Point = import('unist').Point
export type NodeLike = Record<string, unknown> & {
type: string
position?: Position | undefined
}
/**
* @param {Position|undefined} pos
* @returns {string}
*/
declare function position(pos: Position | undefined): string
export {}

@@ -1,7 +0,5 @@

var own = {}.hasOwnProperty
/**
* @typedef {import('unist').Node} Node
* @typedef {import('unist').Point} Point
* @typedef {import('unist').Position} Position
* @typedef {import('unist').Point} Point
* @typedef {Record<string, unknown> & {type: string, position?: Position|undefined}} NodeLike
*/

@@ -13,3 +11,3 @@

*
* @param {Node|Position|Point} [value]
* @param {NodeLike|Position|Point|null} [value]
* @returns {string}

@@ -24,4 +22,3 @@ */

// Node.
if (own.call(value, 'position') || own.call(value, 'type')) {
// @ts-ignore looks like a node.
if ('position' in value || 'type' in value) {
return position(value.position)

@@ -31,4 +28,3 @@ }

// Position.
if (own.call(value, 'start') || own.call(value, 'end')) {
// @ts-ignore looks like a position.
if ('start' in value || 'end' in value) {
return position(value)

@@ -38,4 +34,3 @@ }

// Point.
if (own.call(value, 'line') || own.call(value, 'column')) {
// @ts-ignore looks like a point.
if ('line' in value || 'column' in value) {
return point(value)

@@ -49,3 +44,3 @@ }

/**
* @param {Point} point
* @param {Point|undefined} point
* @returns {string}

@@ -58,3 +53,3 @@ */

/**
* @param {Position} pos
* @param {Position|undefined} pos
* @returns {string}

@@ -67,3 +62,3 @@ */

/**
* @param {number} value
* @param {number|undefined} value
* @returns {number}

@@ -70,0 +65,0 @@ */

{
"name": "unist-util-stringify-position",
"version": "3.0.0",
"version": "3.0.1",
"description": "unist utility to serialize a node, position, or point as a human readable location",

@@ -43,4 +43,4 @@ "license": "MIT",

"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"remark-cli": "^10.0.0",
"remark-preset-wooorm": "^9.0.0",
"rimraf": "^3.0.0",

@@ -50,3 +50,3 @@ "tape": "^5.0.0",

"typescript": "^4.0.0",
"xo": "^0.38.0"
"xo": "^0.48.0"
},

@@ -70,7 +70,3 @@ "scripts": {

"xo": {
"prettier": true,
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
}
"prettier": true
},

@@ -77,0 +73,0 @@ "remarkConfig": {

@@ -11,11 +11,35 @@ # unist-util-stringify-position

[**unist**][unist] utility to pretty print the positional information of a node.
**[unist][]** utility to pretty print the positional information of a node.
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`stringifyPosition(node|position|point)`](#stringifypositionnodepositionpoint)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)
## 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](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
This package is [ESM only][esm].
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
[npm][]:
```sh

@@ -25,2 +49,16 @@ npm install unist-util-stringify-position

In Deno with [`esm.sh`][esmsh]:
```js
import {stringifyPosition} from 'https://esm.sh/unist-util-stringify-position@3'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {stringifyPosition} from 'https://esm.sh/unist-util-stringify-position@3?bundle'
</script>
```
## Use

@@ -31,9 +69,4 @@

// Point
stringifyPosition({line: 2, column: 3}) // => '2:3'
// Position
stringifyPosition({start: {line: 2}, end: {line: 3}}) // => '2:1-3:1'
// Node
stringifyPosition({line: 2, column: 3}) // => '2:3' (point)
stringifyPosition({start: {line: 2}, end: {line: 3}}) // => '2:1-3:1' (position)
stringifyPosition({

@@ -46,3 +79,3 @@ type: 'text',

}
}) // => '5:11-5:12'
}) // => '5:11-5:12' (node)
```

@@ -52,3 +85,3 @@

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

@@ -58,4 +91,3 @@

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

@@ -65,7 +97,7 @@ ###### Parameters

* `node` ([`Node`][node])
— Node whose `'position'` property to stringify
— node whose `'position'` property to stringify
* `position` ([`Position`][position])
— Position whose `'start'` and `'end'` points to stringify
— position whose `'start'` and `'end'` points to stringify
* `point` ([`Point`][point])
— Point whose `'line'` and `'column'` to stringify
— point whose `'line'` and `'column'` to stringify

@@ -80,12 +112,28 @@ ###### Returns

## Types
This package is fully typed with [TypeScript][].
There are no additional types exported.
## Compatibility
Projects maintained by the unified collective are compatible with all maintained
versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
## Security
This project is safe.
## Related
* [`unist-util-generated`](https://github.com/syntax-tree/unist-util-generated)
— Check if a node is generated
— check if a node is generated
* [`unist-util-position`](https://github.com/syntax-tree/unist-util-position)
— Get positional info of nodes
— get positional info of nodes
* [`unist-util-remove-position`](https://github.com/syntax-tree/unist-util-remove-position)
— Remove positional info from trees
— remove positional info from trees
* [`unist-util-source`](https://github.com/syntax-tree/unist-util-source)
— Get the source of a value (node or position) in a file
— get the source of a value (node or position) in a file

@@ -140,2 +188,8 @@ ## Contribute

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[typescript]: https://www.typescriptlang.org
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md

@@ -154,3 +208,1 @@

[point]: https://github.com/syntax-tree/unist#point
[positional-information]: https://github.com/syntax-tree/unist#positional-information
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc