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.2 to 3.0.3

lib/index.d.ts

36

index.d.ts

@@ -1,35 +0,1 @@

/**
* @typedef {import('unist').Point} Point
* @typedef {import('unist').Node} Node
* @typedef {import('unist').Position} Position
* @typedef {object & {type: string, position?: Position|undefined}} NodeLike
*/
/**
* Stringify one point, a position (start and end points), or a node’s
* positional information.
*
* @param {Node|NodeLike|Position|Point|null} [value]
* @returns {string}
*/
export function stringifyPosition(
value?:
| import('unist').Point
| import('unist').Node<import('unist').Data>
| import('unist').Position
| NodeLike
| null
| undefined
): string
export type Point = import('unist').Point
export type Node = import('unist').Node
export type Position = import('unist').Position
export type NodeLike = object & {
type: string
position?: Position | undefined
}
/**
* @param {Position|undefined} pos
* @returns {string}
*/
declare function position(pos: Position | undefined): string
export {}
export {stringifyPosition} from './lib/index.js'

@@ -1,62 +0,1 @@

/**
* @typedef {import('unist').Point} Point
* @typedef {import('unist').Node} Node
* @typedef {import('unist').Position} Position
* @typedef {object & {type: string, position?: Position|undefined}} NodeLike
*/
/**
* Stringify one point, a position (start and end points), or a node’s
* positional information.
*
* @param {Node|NodeLike|Position|Point|null} [value]
* @returns {string}
*/
export function stringifyPosition(value) {
// Nothing.
if (!value || typeof value !== 'object') {
return ''
}
// Node.
if ('position' in value || 'type' in value) {
return position(value.position)
}
// Position.
if ('start' in value || 'end' in value) {
return position(value)
}
// Point.
if ('line' in value || 'column' in value) {
return point(value)
}
// ?
return ''
}
/**
* @param {Point|undefined} point
* @returns {string}
*/
function point(point) {
return index(point && point.line) + ':' + index(point && point.column)
}
/**
* @param {Position|undefined} pos
* @returns {string}
*/
function position(pos) {
return point(pos && pos.start) + '-' + point(pos && pos.end)
}
/**
* @param {number|undefined} value
* @returns {number}
*/
function index(value) {
return value && typeof value === 'number' ? value : 1
}
export {stringifyPosition} from './lib/index.js'
{
"name": "unist-util-stringify-position",
"version": "3.0.2",
"version": "3.0.3",
"description": "unist utility to serialize a node, position, or point as a human readable location",

@@ -33,2 +33,3 @@ "license": "MIT",

"files": [
"lib/",
"index.d.ts",

@@ -42,19 +43,17 @@ "index.js"

"@types/mdast": "^3.0.0",
"@types/tape": "^4.0.0",
"@types/node": "^18.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"remark-cli": "^10.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.48.0"
"xo": "^0.53.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"

@@ -61,0 +60,0 @@ },

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

**[unist][]** utility to pretty print the positional information of a node.
[unist][] utility to pretty print the positional info of a node.

@@ -43,3 +43,3 @@ ## Contents

This package is [ESM only][esm].
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
In Node.js (version 14.14+ and 16.0+), install with [npm][]:

@@ -83,3 +83,3 @@ ```sh

This package exports the identifier `stringifyPosition`.
This package exports the identifier [`stringifyPosition`][stringifyposition].
There is no default export.

@@ -89,3 +89,4 @@

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

@@ -95,13 +96,15 @@ ###### Parameters

* `node` ([`Node`][node])
— node whose `'position'` property to stringify
— node whose `position` fields to serialize
* `position` ([`Position`][position])
— position whose `'start'` and `'end'` points to stringify
— position whose `start` and `end` points to serialize
* `point` ([`Point`][point])
— point whose `'line'` and `'column'` to stringify
— point whose `line` and `column` fields to serialize
###### 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.
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`,

@@ -113,3 +116,3 @@ `position`, nor `point`.

This package is fully typed with [TypeScript][].
There are no additional types exported.
It exports no additional types.

@@ -120,3 +123,3 @@ ## Compatibility

versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
As of now, that is Node.js 14.14+ and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.

@@ -206,1 +209,3 @@

[point]: https://github.com/syntax-tree/unist#point
[stringifyposition]: #stringifypositionnodepositionpoint
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