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 c09e358..fda832c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,19 +1,15 @@ /** - * @typedef {import('xast').Root} Root - * @typedef {import('xast').Element} Element - * @typedef {import('xast').RootChildMap} RootChildMap + * @typedef {import('xast').Nodes} Nodes + * @typedef {import('xast').Parents} Parents */ -/** - * @typedef {RootChildMap[keyof RootChildMap]} Child - * @typedef {Root | Child} Node - * @typedef {Root | Element} Parent - */ +// This lets VS Code show references to the above types. +'' /** * Get the plain-text value of a node. * - * @param {Node} node + * @param {Nodes} node * Node to serialize. * @returns {string} * Serialized node. @@ -27,7 +23,7 @@ export function toString(node) { /** * Serialize a child. * - * @param {Node} node + * @param {Nodes} node * Child to serialize. * @returns {string} * Serialized node. @@ -41,7 +37,7 @@ function one(node) { /** * Serialize a parent. * - * @param {Parent} node + * @param {Parents} node * Parent to serialize. * @returns {string} * Serialized node. diff --git a/package.json b/package.json index a4c45f4..3c59b8b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xast-util-to-string", - "version": "2.0.1", + "version": "3.0.0", "description": "xast utility to get the text value of a node", "license": "MIT", "keywords": [ @@ -26,54 +26,54 @@ ], "sideEffects": false, "type": "module", - "main": "index.js", - "types": "index.d.ts", + "exports": "./index.js", "files": [ "lib/", "index.d.ts", "index.js" ], "dependencies": { - "@types/xast": "^1.0.0" + "@types/xast": "^2.0.0" }, "devDependencies": { - "@types/node": "^18.0.0", - "c8": "^7.0.0", - "prettier": "^2.0.0", + "@types/node": "^20.0.0", + "c8": "^8.0.0", + "prettier": "^3.0.0", "remark-cli": "^11.0.0", "remark-preset-wooorm": "^9.0.0", "type-coverage": "^2.0.0", - "typescript": "^4.0.0", - "unist-builder": "^3.0.0", - "xo": "^0.53.0" + "typescript": "^5.0.0", + "unist-builder": "^4.0.0", + "xo": "^0.55.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", + "format": "remark . -qfo && prettier . -w --log-level 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 b1197cb..b34bd54 100644 --- a/readme.md +++ b/readme.md @@ -40,7 +40,7 @@ node when working with xast (XML). ## 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 xast-util-to-string @@ -49,14 +49,14 @@ npm install xast-util-to-string In Deno with [`esm.sh`][esmsh]: ```js -import {toString} from 'https://esm.sh/xast-util-to-string@2' +import {toString} from 'https://esm.sh/xast-util-to-string@3' ``` In browsers with [`esm.sh`][esmsh]: ```html ``` @@ -89,7 +89,7 @@ A Christmas CarolCharles Dickens ## API -This package exports the identifier [`toString`][tostring]. +This package exports the identifier [`toString`][api-to-string]. There is no default export. ### `toString(node)` @@ -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, `xast-util-to-string@^3`, +compatible with Node.js 16. ## Security @@ -163,9 +166,9 @@ abide by its terms. [downloads]: https://www.npmjs.com/package/xast-util-to-string -[size-badge]: https://img.shields.io/bundlephobia/minzip/xast-util-to-string.svg +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=xast-util-to-string -[size]: https://bundlephobia.com/result?p=xast-util-to-string +[size]: https://bundlejs.com/?q=xast-util-to-string [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg @@ -215,4 +218,4 @@ abide by its terms. [xss]: https://en.wikipedia.org/wiki/Cross-site_scripting -[tostring]: #tostringnode +[api-to-string]: #tostringnode diff --git a/test.js b/test.js index f8e52d5..c5e44d0 100644 --- a/test.js +++ b/test.js @@ -1,64 +1,73 @@ import assert from 'node:assert/strict' import test from 'node:test' import {u} from 'unist-builder' -import {toString} from './index.js' -import * as mod from './index.js' +import {toString} from 'xast-util-to-string' -test('toString', () => { - assert.deepEqual( - Object.keys(mod).sort(), - ['toString'], - 'should expose the public api' - ) +test('toString', async function (t) { + await t.test('should expose the public api', async function () { + assert.deepEqual(Object.keys(await import('xast-util-to-string')).sort(), [ + 'toString' + ]) + }) - assert.deepEqual( - toString(u('cdata', 'Hello, world!')), - 'Hello, world!', - 'should serialize cdata' - ) + await t.test('should serialize cdata', async function () { + assert.deepEqual( + toString(u('cdata', 'Hello, world!')), + 'Hello, world!' + ) + }) - assert.deepEqual( - toString(u('comment', 'foo')), - 'foo', - 'should serialize comments' - ) + await t.test('should serialize comments', async function () { + assert.deepEqual(toString(u('comment', 'foo')), 'foo') + }) - assert.deepEqual( - toString(u('instruction', {name: 'xml'}, 'version="1.0" encoding="UTF-8"')), - 'version="1.0" encoding="UTF-8"', - 'should serialize instructions' - ) + await t.test('should serialize instructions', async function () { + assert.deepEqual( + toString( + u('instruction', {name: 'xml'}, 'version="1.0" encoding="UTF-8"') + ), + 'version="1.0" encoding="UTF-8"' + ) + }) - assert.deepEqual(toString(u('text', 'foo')), 'foo', 'should serialize texts') + await t.test('should serialize texts', async function () { + assert.deepEqual(toString(u('text', 'foo')), 'foo') + }) - assert.deepEqual( - toString(u('doctype', {name: 'html'})), - '', - 'should return empty for doctypes' - ) + await t.test('should return empty for doctypes', async function () { + assert.deepEqual(toString(u('doctype', {name: 'html'})), '') + }) - assert.deepEqual( - toString( - u('element', {name: 'package'}, [ - u('text', 'foo '), - u('comment', 'bar'), - u('element', {name: 'thing'}, [u('text', ' baz')]) - ]) - ), - 'foo baz', - 'should serialize elements (excluding non-parent and non-text descendants)' + await t.test( + 'should serialize elements (excluding non-parent and non-text descendants)', + async function () { + assert.deepEqual( + toString( + u('element', {name: 'package', attributes: {}}, [ + u('text', 'foo '), + u('comment', 'bar'), + u('element', {name: 'thing', attributes: {}}, [u('text', ' baz')]) + ]) + ), + 'foo baz' + ) + } ) - assert.deepEqual( - toString( - u('root', [ - u('doctype', {name: 'html'}), - u('text', 'foo '), - u('comment', 'bar'), - u('element', {name: 'thing'}, [u('text', ' baz')]) - ]) - ), - 'foo baz', - 'should serialize roots (excluding non-parent and non-text descendants)' + await t.test( + 'should serialize roots (excluding non-parent and non-text descendants)', + async function () { + assert.deepEqual( + toString( + u('root', [ + u('doctype', {name: 'html'}), + u('text', 'foo '), + u('comment', 'bar'), + u('element', {name: 'thing', attributes: {}}, [u('text', ' baz')]) + ]) + ), + 'foo baz' + ) + } ) }) diff --git a/tsconfig.json b/tsconfig.json index 1bc9e99..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"] }