{"_id":"hast-util-to-text@4.0.3","bugs":{"url":"https://github.com/syntax-tree/hast-util-to-text/issues"},"dist":{"shasum":"0405bfc159113a2df02ae15f3e77685260df4e61","tarball":"http://registry-npm.ywwl.com/hast-util-to-text/download/hast-util-to-text-4.0.3.tgz","fileCount":9,"integrity":"sha512-5yrlWOvGFs6CqHriUpSsNrjzT/Tdo+IOQudbznxOn8K5qblp18MJyzOg8IgDOKQ8MYgQcJA7SusuCjSpDr8mSA==","signatures":[{"sig":"MEQCICIAyY2fM/wOCBhws65wpmbOrX/jquNzkkqsJLLXmL8tAiBK2USTxB31CBYbVG5+Zq5fVQF9gz6ClW3FfSqN5OXMZQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQC9TQxdImmHKrLbgMkfAt+mD1vNeOD3awc2otFK1eoLJAIgdDGU0bAdkimwNM3xtUCLJE4s3T2HzSMGfwAmoHzmpfI="}],"unpackedSize":38021,"size":11790,"noattachment":false,"key":"/hast-util-to-text/-/hast-util-to-text-4.0.3.tgz"},"name":"hast-util-to-text","type":"module","types":"./index.d.ts","author":{"url":"https://wooorm.com","name":"Titus Wormer","email":"tituswormer@gmail.com"},"exports":"./index.js","funding":{"url":"https://opencollective.com/unified","type":"opencollective"},"gitHead":"6aeca3a28f690c1bbcb656f20192ecd1ba04ad2a","license":"MIT","scripts":{"test":"npm run build && npm run format && npm run test-coverage","build":"tsc --build --clean && tsc --build && type-coverage","format":"remark --frail --output --quiet -- . && prettier --log-level warn --write -- . && xo --fix","prepack":"npm run build && npm run format","test-api":"node --conditions development test.js","test-coverage":"c8 --100 --reporter lcov -- npm run test-api"},"version":"4.0.3","_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"homepage":"https://github.com/syntax-tree/hast-util-to-text#readme","keywords":["content","hast-util","hast","html","innertext","string","unist","utility","util","text"],"prettier":{"semi":false,"useTabs":false,"tabWidth":2,"singleQuote":true,"trailingComma":"none","bracketSpacing":false},"repository":{"url":"git+https://github.com/syntax-tree/hast-util-to-text.git","type":"git"},"_npmVersion":"12.2.1","description":"hast utility to get the plain-text value of a node according to the `innerText` algorithm","directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"},{"name":"kmck","email":"keith@mcknig.ht"}],"sideEffects":false,"_nodeVersion":"26.12.1","contributors":[{"url":"https://wooorm.com","name":"Titus Wormer","email":"tituswormer@gmail.com"}],"dependencies":{"@types/hast":"^3.0.0"},"remarkConfig":{"plugins":["remark-preset-wooorm"]},"typeCoverage":{"detail":true,"strict":true,"atLeast":100,"ignoreCatch":true},"_hasShrinkwrap":false,"devDependencies":{"c8":"^12.0.0","xo":"^5.0.0","prettier":"^3.0.0","hastscript":"^9.0.0","remark-cli":"^12.0.0","typescript":"^6.0.0","@types/node":"^26.0.0","type-coverage":"^2.0.0","remark-preset-wooorm":"^11.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/hast-util-to-text_4.0.3_1792927734980_0.935560066264334"},"readme":"# hast-util-to-text\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[hast][] 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  * [`toText(tree[, options])`](#totexttree-options)\n  * [`Options`](#options)\n  * [`Whitespace`](#whitespace)\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 [hast][] node and gets its plain-text\nvalue.\nIt is like the DOMs `Node#innerText`, which is a bit nicer than\n`Node#textContent`, because this turns `<br>` elements into line breaks and\nuses `'\\t'` (tabs) between table cells.\n\nThere are some small deviations from the spec, because the DOM has knowledge of\nassociated CSS, and can take into account that elements have `display: none` or\n`text-transform` association with them, and this utility can’t do that.\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 that is close to how it’s “visible” to users.\n\nThis utility is similar to [`hast-util-to-string`][hast-util-to-string], which\nis simpler, and more like the `Node#textContent` algorithm discussed above.\n\nThere is also a package [`hast-util-from-text`][hast-util-from-text], which sort\nof does the inverse: it takes a string, sets that as text on the node, while\nturning line endings into `<br>`s\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install hast-util-to-text\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {toText} from 'https://esm.sh/hast-util-to-text@4'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {toText} from 'https://esm.sh/hast-util-to-text@4?bundle'\n</script>\n```\n\n## Use\n\n```js\nimport {h} from 'hastscript'\nimport {toText} from 'hast-util-to-text'\n\nconst tree = h('div', [\n  h('h1', {hidden: true}, 'Alpha.'),\n  h('article', [\n    h('p', ['Bravo', h('br'), 'charlie.']),\n    h('p', 'Delta echo \\t foxtrot.')\n  ])\n])\n\nconsole.log(toText(tree))\n```\n\nYields:\n\n```text\nBravo\ncharlie.\n\nDelta echo foxtrot.\n```\n\n## API\n\nThis package exports the identifier [`toText`][api-to-text].\nThere is no default export.\n\n### `toText(tree[, options])`\n\nGet the plain-text value of a node.\n\n###### Parameters\n\n* `tree` ([`Node`][node])\n  — tree to turn into text\n* `options` ([`Options`][api-options], optional)\n  — configuration\n\n###### Returns\n\nSerialized `tree` (`string`).\n\n###### Algorithm\n\n* if `tree` is a [comment][], returns its `value`\n* if `tree` is a [text][], applies normal whitespace collapsing to its\n  `value`, as defined by the [CSS Text][css] spec\n* if `tree` is a [root][] or [element][], applies an algorithm similar to the\n  `innerText` getter as defined by [HTML][]\n\n###### Notes\n\n> 👉 **Note**: the algorithm acts as if `tree` is being rendered, and as if\n> we’re a CSS-supporting user agent, with scripting enabled.\n\n* if `tree` is an element that is not displayed (such as a `head`), we’ll\n  still use the `innerText` algorithm instead of switching to `textContent`\n* if descendants of `tree` are elements that are not displayed, they are\n  ignored\n* CSS is not considered, except for the default user agent style sheet\n* a line feed is collapsed instead of ignored in cases where Fullwidth, Wide,\n  or Halfwidth East Asian Width characters are used, the same goes for a case\n  with Chinese, Japanese, or Yi writing systems\n* replaced elements (such as `audio`) are treated like non-replaced elements\n\n### `Options`\n\nConfiguration (TypeScript type).\n\n##### Fields\n\n* `whitespace` ([`Whitespace`][api-whitespace], default: `'normal'`)\n  — default whitespace setting to use\n\n### `Whitespace`\n\nValid and useful whitespace values (from [CSS][]) (TypeScript type).\n\n##### Type\n\n```ts\ntype Whitespace = 'normal' | 'nowrap' | 'pre' | 'pre-wrap'\n```\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`Options`][api-options] and\n[`Whitespace`][api-whitespace].\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, `hast-util-to-text@^4`,\ncompatible with Node.js 16.\n\n## Security\n\n`hast-util-to-text` does not change the syntax tree so there are no\nopenings for [cross-site scripting (XSS)][xss] attacks.\n\n## Related\n\n* [`hast-util-to-string`][hast-util-to-string]\n  — get the plain-text value (`textContent`)\n* [`hast-util-from-text`][hast-util-from-text]\n  — set the plain-text value (`innerText`)\n* [`hast-util-from-string`\n  ](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<!-- Definitions -->\n\n[api-options]: #options\n\n[api-to-text]: #totexttree-options\n\n[api-whitespace]: #whitespace\n\n[author]: https://wooorm.com\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[build]: https://github.com/syntax-tree/hast-util-to-text/actions\n\n[build-badge]: https://github.com/syntax-tree/hast-util-to-text/workflows/main/badge.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[collective]: https://opencollective.com/unified\n\n[comment]: https://github.com/syntax-tree/hast#comment\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[coverage]: https://codecov.io/github/syntax-tree/hast-util-to-text\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-to-text.svg\n\n[css]: https://drafts.csswg.org/css-text/#white-space-phase-1\n\n[downloads]: https://www.npmjs.com/package/hast-util-to-text\n\n[downloads-badge]: https://img.shields.io/npm/dm/hast-util-to-text.svg\n\n[element]: https://github.com/syntax-tree/hast#element\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[hast]: https://github.com/syntax-tree/hast\n\n[hast-util-from-text]: https://github.com/syntax-tree/hast-util-from-text\n\n[hast-util-to-string]: https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-to-string\n\n[health]: https://github.com/syntax-tree/.github\n\n[html]: https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute\n\n[license]: license\n\n[node]: https://github.com/syntax-tree/hast#nodes\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[root]: https://github.com/syntax-tree/hast#root\n\n[size]: https://bundlejs.com/?q=hast-util-to-text\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=hast-util-to-text\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[text]: https://github.com/syntax-tree/hast#text\n\n[typescript]: https://www.typescriptlang.org\n\n[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n","publish_time":1792927735057,"_cnpm_publish_time":1792927735057,"dist-tags":{"latest":"4.0.3"}}