diff --git a/index.js b/index.js index 1b4a320..848978f 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,15 @@ /** * @typedef {import('unist').Point} Point + * @typedef {import('unist').Node} Node * @typedef {import('unist').Position} Position - * @typedef {Record & {type: string, position?: Position|undefined}} NodeLike + * @typedef {object & {type: string, position?: Position|undefined}} NodeLike */ /** * Stringify one point, a position (start and end points), or a node’s * positional information. * - * @param {NodeLike|Position|Point|null} [value] + * @param {Node|NodeLike|Position|Point|null} [value] * @returns {string} */ export function stringifyPosition(value) { diff --git a/package.json b/package.json index 38ea1f3..5d23327 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unist-util-stringify-position", - "version": "3.0.1", + "version": "3.0.2", "description": "unist utility to serialize a node, position, or point as a human readable location", "license": "MIT", "keywords": [ @@ -37,6 +37,7 @@ "@types/unist": "^2.0.0" }, "devDependencies": { + "@types/mdast": "^3.0.0", "@types/tape": "^4.0.0", "c8": "^7.0.0", "prettier": "^2.0.0", diff --git a/test.js b/test.js index 5ae7b4d..921e87c 100644 --- a/test.js +++ b/test.js @@ -77,7 +77,22 @@ test('stringifyPosition', function (t) { } }), '2:5-2:6', - 'should return a range for `node` with valid `position`' + 'should return a range for `node` with valid `position` (types: literal object)' + ) + + t.equal( + stringifyPosition( + /** @type {import('mdast').Root} */ ({ + type: 'root', + children: [], + position: { + start: {line: 1, column: 1}, + end: {line: 2, column: 1} + } + }) + ), + '1:1-2:1', + 'should return a range for `node` with valid `position` (types: explicit instance of node)' ) t.equal( @@ -102,9 +117,10 @@ test('stringifyPosition', function (t) { ) t.equal( - // @ts-expect-error runtime. stringifyPosition({ + // @ts-expect-error runtime. start: {line: null, column: null}, + // @ts-expect-error runtime. end: {line: null, column: null} }), '1:1-1:1', 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