{"author":{"name":"Keith McKnight","email":"keith@mcknig.ht","url":"https://keith.mcknig.ht"},"bugs":{"url":"https://github.com/syntax-tree/hast-util-from-dom/issues"},"contributors":[{"name":"Keith McKnight","email":"keith@mcknig.ht","url":"https://keith.mcknig.ht"},{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"dependencies":{"@types/hast":"^3.0.0","hastscript":"^9.0.0","web-namespaces":"^2.0.0"},"description":"hast utility to create a tree from the DOM","devDependencies":{"@types/jsdom":"^21.0.0","@types/node":"^22.0.0","c8":"^10.0.0","jsdom":"^25.0.0","prettier":"^3.0.0","remark-cli":"^12.0.0","remark-preset-wooorm":"^10.0.0","type-coverage":"^2.0.0","typescript":"^5.0.0","xo":"^0.59.0"},"exports":"./index.js","funding":{"type":"opencollective","url":"https://opencollective.com/unified"},"keywords":["dom","hast-util","hast","html","rehype","unist","utility","util"],"license":"ISC","name":"hast-util-from-dom","prettier":{"bracketSpacing":false,"semi":false,"singleQuote":true,"tabWidth":2,"trailingComma":"none","useTabs":false},"remarkConfig":{"plugins":["remark-preset-wooorm"]},"repository":{"type":"git","url":"git+https://github.com/syntax-tree/hast-util-from-dom.git"},"scripts":{"build":"tsc --build --clean && tsc --build && type-coverage","format":"remark --frail --quiet --output -- . && prettier --log-level warn --write -- . && xo --fix","test-api":"node --conditions development test/index.js","test-coverage":"c8 --100 --reporter lcov -- npm run test-api","test":"npm run build && npm run format && npm run test-coverage"},"sideEffects":false,"typeCoverage":{"atLeast":100,"strict":true},"type":"module","version":"5.0.1","xo":{"overrides":[{"files":"test/**/*.js","rules":{"no-await-in-loop":"off"}}],"prettier":true},"_id":"hast-util-from-dom@5.0.1","gitHead":"a00e71765db75da0fbae2e86c90215aac2901335","types":"./index.d.ts","homepage":"https://github.com/syntax-tree/hast-util-from-dom#readme","_nodeVersion":"23.1.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-N+LqofjR2zuzTjCPzyDUdSshy4Ma6li7p/c3pA78uTwzFgENbgbUrm2ugwsOdcjI1muO+o6Dgzp9p8WHtn/39Q==","shasum":"c3c92fbd8d4e1c1625edeb3a773952b9e4ad64a8","tarball":"http://registry-npm.ywwl.com/hast-util-from-dom/download/hast-util-from-dom-5.0.1.tgz","fileCount":9,"unpackedSize":16369,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDOJybsLtqqg0ODptvcQu5JP1pkBM8nKRx9ka4Ds5j9jQIhAO7pUe2155TSKTZhGmJ1GbnSE/G5vDU1ul8dkUcUr7Vr"}],"size":5699,"noattachment":false,"key":"/hast-util-from-dom/-/hast-util-from-dom-5.0.1.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"},{"name":"kmck","email":"keith@mcknig.ht"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hast-util-from-dom_5.0.1_1732007910346_0.18724328486116293"},"_hasShrinkwrap":false,"readme":"# hast-util-from-dom\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 transform from a [DOM][] tree.\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  * [`fromDom(tree, options?)`](#fromdomtree-options)\n  * [`AfterTransform`](#aftertransform)\n  * [`Options`](#options)\n* [Types](#types)\n* [Compatibility](#compatibility)\n* [Security](#security)\n* [Contribute](#contribute)\n* [Related](#related)\n* [License](#license)\n\n## What is this?\n\nThis package is a utility that takes a DOM tree (from the actual DOM or from\nthings like [`jsdom`][jsdom]) as input and turns it into a [hast][] (HTML)\nsyntax tree.\n\n## When should I use this?\n\nYou can use this project when you want to use hast in browsers.\nThis package is very small, but it does so by:\n\n* …not providing positional information\n* …potentially yielding varying results in different (especially older)\n  browsers\n\nThe hast utility [`hast-util-to-dom`][hast-util-to-dom] does the inverse of this\nutility.\nIt turns hast into a DOM tree.\n\nThe rehype plugin [`rehype-dom-parse`][rehype-dom-parse] wraps this utility to\nparse HTML with DOM APIs.\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-from-dom\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {fromDom} from 'https://esm.sh/hast-util-from-dom@5'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {fromDom} from 'https://esm.sh/hast-util-from-dom@5?bundle'\n</script>\n```\n\n## Use\n\nSay our page `example.html` looks as follows:\n\n```html\n<!doctype html>\n<title>Example</title>\n<body>\n  <main>\n    <h1>Hi</h1>\n    <p><em>Hello</em>, world!</p>\n  </main>\n  <script type=\"module\">\n    import {fromDom} from 'https://esm.sh/hast-util-from-dom@4?bundle'\n\n    const hast = fromDom(document.querySelector('main'))\n\n    console.log(hast)\n  </script>\n```\n\nNow running `open example.html` prints the following to the console:\n\n```js\n{type: \"element\", tagName: \"main\", properties: {}, children: Array}\n```\n\n## API\n\nThis package exports the identifier [`fromDom`][api-from-dom].\nThere is no default export.\n\n### `fromDom(tree, options?)`\n\nTransform a DOM tree to a hast tree.\n\n###### Parameters\n\n* `tree` ([`DomNode`][dom-node])\n  — DOM tree to transform\n* `options` ([`Options`][api-options], optional)\n  — configuration\n\n###### Returns\n\nEquivalent hast node ([`HastNode`][hast-node]).\n\n### `AfterTransform`\n\nCallback called when each node is transformed (TypeScript type).\n\n###### Parameters\n\n* `domNode` ([`DomNode`][dom-node])\n  — DOM node that was handled\n* `hastNode` ([`HastNode`][hast-node])\n  — corresponding hast node\n\n###### Returns\n\nNothing.\n\n### `Options`\n\nConfiguration (TypeScript type).\n\n##### Fields\n\n* `afterTransform` ([`AfterTransform`][api-after-transform], optional)\n  — callback called when each node is transformed\n\n##### Returns\n\n[`HastNode`][hast-node].\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`AfterTransform`][api-after-transform] and\n[`Options`][api-options].\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-from-dom@^5`,\ncompatible with Node.js 16.\n\n## Security\n\nUse of `hast-util-from-dom` itself is safe but see other utilities for more\ninformation on potential security problems.\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, organisation, or community you agree to\nabide by its terms.\n\n## Related\n\n* [`hast-util-from-html`][hast-util-from-html]\n  — parse hast from a string of HTML\n* [`hast-util-sanitize`](https://github.com/syntax-tree/hast-util-sanitize)\n  — sanitize hast nodes\n* [`hast-util-to-html`](https://github.com/syntax-tree/hast-util-to-html)\n  — serialize hast as HTML\n* [`hast-util-to-dom`](https://github.com/syntax-tree/hast-util-to-dom)\n  — create DOM trees from hast\n\n## License\n\n[ISC][license] © [Keith McKnight][author]\n\n<!-- Definitions -->\n\n[build-badge]: https://github.com/syntax-tree/hast-util-from-dom/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/hast-util-from-dom/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-from-dom.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/hast-util-from-dom\n\n[downloads-badge]: https://img.shields.io/npm/dm/hast-util-from-dom.svg\n\n[downloads]: https://www.npmjs.com/package/hast-util-from-dom\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-from-dom\n\n[size]: https://bundlejs.com/?q=hast-util-from-dom\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://keith.mcknig.ht\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[hast]: https://github.com/syntax-tree/hast\n\n[hast-node]: https://github.com/syntax-tree/hast#nodes\n\n[dom]: https://developer.mozilla.org/docs/Web/API/Document_Object_Model\n\n[dom-node]: https://developer.mozilla.org/docs/Web/API/Node\n\n[hast-util-from-html]: https://github.com/syntax-tree/hast-util-from-html\n\n[hast-util-to-dom]: https://github.com/syntax-tree/hast-util-to-dom\n\n[rehype-dom-parse]: https://github.com/rehypejs/rehype-dom/tree/main/packages/rehype-dom-parse\n\n[jsdom]: https://github.com/jsdom/jsdom\n\n[api-from-dom]: #fromdomtree-options\n\n[api-options]: #options\n\n[api-after-transform]: #aftertransform\n","publish_time":1732007910519,"_cnpm_publish_time":1732007910519,"dist-tags":{"latest":"5.0.1"}}