From 3b9f4cda7a7c4d78c878d447010e0aa274404248 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 3 Mar 2022 13:39:23 +0100 Subject: [PATCH 1/2] Fix types to support instances of `Node` again --- index.js | 5 +++-- package.json | 1 + test.js | 20 ++++++++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) 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..c22c9db 100644 --- a/package.json +++ b/package.json @@ -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', From c11abaa2dd12a12de3342af56b6473b8e3b0eb9e Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 3 Mar 2022 13:42:23 +0100 Subject: [PATCH 2/2] 3.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c22c9db..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": [ 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