From c7f8f0f39684a07f415f0e74b7d160b3b4b6e941 Mon Sep 17 00:00:00 2001 From: Titus Date: Tue, 1 Jun 2021 11:02:13 +0200 Subject: [PATCH 01/17] Use `pull_request_target` in bb --- .github/workflows/bb.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bb.yml b/.github/workflows/bb.yml index 291ab09..0198fc3 100644 --- a/.github/workflows/bb.yml +++ b/.github/workflows/bb.yml @@ -2,7 +2,7 @@ name: bb on: issues: types: [opened, reopened, edited, closed, labeled, unlabeled] - pull_request: + pull_request_target: types: [opened, reopened, edited, closed, labeled, unlabeled] jobs: main: From df09bb96128e09e223b4f7c8d4732e29434ed592 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sat, 24 Jul 2021 13:34:08 +0200 Subject: [PATCH 02/17] Refactor code-style --- index.js | 6 +++--- package.json | 6 +----- readme.md | 2 +- test.js | 2 +- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 46f8fb9..f104e5f 100644 --- a/index.js +++ b/index.js @@ -35,10 +35,10 @@ function one(node) { * @returns {string} */ function all(node) { - var children = node.children - var index = -1 + const children = node.children + let index = -1 /** @type {Array.} */ - var result = [] + const result = [] while (++index < children.length) { result[index] = one(children[index]) diff --git a/package.json b/package.json index a395ac4..e9828b1 100644 --- a/package.json +++ b/package.json @@ -65,11 +65,7 @@ "trailingComma": "none" }, "xo": { - "prettier": true, - "rules": { - "no-var": "off", - "prefer-arrow-callback": "off" - } + "prettier": true }, "remarkConfig": { "plugins": [ diff --git a/readme.md b/readme.md index 04c1d22..cdbc4e1 100644 --- a/readme.md +++ b/readme.md @@ -30,7 +30,7 @@ npm install xast-util-to-string import {x} from 'xastscript' import {toString} from 'xast-util-to-string' -var tree = x( +const tree = x( 'ncx', {xmlns: 'http://www.daisy.org/z3986/2005/ncx/', version: '2005-1'}, [ diff --git a/test.js b/test.js index 41bfd8d..a89e220 100644 --- a/test.js +++ b/test.js @@ -2,7 +2,7 @@ import test from 'tape' import {u} from 'unist-builder' import {toString} from './index.js' -test('xast-util-to-string', function (t) { +test('xast-util-to-string', (t) => { t.deepEqual( toString(u('cdata', 'Hello, world!')), 'Hello, world!', From b1398f63eeaf3bae380280e4b637ee69a4f331fa Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sat, 24 Jul 2021 13:35:27 +0200 Subject: [PATCH 03/17] Add `strict` to `tsconfig.json` --- index.js | 5 +---- tsconfig.json | 3 ++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index f104e5f..8421c66 100644 --- a/index.js +++ b/index.js @@ -13,9 +13,7 @@ */ export function toString(node) { // A root or an element - // @ts-ignore Looks like a parent. if ('children' in node) return all(node) - // @ts-ignore Looks like a literal. return 'value' in node ? node.value : '' } @@ -26,8 +24,7 @@ export function toString(node) { function one(node) { if (node.type === 'text') return node.value // Ignore things like comments, instruction, cdata. - // @ts-ignore Looks like a parent. - return node.children ? all(node) : '' + return 'children' in node ? all(node) : '' } /** diff --git a/tsconfig.json b/tsconfig.json index be08abe..e31adf8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,7 @@ "declaration": true, "emitDeclarationOnly": true, "allowSyntheticDefaultImports": true, - "skipLibCheck": true + "skipLibCheck": true, + "strict": true } } From ea8bfaf6bb2f2d03b48e3a4f360632f61b81325f Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sat, 24 Jul 2021 13:36:00 +0200 Subject: [PATCH 04/17] Update `xo` --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index e9828b1..6a65581 100644 --- a/package.json +++ b/package.json @@ -41,12 +41,12 @@ "prettier": "^2.0.0", "remark-cli": "^9.0.0", "remark-preset-wooorm": "^8.0.0", - "rimraf": "^3.0.2", + "rimraf": "^3.0.0", "tape": "^5.0.0", - "type-coverage": "^2.17.5", - "typescript": "^4.2.4", + "type-coverage": "^2.0.0", + "typescript": "^4.0.0", "unist-builder": "^3.0.0", - "xo": "^0.39.0" + "xo": "^0.42.0" }, "scripts": { "prepack": "npm run build && npm run format", From 5f7a93b363f0937b5624b19303caec487d37c3c4 Mon Sep 17 00:00:00 2001 From: Christian Murphy Date: Thu, 3 Mar 2022 10:38:02 -0700 Subject: [PATCH 05/17] Add `ignore-scripts` to `.npmrc` --- .npmrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.npmrc b/.npmrc index 43c97e7..9951b11 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1,2 @@ package-lock=false +ignore-scripts=true From 540af33cc33a45b4631de753dc166c50b9722c38 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sat, 28 May 2022 12:41:53 +0200 Subject: [PATCH 06/17] Update dev-dependencies --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 6a65581..569ea4e 100644 --- a/package.json +++ b/package.json @@ -39,14 +39,14 @@ "@types/tape": "^4.0.0", "c8": "^7.0.0", "prettier": "^2.0.0", - "remark-cli": "^9.0.0", - "remark-preset-wooorm": "^8.0.0", + "remark-cli": "^10.0.0", + "remark-preset-wooorm": "^9.0.0", "rimraf": "^3.0.0", "tape": "^5.0.0", "type-coverage": "^2.0.0", "typescript": "^4.0.0", "unist-builder": "^3.0.0", - "xo": "^0.42.0" + "xo": "^0.49.0" }, "scripts": { "prepack": "npm run build && npm run format", From d68827b476a2dd32ae8df9ecbffa98e27ba896ec Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sat, 28 May 2022 12:42:02 +0200 Subject: [PATCH 07/17] Refactor code-style --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 8421c66..0994816 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,7 @@ function one(node) { function all(node) { const children = node.children let index = -1 - /** @type {Array.} */ + /** @type {Array} */ const result = [] while (++index < children.length) { From f761b5d740d74d38f3cc2b3b543e23f824b90d0d Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sat, 28 May 2022 12:45:56 +0200 Subject: [PATCH 08/17] Add improved docs --- readme.md | 92 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 19 deletions(-) diff --git a/readme.md b/readme.md index cdbc4e1..1f387db 100644 --- a/readme.md +++ b/readme.md @@ -8,22 +8,58 @@ [![Backers][backers-badge]][collective] [![Chat][chat-badge]][chat] -[**xast**][xast] utility to get the plain text value of a [*node*][node]. +[xast][] utility to get the plain-text value of a node. -This is like the DOMs `Node#textContent` getter but there are some deviations. -The resulting text is returned. +## Contents -## Install +* [What is this?](#what-is-this) +* [When should I use this?](#when-should-i-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`toString(node)`](#tostringnode) +* [Types](#types) +* [Compatibility](#compatibility) +* [Security](#security) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package is a utility that takes a [xast][] node and gets its plain-text +value. +This is like the DOMs `Node#textContent` getter but there are some small +deviations. -This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): -Node 12+ is needed to use it and it must be `import`ed instead of `require`d. +## When should I use this? + +This is a small utility that is useful when you want a plain-text version of a +node when working with xast (XML). + +## Install -[npm][]: +This package is [ESM only][esm]. +In Node.js (version 12.20+, 14.14+, 16.0+, 18.0+), install with [npm][]: ```sh npm install xast-util-to-string ``` +In Deno with [`esm.sh`][esmsh]: + +```js +import {toString} from "https://esm.sh/xast-util-to-string@2" +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + ## Use ```js @@ -53,12 +89,12 @@ A Christmas CarolCharles Dickens ## API -This package exports the following identifiers: `toString`. +This package exports the identifier `toString`. There is no default export. ### `toString(node)` -Utility to get the plain text value of a [*node*][node]. +Get the plain text value of a node. If the node has a `value` field ([*cdata*][cdata], [*comment*][comment], [*doctype*][doctype], [*instruction*][instruction], or [*text*][text]), returns it. @@ -67,7 +103,19 @@ recurses into it to concatenate all [*text*][text]s. ###### Returns -`string` — Serialized `node`. +Serialized `node` (`string`). + +## Types + +This package is fully typed with [TypeScript][]. +It exports no additional types. + +## Compatibility + +Projects maintained by the unified collective are compatible with all maintained +versions of Node.js. +As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+. +Our projects sometimes work with older versions, but this is not guaranteed. ## Security @@ -78,19 +126,19 @@ for [cross-site scripting (XSS)][xss] attacks. * [`xast-util-to-xml`](https://github.com/syntax-tree/xast-util-to-xml) — serialize xast to XML -* [`hast-util-to-string`](https://github.com/rehypejs/rehype-minify/tree/HEAD/packages/hast-util-to-string) +* [`hast-util-to-string`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-to-string) — get the plain-text value (`textContent`) * [`hast-util-to-text`](https://github.com/syntax-tree/hast-util-to-text) — get the plain-text value (`innerText`) * [`hast-util-from-text`](https://github.com/syntax-tree/hast-util-from-text) — set the plain-text value (`innerText`) -* [`hast-util-from-string`](https://github.com/rehypejs/rehype-minify/tree/HEAD/packages/hast-util-from-string) +* [`hast-util-from-string`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-from-string) — set the plain-text value (`textContent`) ## Contribute -See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get -started. +See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for +ways to get started. See [`support.md`][support] for ways to get help. This project has a [code of conduct][coc]. @@ -131,19 +179,25 @@ abide by its terms. [npm]: https://docs.npmjs.com/cli/install +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[esmsh]: https://esm.sh + +[typescript]: https://www.typescriptlang.org + [license]: license [author]: https://wooorm.com -[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md +[health]: https://github.com/syntax-tree/.github -[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md +[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md -[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md +[support]: https://github.com/syntax-tree/.github/blob/main/support.md -[xast]: https://github.com/syntax-tree/xast +[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md -[node]: https://github.com/syntax-tree/xast#nodes +[xast]: https://github.com/syntax-tree/xast [root]: https://github.com/syntax-tree/xast#root From 5a8823452a50d1f24d227bb8e6c2812254da3a9e Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 16 Jan 2023 20:03:12 +0100 Subject: [PATCH 09/17] Update dev-dependencies --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 569ea4e..8df7f81 100644 --- a/package.json +++ b/package.json @@ -39,14 +39,14 @@ "@types/tape": "^4.0.0", "c8": "^7.0.0", "prettier": "^2.0.0", - "remark-cli": "^10.0.0", + "remark-cli": "^11.0.0", "remark-preset-wooorm": "^9.0.0", "rimraf": "^3.0.0", "tape": "^5.0.0", "type-coverage": "^2.0.0", "typescript": "^4.0.0", "unist-builder": "^3.0.0", - "xo": "^0.49.0" + "xo": "^0.53.0" }, "scripts": { "prepack": "npm run build && npm run format", From 85bf8454891a8598149f34069b189bf39f8edaf1 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 16 Jan 2023 20:03:21 +0100 Subject: [PATCH 10/17] Update Actions --- .github/workflows/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fe284ad..89dc06c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,15 +7,15 @@ jobs: name: ${{matrix.node}} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: dcodeIO/setup-node-nvm@master + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: ${{matrix.node}} - run: npm install - run: npm test - - uses: codecov/codecov-action@v1 + - uses: codecov/codecov-action@v3 strategy: matrix: node: - - lts/erbium + - lts/fermium - node From 412e8ff3199edbce6a8d19c5f0f2e67f36846a3d Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 16 Jan 2023 20:03:43 +0100 Subject: [PATCH 11/17] Update `tsconfig.json` --- package.json | 9 ++++----- tsconfig.json | 17 +++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 8df7f81..1c0448b 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,6 @@ "prettier": "^2.0.0", "remark-cli": "^11.0.0", "remark-preset-wooorm": "^9.0.0", - "rimraf": "^3.0.0", "tape": "^5.0.0", "type-coverage": "^2.0.0", "typescript": "^4.0.0", @@ -50,10 +49,10 @@ }, "scripts": { "prepack": "npm run build && npm run format", - "build": "rimraf \"*.d.ts\" && tsc && type-coverage", - "format": "remark . -qfo && prettier . --write --loglevel warn && xo --fix", - "test-api": "node test.js", - "test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js", + "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": "npm run build && npm run format && npm run test-coverage" }, "prettier": { diff --git a/tsconfig.json b/tsconfig.json index e31adf8..1bc9e99 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,16 +1,17 @@ { - "include": ["*.js"], + "include": ["**/**.js"], + "exclude": ["coverage/", "node_modules/"], "compilerOptions": { - "target": "ES2020", - "lib": ["ES2020"], - "module": "ES2020", - "moduleResolution": "node", - "allowJs": true, "checkJs": true, "declaration": true, "emitDeclarationOnly": true, - "allowSyntheticDefaultImports": true, + "exactOptionalPropertyTypes": true, + "forceConsistentCasingInFileNames": true, + "lib": ["es2020"], + "module": "node16", + "newLine": "lf", "skipLibCheck": true, - "strict": true + "strict": true, + "target": "es2020" } } From 1d8f30b3c57b5de391a42b3667b0127bf4cef379 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 16 Jan 2023 20:05:50 +0100 Subject: [PATCH 12/17] Add more JSDocs --- index.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 0994816..c09e358 100644 --- a/index.js +++ b/index.js @@ -2,14 +2,21 @@ * @typedef {import('xast').Root} Root * @typedef {import('xast').Element} Element * @typedef {import('xast').RootChildMap} RootChildMap + */ + +/** * @typedef {RootChildMap[keyof RootChildMap]} Child - * @typedef {Root|Child} Node - * @typedef {Root|Element} Parent + * @typedef {Root | Child} Node + * @typedef {Root | Element} Parent */ /** + * Get the plain-text value of a node. + * * @param {Node} node + * Node to serialize. * @returns {string} + * Serialized node. */ export function toString(node) { // A root or an element @@ -18,8 +25,12 @@ export function toString(node) { } /** + * Serialize a child. + * * @param {Node} node + * Child to serialize. * @returns {string} + * Serialized node. */ function one(node) { if (node.type === 'text') return node.value @@ -28,8 +39,12 @@ function one(node) { } /** + * Serialize a parent. + * * @param {Parent} node + * Parent to serialize. * @returns {string} + * Serialized node. */ function all(node) { const children = node.children From de13ee23a2e24d7f206a5cba7c3685b14fcf5bb9 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 16 Jan 2023 20:08:07 +0100 Subject: [PATCH 13/17] Use Node test runner --- .github/workflows/main.yml | 2 +- package.json | 3 +-- test.js | 25 ++++++++++++++----------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 89dc06c..fb63387 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,5 +17,5 @@ jobs: strategy: matrix: node: - - lts/fermium + - lts/gallium - node diff --git a/package.json b/package.json index 1c0448b..0604a25 100644 --- a/package.json +++ b/package.json @@ -36,12 +36,11 @@ "@types/xast": "^1.0.0" }, "devDependencies": { - "@types/tape": "^4.0.0", + "@types/node": "^18.0.0", "c8": "^7.0.0", "prettier": "^2.0.0", "remark-cli": "^11.0.0", "remark-preset-wooorm": "^9.0.0", - "tape": "^5.0.0", "type-coverage": "^2.0.0", "typescript": "^4.0.0", "unist-builder": "^3.0.0", diff --git a/test.js b/test.js index a89e220..2649cfe 100644 --- a/test.js +++ b/test.js @@ -1,31 +1,36 @@ -import test from 'tape' +import assert from 'node:assert/strict' +import test from 'node:test' import {u} from 'unist-builder' import {toString} from './index.js' -test('xast-util-to-string', (t) => { - t.deepEqual( +test('xast-util-to-string', () => { + assert.deepEqual( toString(u('cdata', 'Hello, world!')), 'Hello, world!', 'should serialize cdata' ) - t.deepEqual(toString(u('comment', 'foo')), 'foo', 'should serialize comments') + assert.deepEqual( + toString(u('comment', 'foo')), + 'foo', + 'should serialize comments' + ) - t.deepEqual( + assert.deepEqual( toString(u('instruction', {name: 'xml'}, 'version="1.0" encoding="UTF-8"')), 'version="1.0" encoding="UTF-8"', 'should serialize instructions' ) - t.deepEqual(toString(u('text', 'foo')), 'foo', 'should serialize texts') + assert.deepEqual(toString(u('text', 'foo')), 'foo', 'should serialize texts') - t.deepEqual( + assert.deepEqual( toString(u('doctype', {name: 'html'})), '', 'should return empty for doctypes' ) - t.deepEqual( + assert.deepEqual( toString( u('element', {name: 'package'}, [ u('text', 'foo '), @@ -37,7 +42,7 @@ test('xast-util-to-string', (t) => { 'should serialize elements (excluding non-parent and non-text descendants)' ) - t.deepEqual( + assert.deepEqual( toString( u('root', [ u('doctype', {name: 'html'}), @@ -49,6 +54,4 @@ test('xast-util-to-string', (t) => { 'foo baz', 'should serialize roots (excluding non-parent and non-text descendants)' ) - - t.end() }) From 34fd4b7706fbc4729a307cadc50e9658b7495ab3 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 16 Jan 2023 20:08:44 +0100 Subject: [PATCH 14/17] Refactor to move implementation to `lib/` --- index.js | 61 +--------------------------------------------------- lib/index.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 62 insertions(+), 60 deletions(-) create mode 100644 lib/index.js diff --git a/index.js b/index.js index c09e358..361171e 100644 --- a/index.js +++ b/index.js @@ -1,60 +1 @@ -/** - * @typedef {import('xast').Root} Root - * @typedef {import('xast').Element} Element - * @typedef {import('xast').RootChildMap} RootChildMap - */ - -/** - * @typedef {RootChildMap[keyof RootChildMap]} Child - * @typedef {Root | Child} Node - * @typedef {Root | Element} Parent - */ - -/** - * Get the plain-text value of a node. - * - * @param {Node} node - * Node to serialize. - * @returns {string} - * Serialized node. - */ -export function toString(node) { - // A root or an element - if ('children' in node) return all(node) - return 'value' in node ? node.value : '' -} - -/** - * Serialize a child. - * - * @param {Node} node - * Child to serialize. - * @returns {string} - * Serialized node. - */ -function one(node) { - if (node.type === 'text') return node.value - // Ignore things like comments, instruction, cdata. - return 'children' in node ? all(node) : '' -} - -/** - * Serialize a parent. - * - * @param {Parent} node - * Parent to serialize. - * @returns {string} - * Serialized node. - */ -function all(node) { - const children = node.children - let index = -1 - /** @type {Array} */ - const result = [] - - while (++index < children.length) { - result[index] = one(children[index]) - } - - return result.join('') -} +export {toString} from './lib/index.js' diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..c09e358 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,60 @@ +/** + * @typedef {import('xast').Root} Root + * @typedef {import('xast').Element} Element + * @typedef {import('xast').RootChildMap} RootChildMap + */ + +/** + * @typedef {RootChildMap[keyof RootChildMap]} Child + * @typedef {Root | Child} Node + * @typedef {Root | Element} Parent + */ + +/** + * Get the plain-text value of a node. + * + * @param {Node} node + * Node to serialize. + * @returns {string} + * Serialized node. + */ +export function toString(node) { + // A root or an element + if ('children' in node) return all(node) + return 'value' in node ? node.value : '' +} + +/** + * Serialize a child. + * + * @param {Node} node + * Child to serialize. + * @returns {string} + * Serialized node. + */ +function one(node) { + if (node.type === 'text') return node.value + // Ignore things like comments, instruction, cdata. + return 'children' in node ? all(node) : '' +} + +/** + * Serialize a parent. + * + * @param {Parent} node + * Parent to serialize. + * @returns {string} + * Serialized node. + */ +function all(node) { + const children = node.children + let index = -1 + /** @type {Array} */ + const result = [] + + while (++index < children.length) { + result[index] = one(children[index]) + } + + return result.join('') +} diff --git a/package.json b/package.json index 0604a25..757b1ce 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "main": "index.js", "types": "index.d.ts", "files": [ + "lib/", "index.d.ts", "index.js" ], From 134d0cc59d8b2bb36a990eba4d79dd1e1666cf56 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 16 Jan 2023 20:09:10 +0100 Subject: [PATCH 15/17] Add tests for exposed identifiers --- test.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test.js b/test.js index 2649cfe..f8e52d5 100644 --- a/test.js +++ b/test.js @@ -2,8 +2,15 @@ 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' + +test('toString', () => { + assert.deepEqual( + Object.keys(mod).sort(), + ['toString'], + 'should expose the public api' + ) -test('xast-util-to-string', () => { assert.deepEqual( toString(u('cdata', 'Hello, world!')), 'Hello, world!', From 16cd9533d7dea1c3e8424b7d121275f98c6afd36 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 16 Jan 2023 20:11:46 +0100 Subject: [PATCH 16/17] Add improved docs --- readme.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/readme.md b/readme.md index 1f387db..b1197cb 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 12.20+, 14.14+, 16.0+, 18.0+), install with [npm][]: +In Node.js (version 14.14+ and 16.0+), 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@2' ``` In browsers with [`esm.sh`][esmsh]: ```html ``` @@ -89,17 +89,17 @@ A Christmas CarolCharles Dickens ## API -This package exports the identifier `toString`. +This package exports the identifier [`toString`][tostring]. There is no default export. ### `toString(node)` Get the plain text value of a node. -If the node has a `value` field ([*cdata*][cdata], [*comment*][comment], -[*doctype*][doctype], [*instruction*][instruction], or [*text*][text]), returns -it. -If the node has a `children` field ([*root*][root] or [*element*][element]), -recurses into it to concatenate all [*text*][text]s. + +If the node has a `value` field (*[cdata][]*, *[comment][]*, *[doctype][]*, +*[instruction][]*, or *[text][]*), returns it. +If the node has a `children` field (*[root][]* or *[element][]*), recurses into +it to concatenate all texts. ###### Returns @@ -114,7 +114,7 @@ It exports no additional types. Projects maintained by the unified collective are compatible with all maintained versions of Node.js. -As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+. +As of now, that is Node.js 14.14+ and 16.0+. Our projects sometimes work with older versions, but this is not guaranteed. ## Security @@ -214,3 +214,5 @@ abide by its terms. [text]: https://github.com/syntax-tree/xast#text [xss]: https://en.wikipedia.org/wiki/Cross-site_scripting + +[tostring]: #tostringnode From aed0cea17c17d0d6e2265e4dfe42e20b78ea75ad Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 16 Jan 2023 20:13:01 +0100 Subject: [PATCH 17/17] 2.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 757b1ce..a4c45f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xast-util-to-string", - "version": "2.0.0", + "version": "2.0.1", "description": "xast utility to get the text value of a node", "license": "MIT", "keywords": [