{"id":29125774,"url":"https://github.com/syntax-tree/xast-util-to-string","last_synced_at":"2025-06-29T22:03:36.569Z","repository":{"id":43396601,"uuid":"304862550","full_name":"syntax-tree/xast-util-to-string","owner":"syntax-tree","description":"xast utility to get the text value of a node","archived":false,"fork":false,"pushed_at":"2023-07-18T10:47:21.000Z","size":59,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-06-04T01:08:26.092Z","etag":null,"topics":["string","text","unist","xast","xast-util"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syntax-tree.png","metadata":{"funding":{"github":"unifiedjs","open_collective":"unified"},"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-17T11:29:28.000Z","updated_at":"2023-06-30T09:19:05.000Z","dependencies_parsed_at":"2024-06-20T00:09:37.586Z","dependency_job_id":null,"html_url":"https://github.com/syntax-tree/xast-util-to-string","commit_stats":{"total_commits":36,"total_committers":2,"mean_commits":18.0,"dds":0.02777777777777779,"last_synced_commit":"04b668c4017c82d9fad53afb4ef8adbc3555f113"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/xast-util-to-string","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast-util-to-string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast-util-to-string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast-util-to-string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast-util-to-string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/xast-util-to-string/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast-util-to-string/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260609424,"owners_count":23035941,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["string","text","unist","xast","xast-util"],"created_at":"2025-06-29T22:03:35.516Z","updated_at":"2025-06-29T22:03:36.515Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","readme":"# xast-util-to-string\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[xast][] utility to get the plain-text value of a node.\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`toString(node)`](#tostringnode)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package is a utility that takes a [xast][] node and gets its plain-text\nvalue.\nThis is like the DOMs `Node#textContent` getter but there are some small\ndeviations.\n\n## When should I use this?\n\nThis is a small utility that is useful when you want a plain-text version of a\nnode when working with xast (XML).\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install xast-util-to-string\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {toString} from 'https://esm.sh/xast-util-to-string@3'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {toString} from 'https://esm.sh/xast-util-to-string@3?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport {x} from 'xastscript'\nimport {toString} from 'xast-util-to-string'\n\nconst tree = x(\n  'ncx',\n  {xmlns: 'http://www.daisy.org/z3986/2005/ncx/', version: '2005-1'},\n  [\n    x('head', [\n      x('meta', {name: 'dtb:uid', content: 'urn:isbn:9781234567891'})\n    ]),\n    x('docTitle', [x('text', 'A Christmas Carol')]),\n    x('docAuthor', [x('text', 'Charles Dickens')])\n  ]\n)\n\nconsole.log(toString(tree))\n```\n\nYields:\n\n```txt\nA Christmas CarolCharles Dickens\n```\n\n## API\n\nThis package exports the identifier [`toString`][api-to-string].\nThere is no default export.\n\n### `toString(node)`\n\nGet the plain text value of a node.\n\nIf the node has a `value` field (*[cdata][]*, *[comment][]*, *[doctype][]*,\n*[instruction][]*, or *[text][]*), returns it.\nIf the node has a `children` field (*[root][]* or *[element][]*), recurses into\nit to concatenate all texts.\n\n###### Returns\n\nSerialized `node` (`string`).\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports no additional types.\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line, `xast-util-to-string@^3`,\ncompatible with Node.js 16.\n\n## Security\n\n`xast-util-to-string` does not change the syntax tree so there are no openings\nfor [cross-site scripting (XSS)][xss] attacks.\n\n## Related\n\n*   [`xast-util-to-xml`](https://github.com/syntax-tree/xast-util-to-xml)\n    — serialize xast to XML\n*   [`hast-util-to-string`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-to-string)\n    — get the plain-text value (`textContent`)\n*   [`hast-util-to-text`](https://github.com/syntax-tree/hast-util-to-text)\n    — get the plain-text value (`innerText`)\n*   [`hast-util-from-text`](https://github.com/syntax-tree/hast-util-from-text)\n    — set the plain-text value (`innerText`)\n*   [`hast-util-from-string`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-from-string)\n    — set the plain-text value (`textContent`)\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/syntax-tree/xast-util-to-string/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/xast-util-to-string/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/xast-util-to-string.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/xast-util-to-string\n\n[downloads-badge]: https://img.shields.io/npm/dm/xast-util-to-string.svg\n\n[downloads]: https://www.npmjs.com/package/xast-util-to-string\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=xast-util-to-string\n\n[size]: https://bundlejs.com/?q=xast-util-to-string\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[typescript]: https://www.typescriptlang.org\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[xast]: https://github.com/syntax-tree/xast\n\n[root]: https://github.com/syntax-tree/xast#root\n\n[comment]: https://github.com/syntax-tree/xast#comment\n\n[cdata]: https://github.com/syntax-tree/xast#cdata\n\n[doctype]: https://github.com/syntax-tree/xast#doctype\n\n[element]: https://github.com/syntax-tree/xast#element\n\n[instruction]: https://github.com/syntax-tree/xast#instruction\n\n[text]: https://github.com/syntax-tree/xast#text\n\n[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n\n[api-to-string]: #tostringnode\n","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fxast-util-to-string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Fxast-util-to-string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fxast-util-to-string/lists"}