From c376ee3bb9b69ec8a4c943b7eb72314afd77b080 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 30 Jun 2023 14:00:55 +0200 Subject: [PATCH 1/9] Update dev-dependencies --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 51e32c2..63fabeb 100644 --- a/package.json +++ b/package.json @@ -39,14 +39,14 @@ }, "devDependencies": { "@types/mdast": "^3.0.0", - "@types/node": "^18.0.0", - "c8": "^7.0.0", + "@types/node": "^20.0.0", + "c8": "^8.0.0", "prettier": "^2.0.0", "remark-cli": "^11.0.0", "remark-preset-wooorm": "^9.0.0", "type-coverage": "^2.0.0", - "typescript": "^4.0.0", - "xo": "^0.53.0" + "typescript": "^5.0.0", + "xo": "^0.54.0" }, "scripts": { "prepack": "npm run build && npm run format", From 67038e37c5d07a75d26a976b54797ec7b03dd838 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 30 Jun 2023 14:01:21 +0200 Subject: [PATCH 2/9] Refactor `package.json`, `tsconfig.json` --- package.json | 19 ++++++++++--------- tsconfig.json | 10 ++++------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 63fabeb..7a5d419 100644 --- a/package.json +++ b/package.json @@ -53,28 +53,29 @@ "build": "tsc --build --clean && tsc --build && type-coverage", "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", "test-api": "node --conditions development test.js", - "test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", "test": "npm run build && npm run format && npm run test-coverage" }, "prettier": { - "tabWidth": 2, - "useTabs": false, - "singleQuote": true, "bracketSpacing": false, "semi": false, - "trailingComma": "none" - }, - "xo": { - "prettier": true + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false }, "remarkConfig": { "plugins": [ - "preset-wooorm" + "remark-preset-wooorm" ] }, "typeCoverage": { "atLeast": 100, "detail": true, + "ignoreCatch": true, "strict": true + }, + "xo": { + "prettier": true } } diff --git a/tsconfig.json b/tsconfig.json index ebe8889..870d82c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,17 +1,15 @@ { - "include": ["**/*.js"], - "exclude": ["coverage/", "node_modules/"], "compilerOptions": { "checkJs": true, + "customConditions": ["development"], "declaration": true, "emitDeclarationOnly": true, "exactOptionalPropertyTypes": true, - "forceConsistentCasingInFileNames": true, "lib": ["es2020"], "module": "node16", - "newLine": "lf", - "skipLibCheck": true, "strict": true, "target": "es2020" - } + }, + "exclude": ["coverage/", "node_modules/"], + "include": ["**/*.js"] } From e85618b26da32c8f6a80e01614c110a813efb182 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 30 Jun 2023 14:07:18 +0200 Subject: [PATCH 3/9] Refactor code-style --- lib/index.js | 10 +- test.js | 370 ++++++++++++++++++++++++++++----------------------- 2 files changed, 211 insertions(+), 169 deletions(-) diff --git a/lib/index.js b/lib/index.js index 7474343..109b646 100644 --- a/lib/index.js +++ b/lib/index.js @@ -9,21 +9,21 @@ * @property {string} type * @property {PositionLike | null | undefined} [position] * - * @typedef PositionLike - * @property {PointLike | null | undefined} [start] - * @property {PointLike | null | undefined} [end] - * * @typedef PointLike * @property {number | null | undefined} [line] * @property {number | null | undefined} [column] * @property {number | null | undefined} [offset] + * + * @typedef PositionLike + * @property {PointLike | null | undefined} [start] + * @property {PointLike | null | undefined} [end] */ /** * Serialize the positional info of a point, position (start and end points), * or node. * - * @param {Node | NodeLike | Position | PositionLike | Point | PointLike | null | undefined} [value] + * @param {Node | NodeLike | Point | PointLike | Position | PositionLike | null | undefined} [value] * Node, position, or point. * @returns {string} * Pretty printed positional info of a node (`string`). diff --git a/test.js b/test.js index 9681c10..55f69e7 100644 --- a/test.js +++ b/test.js @@ -1,169 +1,211 @@ import assert from 'node:assert/strict' import test from 'node:test' import {stringifyPosition} from './index.js' -import * as mod from './index.js' - -test('stringifyPosition', function () { - assert.deepEqual( - Object.keys(mod).sort(), - ['stringifyPosition'], - 'should expose the public api' - ) - - assert.equal( - stringifyPosition(), - '', - 'should return empty `string` with `undefined`' - ) - assert.equal( - stringifyPosition(null), - '', - 'should return empty `string` with `null`' - ) - assert.equal( - // @ts-expect-error runtime. - stringifyPosition('foo'), - '', - 'should return empty `string` with `string`' - ) - assert.equal( - // @ts-expect-error runtime. - stringifyPosition(5), - '', - 'should return empty `string` with `number`' - ) - assert.equal( - stringifyPosition({}), - '', - 'should return empty `string` with `{}`' - ) - - assert.equal( - stringifyPosition({type: 'text'}), - '1:1-1:1', - 'should return a range for a `node` without `position`' - ) - - assert.equal( - // @ts-expect-error runtime. - stringifyPosition({type: 'text', position: 3}), - '1:1-1:1', - 'should return a range for `node` with invalid `position` #1' - ) - - assert.equal( - stringifyPosition({ - type: 'text', - position: {start: {}, end: {}} - }), - '1:1-1:1', - 'should return a range for `node` with invalid `position` #2' - ) - - assert.equal( - stringifyPosition({ - type: 'text', - position: { - start: {line: null, column: null}, - end: {line: null, column: null} - } - }), - '1:1-1:1', - 'should return a range for `node` with invalid `position` #3' - ) - - assert.equal( - stringifyPosition({ - type: 'text', - position: { - start: {line: 2, column: 5}, - end: {line: 2, column: 6} - } - }), - '2:5-2:6', - 'should return a range for `node` with valid `position` (types: literal object)' - ) - - assert.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)' - ) - - assert.equal( - stringifyPosition({start: null, end: null}), - '1:1-1:1', - 'should return a range for a `position` without `point`s' - ) - - assert.equal( - // @ts-expect-error runtime. - stringifyPosition({start: 3, end: 6}), - '1:1-1:1', - 'should return a range for `position` with invalid `point`s #1' - ) - - assert.equal( - stringifyPosition({start: {}, end: {}}), - '1:1-1:1', - 'should return range for `position` with invalid `point`s #1' - ) - - assert.equal( - stringifyPosition({ - start: {line: null, column: null}, - end: {line: null, column: null} - }), - '1:1-1:1', - 'should return range for `position` with invalid `point`s #3' - ) - - assert.equal( - stringifyPosition({ - start: {line: 2, column: 5}, - end: {line: 2, column: 6} - }), - '2:5-2:6', - 'should return range for `position` with valid `point`s' - ) - - assert.equal( - stringifyPosition({line: null, column: null}), - '1:1', - 'should return a point for a `point` without indices' - ) - assert.equal( - // @ts-expect-error runtime. - stringifyPosition({line: 'foo', column: 'bar'}), - '1:1', - 'should return a point for a `point` with invalid indices #1' - ) - - assert.equal( - stringifyPosition({line: 4}), - '4:1', - 'should return a point for a partially valid `point` #1' - ) - - assert.equal( - stringifyPosition({column: 12}), - '1:12', - 'should return a point for a partially valid `point` #1' - ) - - assert.equal( - stringifyPosition({line: 5, column: 2}), - '5:2', - 'should return a point for a valid `point`' - ) +test('stringifyPosition', async function (t) { + await t.test('should expose the public api', async function () { + assert.deepEqual(Object.keys(await import('./index.js')).sort(), [ + 'stringifyPosition' + ]) + }) + + await t.test( + 'should return empty `string` with `undefined`', + async function () { + assert.equal(stringifyPosition(), '') + } + ) + + await t.test('should return empty `string` with `null`', async function () { + assert.equal(stringifyPosition(null), '') + }) + + await t.test('should return empty `string` with `string`', async function () { + assert.equal( + // @ts-expect-error runtime. + stringifyPosition('foo'), + '' + ) + }) + + await t.test('should return empty `string` with `number`', async function () { + assert.equal( + // @ts-expect-error runtime. + stringifyPosition(5), + '' + ) + }) + + await t.test('should return empty `string` with `{}`', async function () { + assert.equal(stringifyPosition({}), '') + }) + + await t.test( + 'should return a range for a `node` without `position`', + async function () { + assert.equal(stringifyPosition({type: 'text'}), '1:1-1:1') + } + ) + + await t.test( + 'should return a range for `node` with invalid `position` #1', + async function () { + assert.equal( + // @ts-expect-error runtime. + stringifyPosition({type: 'text', position: 3}), + '1:1-1:1' + ) + } + ) + + await t.test( + 'should return a range for `node` with invalid `position` #2', + async function () { + assert.equal( + stringifyPosition({ + type: 'text', + position: {start: {}, end: {}} + }), + '1:1-1:1' + ) + } + ) + + await t.test( + 'should return a range for `node` with invalid `position` #3', + async function () { + assert.equal( + stringifyPosition({ + type: 'text', + position: { + start: {line: null, column: null}, + end: {line: null, column: null} + } + }), + '1:1-1:1' + ) + } + ) + + await t.test( + 'should return a range for `node` with valid `position` (types: literal object)', + async function () { + assert.equal( + stringifyPosition({ + type: 'text', + position: { + start: {line: 2, column: 5}, + end: {line: 2, column: 6} + } + }), + '2:5-2:6' + ) + } + ) + + await t.test( + 'should return a range for `node` with valid `position` (types: explicit instance of node)', + async function () { + assert.equal( + stringifyPosition( + /** @type {import('mdast').Root} */ ({ + type: 'root', + children: [], + position: { + start: {line: 1, column: 1}, + end: {line: 2, column: 1} + } + }) + ), + '1:1-2:1' + ) + } + ) + + await t.test( + 'should return a range for a `position` without `point`s', + async function () { + assert.equal(stringifyPosition({start: null, end: null}), '1:1-1:1') + } + ) + + await t.test( + 'should return a range for `position` with invalid `point`s #1', + async function () { + assert.equal( + // @ts-expect-error runtime. + stringifyPosition({start: 3, end: 6}), + '1:1-1:1' + ) + } + ) + + await t.test( + 'should return range for `position` with invalid `point`s #1', + async function () { + assert.equal(stringifyPosition({start: {}, end: {}}), '1:1-1:1') + } + ) + + await t.test( + 'should return range for `position` with invalid `point`s #3', + async function () { + assert.equal( + stringifyPosition({ + start: {line: null, column: null}, + end: {line: null, column: null} + }), + '1:1-1:1' + ) + } + ) + + await t.test( + 'should return range for `position` with valid `point`s', + async function () { + assert.equal( + stringifyPosition({ + start: {line: 2, column: 5}, + end: {line: 2, column: 6} + }), + '2:5-2:6' + ) + } + ) + + await t.test( + 'should return a point for a `point` without indices', + async function () { + assert.equal(stringifyPosition({line: null, column: null}), '1:1') + } + ) + + await t.test( + 'should return a point for a `point` with invalid indices #1', + async function () { + assert.equal( + // @ts-expect-error runtime. + stringifyPosition({line: 'foo', column: 'bar'}), + '1:1' + ) + } + ) + + await t.test( + 'should return a point for a partially valid `point` #1', + async function () { + assert.equal(stringifyPosition({line: 4}), '4:1') + } + ) + + await t.test( + 'should return a point for a partially valid `point` #1', + async function () { + assert.equal(stringifyPosition({column: 12}), '1:12') + } + ) + + await t.test('should return a point for a valid `point`', async function () { + assert.equal(stringifyPosition({line: 5, column: 2}), '5:2') + }) }) From 9e165c37560cc8f72e2cff2a5d586da6582ed434 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 30 Jun 2023 14:07:35 +0200 Subject: [PATCH 4/9] Refactor `.npmrc` --- .npmrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.npmrc b/.npmrc index 9951b11..3757b30 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,2 @@ -package-lock=false ignore-scripts=true +package-lock=false From d7621079e3be8390f00cec0becf0b5365272c167 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 30 Jun 2023 14:08:35 +0200 Subject: [PATCH 5/9] Refactor docs --- readme.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/readme.md b/readme.md index 323f960..8e70201 100644 --- a/readme.md +++ b/readme.md @@ -39,7 +39,7 @@ For example, when throwing errors or warning messages about something. ## Install This package is [ESM only][esm]. -In Node.js (version 14.14+ and 16.0+), install with [npm][]: +In Node.js (version 16+), install with [npm][]: ```sh npm install unist-util-stringify-position @@ -112,10 +112,13 @@ It exports no additional types. ## Compatibility -Projects maintained by the unified collective are compatible with all maintained +Projects maintained by the unified collective are compatible with maintained versions of Node.js. -As of now, that is Node.js 14.14+ and 16.0+. -Our projects sometimes work with older versions, but this is not guaranteed. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, +`unist-util-stringify-position@^3`, compatible with Node.js 12. ## Security @@ -160,9 +163,9 @@ abide by its terms. [downloads]: https://www.npmjs.com/package/unist-util-stringify-position -[size-badge]: https://img.shields.io/bundlephobia/minzip/unist-util-stringify-position.svg +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=unist-util-stringify-position -[size]: https://bundlephobia.com/result?p=unist-util-stringify-position +[size]: https://bundlejs.com/?q=unist-util-stringify-position [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg @@ -186,11 +189,11 @@ abide by its terms. [typescript]: https://www.typescriptlang.org -[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md +[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md -[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md +[support]: https://github.com/syntax-tree/.github/blob/main/support.md -[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md +[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md [unist]: https://github.com/syntax-tree/unist From dc23794af663e9a54853eaeb8902d9e4e964d9c4 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 30 Jun 2023 14:09:57 +0200 Subject: [PATCH 6/9] Change to use `export` map --- package.json | 3 +-- test.js | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 7a5d419..c424a62 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,7 @@ ], "sideEffects": false, "type": "module", - "main": "index.js", - "types": "index.d.ts", + "exports": "./index.js", "files": [ "lib/", "index.d.ts", diff --git a/test.js b/test.js index 55f69e7..b99f73f 100644 --- a/test.js +++ b/test.js @@ -1,12 +1,13 @@ import assert from 'node:assert/strict' import test from 'node:test' -import {stringifyPosition} from './index.js' +import {stringifyPosition} from 'unist-util-stringify-position' test('stringifyPosition', async function (t) { await t.test('should expose the public api', async function () { - assert.deepEqual(Object.keys(await import('./index.js')).sort(), [ - 'stringifyPosition' - ]) + assert.deepEqual( + Object.keys(await import('unist-util-stringify-position')).sort(), + ['stringifyPosition'] + ) }) await t.test( From d6f7251f1228bcc9983d3fd3648b3ae263052e49 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 30 Jun 2023 14:10:10 +0200 Subject: [PATCH 7/9] Change to require Node.js 16 --- readme.md | 2 +- tsconfig.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 8e70201..445fd80 100644 --- a/readme.md +++ b/readme.md @@ -118,7 +118,7 @@ versions of Node.js. When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, -`unist-util-stringify-position@^3`, compatible with Node.js 12. +`unist-util-stringify-position@^4`, compatible with Node.js 16. ## Security diff --git a/tsconfig.json b/tsconfig.json index 870d82c..82cc749 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,10 +5,10 @@ "declaration": true, "emitDeclarationOnly": true, "exactOptionalPropertyTypes": true, - "lib": ["es2020"], + "lib": ["es2022"], "module": "node16", "strict": true, - "target": "es2020" + "target": "es2022" }, "exclude": ["coverage/", "node_modules/"], "include": ["**/*.js"] From 6f1e0f010f94cd03fe2091c7d5954cbc05ee09d3 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 7 Jul 2023 12:08:50 +0200 Subject: [PATCH 8/9] Update `@types/unist` --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c424a62..f65ef3c 100644 --- a/package.json +++ b/package.json @@ -34,10 +34,10 @@ "index.js" ], "dependencies": { - "@types/unist": "^2.0.0" + "@types/unist": "^3.0.0" }, "devDependencies": { - "@types/mdast": "^3.0.0", + "@types/mdast": "^4.0.0", "@types/node": "^20.0.0", "c8": "^8.0.0", "prettier": "^2.0.0", From be908410e4acaca52ea5a723ca7c558fdb269cab Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 7 Jul 2023 12:09:21 +0200 Subject: [PATCH 9/9] 4.0.0 --- package.json | 2 +- readme.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f65ef3c..334550f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unist-util-stringify-position", - "version": "3.0.3", + "version": "4.0.0", "description": "unist utility to serialize a node, position, or point as a human readable location", "license": "MIT", "keywords": [ diff --git a/readme.md b/readme.md index 445fd80..af692c8 100644 --- a/readme.md +++ b/readme.md @@ -48,14 +48,14 @@ npm install unist-util-stringify-position In Deno with [`esm.sh`][esmsh]: ```js -import {stringifyPosition} from 'https://esm.sh/unist-util-stringify-position@3' +import {stringifyPosition} from 'https://esm.sh/unist-util-stringify-position@4' ``` In browsers with [`esm.sh`][esmsh]: ```html ``` 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