{"_id":"hast-util-format","_rev":"2-00800150aa6f692248ebb070f9f0c1f4","name":"hast-util-format","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"hast-util-format","version":"1.0.0","keywords":["ast","format","hast","html","pretty","tree","whitespace"],"author":{"url":"https://wooorm.com","name":"Titus Wormer","email":"tituswormer@gmail.com"},"license":"MIT","_id":"hast-util-format@1.0.0","maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"}],"contributors":[{"url":"https://wooorm.com","name":"Titus Wormer","email":"tituswormer@gmail.com"}],"homepage":"https://github.com/syntax-tree/hast-util-format#readme","bugs":{"url":"https://github.com/syntax-tree/hast-util-format/issues"},"xo":{"rules":{"complexity":"off","unicorn/prefer-at":"off","unicorn/prefer-string-replace-all":"off"},"prettier":true,"overrides":[{"files":["**/*.d.ts"],"rules":{"@typescript-eslint/ban-types":["error",{"extendDefaults":true}],"@typescript-eslint/array-type":["error",{"default":"generic"}],"@typescript-eslint/consistent-type-definitions":["error","interface"]}},{"files":["test/**/*.js"],"rules":{"no-await-in-loop":"off"}}]},"dist":{"shasum":"100022ce7724b9d8f5b1a78e2383f2a7e3fb1fab","tarball":"https://registry.npmjs.org/hast-util-format/-/hast-util-format-1.0.0.tgz","fileCount":10,"integrity":"sha512-5f3cZl70brOA4DasFZIfhKP4OQOQmtyP6sNJagQ+/Y0uuLH5Pfp4Bbt+oOx0xZC7ak2Sclp3Kbw9lTuFGbYnig==","signatures":[{"sig":"MEQCIBDJW/OO1grN9CkNDhXBMpC7bYcSuDf7Bua73KZDAfhOAiBAzU4IDMLY8+3j2/R6vy/Vz4bv9VAXblb5+EHXox1PZg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":16482},"type":"module","types":"./index.d.ts","exports":"./index.js","funding":{"url":"https://opencollective.com/unified","type":"opencollective"},"gitHead":"eb8bb246c9e94e5a1b611137dbb44838aaafb26a","scripts":{"test":"npm run build && npm run format && npm run test-coverage","build":"tsc --build --clean && tsc --build && type-coverage","format":"remark . -qfo && prettier . -w --log-level warn && xo --fix","prepack":"npm run build && npm run format","test-api":"node --conditions development test/index.js","test-coverage":"c8 --100 --reporter lcov npm run test-api"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"prettier":{"semi":false,"useTabs":false,"tabWidth":2,"singleQuote":true,"trailingComma":"none","bracketSpacing":false},"repository":{"url":"git+https://github.com/syntax-tree/hast-util-format.git","type":"git"},"_npmVersion":"10.8.3","description":"Format whitespace in HTML","directories":{},"sideEffects":false,"_nodeVersion":"22.7.0","dependencies":{"@types/hast":"^3.0.0","hast-util-embedded":"^3.0.0","hast-util-phrasing":"^3.0.0","hast-util-whitespace":"^3.0.0","unist-util-visit-parents":"^6.0.0","hast-util-minify-whitespace":"^1.0.0","html-whitespace-sensitive-tag-names":"^3.0.0"},"remarkConfig":{"plugins":["remark-api","remark-preset-wooorm"]},"typeCoverage":{"detail":true,"strict":true,"atLeast":100,"ignoreCatch":true},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.0.0","xo":"^0.59.0","prettier":"^3.0.0","remark-api":"^1.0.0","remark-cli":"^12.0.0","typescript":"^5.0.0","@types/node":"^22.0.0","type-coverage":"^2.0.0","hast-util-to-html":"^9.0.0","hast-util-from-html":"^2.0.0","remark-preset-wooorm":"^10.0.0"},"_npmOperationalInternal":{"tmp":"tmp/hast-util-format_1.0.0_1726741032393_0.4335675787031763","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"hast-util-format","version":"1.1.0","keywords":["ast","format","hast","html","pretty","tree","whitespace"],"author":{"url":"https://wooorm.com","name":"Titus Wormer","email":"tituswormer@gmail.com"},"license":"MIT","_id":"hast-util-format@1.1.0","maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"}],"contributors":[{"url":"https://wooorm.com","name":"Titus Wormer","email":"tituswormer@gmail.com"}],"homepage":"https://github.com/syntax-tree/hast-util-format#readme","bugs":{"url":"https://github.com/syntax-tree/hast-util-format/issues"},"xo":{"rules":{"complexity":"off","unicorn/prefer-at":"off","unicorn/prefer-string-replace-all":"off"},"prettier":true,"overrides":[{"files":["**/*.d.ts"],"rules":{"@typescript-eslint/ban-types":["error",{"extendDefaults":true}],"@typescript-eslint/array-type":["error",{"default":"generic"}],"@typescript-eslint/consistent-type-definitions":["error","interface"]}},{"files":["test/**/*.js"],"rules":{"no-await-in-loop":"off"}}]},"dist":{"shasum":"373e77382e07deb04f6676f1b4437e7d8549d985","tarball":"https://registry.npmjs.org/hast-util-format/-/hast-util-format-1.1.0.tgz","fileCount":10,"integrity":"sha512-yY1UDz6bC9rDvCWHpx12aIBGRG7krurX0p0Fm6pT547LwDIZZiNr8a+IHDogorAdreULSEzP82Nlv5SZkHZcjA==","signatures":[{"sig":"MEQCIH8vU7ZPnkfJpOzfUqmVzdl+uNOr3rwrtDe/P0gerzfvAiAhCwVw3MolJXBeJa4DgXVCKMwjL8jhnmU4x8osxPe2Zg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":16539},"type":"module","types":"./index.d.ts","exports":"./index.js","funding":{"url":"https://opencollective.com/unified","type":"opencollective"},"gitHead":"3f450bf99d7ec195a108cb179bf8e7ef0eb52827","scripts":{"test":"npm run build && npm run format && npm run test-coverage","build":"tsc --build --clean && tsc --build && type-coverage","format":"remark . -qfo && prettier . -w --log-level warn && xo --fix","prepack":"npm run build && npm run format","test-api":"node --conditions development test/index.js","test-coverage":"c8 --100 --reporter lcov npm run test-api"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"prettier":{"semi":false,"useTabs":false,"tabWidth":2,"singleQuote":true,"trailingComma":"none","bracketSpacing":false},"repository":{"url":"git+https://github.com/syntax-tree/hast-util-format.git","type":"git"},"_npmVersion":"10.8.3","description":"Format whitespace in HTML","directories":{},"sideEffects":false,"_nodeVersion":"22.7.0","dependencies":{"@types/hast":"^3.0.0","hast-util-embedded":"^3.0.0","hast-util-phrasing":"^3.0.0","hast-util-whitespace":"^3.0.0","unist-util-visit-parents":"^6.0.0","hast-util-minify-whitespace":"^1.0.0","html-whitespace-sensitive-tag-names":"^3.0.0"},"remarkConfig":{"plugins":["remark-api","remark-preset-wooorm"]},"typeCoverage":{"detail":true,"strict":true,"atLeast":100,"ignoreCatch":true},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.0.0","xo":"^0.59.0","prettier":"^3.0.0","remark-api":"^1.0.0","remark-cli":"^12.0.0","typescript":"^5.0.0","@types/node":"^22.0.0","type-coverage":"^2.0.0","hast-util-to-html":"^9.0.0","hast-util-from-html":"^2.0.0","remark-preset-wooorm":"^10.0.0"},"_npmOperationalInternal":{"tmp":"tmp/hast-util-format_1.1.0_1726744863794_0.26897655129769893","host":"s3://npm-registry-packages"}}},"time":{"created":"2024-09-19T10:17:12.392Z","modified":"2024-09-27T11:45:30.514Z","1.0.0":"2024-09-19T10:17:12.531Z","1.1.0":"2024-09-19T11:21:03.950Z"},"bugs":{"url":"https://github.com/syntax-tree/hast-util-format/issues"},"author":{"url":"https://wooorm.com","name":"Titus Wormer","email":"tituswormer@gmail.com"},"license":"MIT","homepage":"https://github.com/syntax-tree/hast-util-format#readme","keywords":["ast","format","hast","html","pretty","tree","whitespace"],"repository":{"url":"git+https://github.com/syntax-tree/hast-util-format.git","type":"git"},"description":"Format whitespace in HTML","contributors":[{"url":"https://wooorm.com","name":"Titus Wormer","email":"tituswormer@gmail.com"}],"maintainers":[{"email":"tituswormer@gmail.com","name":"wooorm"},{"email":"keith@mcknig.ht","name":"kmck"}],"readme":"# hast-util-format\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 format whitespace in HTML.\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  * [`Options`](#options)\n  * [`format(tree, options)`](#formattree-options)\n* [Compatibility](#compatibility)\n* [Related](#related)\n* [Security](#security)\n* [Contribute](#contribute)\n* [License](#license)\n\n## What is this?\n\nThis package is a utility that formats whitespace in HTML.\nIn short, it works as follows:\n\n* collapse all existing whitespace to either a line ending or a single space\n  ([`hast-util-minify-whitespace`][hast-util-minify-whitespace])\n* remove those spaces and line endings if they do not contribute to the\n  document\n* inject needed line endings\n* indent previously collapsed line endings properly\n\n## When should I use this?\n\nThis package is useful when you want to improve the readability of an HTML\nfragment as it adds insignificant but pretty whitespace between elements.\nThe plugin [`rehype-format`][rehype-format] uses this package to format HTML\nat the plugin level.\nThe package [`hast-util-minify-whitespace`][hast-util-minify-whitespace] does\nthe inverse.\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-format\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {format} from 'https://esm.sh/hast-util-format@1'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {format} from 'https://esm.sh/hast-util-format@1?bundle'\n</script>\n```\n\n## Use\n\nSay we have the following `example.html`:\n\n```html\n<!doCTYPE HTML><html>\n <head>\n    <title>Hello!</title>\n<meta charset=utf8>\n      </head>\n  <body><section>    <p>hi there</p>\n     </section>\n </body>\n</html>\n```\n\nSay we have the following `example.js`:\n\n```js\nimport fs from 'node:fs/promises'\nimport {format} from 'hast-util-format'\nimport {fromHtml} from 'hast-util-from-html'\nimport {toHtml} from 'hast-util-to-html'\n\nconst document = await fs.readFile('example.html', 'utf8')\n\nconst tree = fromHtml(document)\n\nformat(tree)\n\nconst result = toHtml(tree)\n\nconsole.log(result)\n```\n\n…now running `node example.js` yields:\n\n```html\n<!doctype html>\n<html>\n  <head>\n    <title>Hello!</title>\n    <meta charset=\"utf8\">\n  </head>\n  <body>\n    <section>\n      <p>hi there</p>\n    </section>\n  </body>\n</html>\n```\n\n> 👉 **Note**:\n> some of the changes have been made by `hast-util-to-html`.\n\n## API\n\n### `Options`\n\nConfiguration.\n\n###### Fields\n\n* `blanks?` (`Array<string> | null | undefined`)\n  — list of tag names to join with a blank line (default: `[]`);\n  these tags,\n  when next to each other,\n  are joined by a blank line (`\\n\\n`);\n  for example,\n  when `['head', 'body']` is given,\n  a blank line is added between these two\n* `indent?` (`string | number | null | undefined`)\n  — indentation per level (default: `2`);\n  when `number`,\n  uses that amount of spaces; when `string`,\n  uses that per indentation level\n* `indentInitial?` (`boolean | null | undefined`)\n  — whether to indent the first level (default: `true`);\n  this is usually the `<html>`,\n  thus not indenting `head` and `body`\n\n### `format(tree, options)`\n\nFormat whitespace in HTML.\n\n###### Parameters\n\n* `tree` (`Root`)\n  — tree\n* `options?` (`Options | null | undefined`)\n  — configuration (optional)\n\n###### Returns\n\nNothing (`undefined`).\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-format@1`,\ncompatible with Node.js 16.\n\n## Related\n\n* [`hast-util-minify-whitespace`][hast-util-minify-whitespace]\n  — minify whitespace between elements\n\n## Security\n\nThis package is safe.\n\n## Contribute\n\nSee [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get\nstarted.\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[build-badge]: https://github.com/syntax-tree/hast-util-format/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/hast-util-format/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-format.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/hast-util-format\n\n[downloads-badge]: https://img.shields.io/npm/dm/hast-util-format.svg\n\n[downloads]: https://www.npmjs.com/package/hast-util-format\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-format\n\n[size]: https://bundlejs.com/?q=hast-util-format\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[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esmsh]: https://esm.sh\n\n[license]: license\n\n[author]: https://wooorm.com\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/hast/hast\n\n[hast-util-minify-whitespace]: https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-minify-whitespace\n\n[rehype-format]: https://github.com/rehypejs/rehype-format\n","readmeFilename":"readme.md"}