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 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/package.json b/package.json index 51e32c2..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": [ @@ -27,54 +27,54 @@ ], "sideEffects": false, "type": "module", - "main": "index.js", - "types": "index.d.ts", + "exports": "./index.js", "files": [ "lib/", "index.d.ts", "index.js" ], "dependencies": { - "@types/unist": "^2.0.0" + "@types/unist": "^3.0.0" }, "devDependencies": { - "@types/mdast": "^3.0.0", - "@types/node": "^18.0.0", - "c8": "^7.0.0", + "@types/mdast": "^4.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", "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/readme.md b/readme.md index 323f960..af692c8 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 @@ -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 ``` @@ -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@^4`, compatible with Node.js 16. ## 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 diff --git a/test.js b/test.js index 9681c10..b99f73f 100644 --- a/test.js +++ b/test.js @@ -1,169 +1,212 @@ 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`' - ) +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('unist-util-stringify-position')).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') + }) }) diff --git a/tsconfig.json b/tsconfig.json index ebe8889..82cc749 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"], + "lib": ["es2022"], "module": "node16", - "newLine": "lf", - "skipLibCheck": true, "strict": true, - "target": "es2020" - } + "target": "es2022" + }, + "exclude": ["coverage/", "node_modules/"], + "include": ["**/*.js"] }
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: