{"name":"htmlfy","version":"0.6.0","keywords":["HTML","format","formatter","prettier","minifier","prettify","minify"],"license":"MIT","_id":"htmlfy@0.6.0","maintainers":[{"name":"j4w8n","email":"jason@malynium.com"}],"homepage":"https://github.com/j4w8n/htmlfy#readme","bugs":{"url":"https://github.com/j4w8n/htmlfy/issues"},"dist":{"shasum":"f411f99b3299f1b97b46696f6a0f0a19e6eaf6c5","tarball":"http://registry-npm.ywwl.com/htmlfy/download/htmlfy-0.6.0.tgz","fileCount":11,"integrity":"sha512-EV1RNjYuG6xIxwA8zDjAUQVeS/SsPE0nhFsdjM8ALopS22ZRAcePocdrhKaaV26PYiTkUrKplJuSZkGRN6Y0Rg==","signatures":[{"sig":"MEUCIQD/lSMq4lnnFzJXx/oyhzA6b2H8n8GBQzdqCzuot3duRQIgGG4WSqh0b54R/aUJK8Pl/M765CcMMNYVH9abHEGLqWM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":26931,"size":8313,"noattachment":false,"key":"/htmlfy/-/htmlfy-0.6.0.tgz"},"type":"module","_from":"file:htmlfy-0.6.0.tgz","types":"types/index.d.ts","exports":{".":{"types":"./types/index.d.ts","import":"./src/exports/index.js","require":"./src/exports/index.js"}},"scripts":{"test":"vitest","check":"tsc"},"_npmUser":{"name":"j4w8n","email":"jason@malynium.com"},"_resolved":"/tmp/2272f4aeedb9ecba3b864278d9c58111/htmlfy-0.6.0.tgz","_integrity":"sha512-EV1RNjYuG6xIxwA8zDjAUQVeS/SsPE0nhFsdjM8ALopS22ZRAcePocdrhKaaV26PYiTkUrKplJuSZkGRN6Y0Rg==","repository":{"url":"git+https://github.com/j4w8n/htmlfy.git","type":"git"},"_npmVersion":"10.2.5","description":"HTML formatter yo! Prettify, minify, and more!","directories":{},"_nodeVersion":"20.10.0","_hasShrinkwrap":false,"devDependencies":{"vitest":"^2.1.2","typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/htmlfy_0.6.0_1737482182788_0.7849261019459219","host":"s3://npm-registry-packages-npm-production"},"readme":"# htmlfy\n\n[![npm][1]][2] [![install size][3]][4] [![downloads][5]][2]\n\n[1]: https://img.shields.io/npm/v/htmlfy \"htmlfy, npm badge\"\n[2]: https://www.npmjs.com/package/htmlfy \"htmlfy, npm link\"\n[3]: https://packagephobia.now.sh/badge?p=htmlfy \"htmlfy size, badge\"\n[4]: https://packagephobia.now.sh/result?p=htmlfy \"htmlfy size, link\"\n[5]: https://badgen.now.sh/npm/dm/htmlfy \"htmlfy downloads, badge\"\n\nHTML formatter yo!\n\nPrettier html, minified html, and a few more goodies.\n\n`htmlfy` is a fork of [html-formatter](https://github.com/uznam8x/html-formatter/tree/master). Some of the processing logic has been preserved, and full credit for that goes to the original author.\n\nI've made the following enhancements:\n\n- Fully typed\n- Converted to ESM\n- Configuration options\n- Support for custom HTML elements (web components)\n- Refactoring galore\n- Made it go brrr fast\n\n## Install\n\n`bun add htmlfy`\n\n## API\n\n### Prettify\nTurn single-line or ugly HTML into highly formatted HTML. You can pass a configuration object as the second argument.\n\n```js\nimport { prettify } from 'htmlfy'\n\nconst html = `<main class=\"hello   there world\"><div>Welcome to htmlfy!  </div></main>`\nconsole.log(prettify(html))\n/*\n<main class=\"hello there world\">\n  <div>\n    Welcome to htmlfy!\n  </div>\n</main>\n*/\n```\n\n### Minify\nTurn well-formatted or ugly HTML into a single line of HTML. You can pass a configuration object as the second argument. This function is called internally when you use `prettify`.\n\n> This feature is not a replacement for compressors like [htmlnano](https://github.com/posthtml/htmlnano), which focus on giving you the smallest data-size possible.\n\n```js\nimport { minify } from 'htmlfy'\n\nconst html = \n`<main class=\"hello there world\">\n  <div>\n    Welcome to htmlfy!\n  </div>\n</main>`\nconsole.log(minify(html))\n/*\n<main class=\"hello there world\"><div>Welcome to htmlfy!</div></main>\n*/\n```\n\n### Closify\nA standalone function that ensures [void elements](https://developer.mozilla.org/en-US/docs/Glossary/Void_element) are \"self-closing\".\n\n```js\nimport { closify } from 'htmlfy'\n\nconst html = `<br><input type=\"text\">`\nconsole.log(closify(html))\n/*\n<br /><input type=\"text\" />\n*/\n```\n\nIt also normalizes non-void elements which happen to be self-closing for whatever reason.\n\n```js\nimport { closify } from 'htmlfy'\n\nconst html = `<form class=\"hello\" />`\nconsole.log(closify(html))\n/*\n<form class=\"hello\"></form>\n*/\n```\n\n### Entify\nA standalone function that enforces entity characters for textarea content. You can pass `true ` as the `minify` to minify the tags themselves. Note that this does not run the HTML through the `minify` function.\n\n```js\nimport { entify } from 'htmlfy'\n\nconst html = `<main class=\"hello   there world\"><div>Welcome to htmlfy!  </div></main><textarea  >\n\nDid   you know that 3 >   2?\n\nThis is another paragraph.   \n\n\n</textarea><textarea class=\"  more  stuff  \">    </textarea>`\nconsole.log(entify(html, true))\n/*\n<main class=\"hello   there world\"><div>Welcome to htmlfy!  </div></main><textarea>&#10;&#10;Did&nbsp;&nbsp;&nbsp;you&nbsp;know&nbsp;that&nbsp;3&nbsp;&gt;&nbsp;&nbsp;&nbsp;2?&#10;&#10;This&nbsp;is&nbsp;another&nbsp;paragraph.&nbsp;&nbsp;&nbsp;&#10;&#10;&#10;</textarea><textarea class=\"more stuff\">&nbsp;&nbsp;&nbsp;&nbsp;</textarea>\n*/\n```\n\n### Trimify\nA standalone function that trims leading and trailing whitespace for whatever HTML elements you'd like.\n\n```js\nimport { trimify } from 'htmlfy'\n\nconst html = `<div>\nHello    World\n</div>`\nconsole.log(trimify(html, ['div']))\n/* <div>Hello    World</div> */\n```\n\n### Default Import\nIf needed, you can use a default import for `htmlfy`.\n\n```js\nimport * as htmlfy from 'htmlfy'\n\nconsole.log(htmlfy.prettify('<main><div>Hello World</div></main'))\n```\n\n### Common JS Import\nAlthough meant to be an ESM module, you can import using `require`.\n\n```js\nconst { prettify } = require('htmlfy')\n```\n\n## Configuration\nThese configuration options can be passed to `prettify` or `minify`. Note that as of now, only the `ignore` and `ignore_with` are relevant for `minify`.\n\nDefault config:\n```js\n{\n  content_wrap: 0,\n  ignore: [],\n  ignore_with: '_!i-£___£%_',\n  strict: false,\n  tab_size: 2,\n  tag_wrap: 0,\n  trim: []\n}\n```\n\n### Content Wrap\nWrap text content at a certain character-width breakpoint. Default is `0`, which does not wrap.\n\n```js\nimport { prettify } from 'htmlfy'\n\nconst html = '<div>Lorem ipsum dolor sit amet consectetur adipiscing elit. Quisque faucibus ex sapien vitae pellentesque sem placerat. In id cursus mi pretium tellus duis convallis.</div>'\nconsole.log(prettify(html, { content_wrap: 40 }))\n/*\n<div>\n  Lorem ipsum dolor sit amet consectetur\n  adipiscing elit. Quisque faucibus ex\n  sapien vitae pellentesque sem placerat.\n  In id cursus mi pretium tellus duis\n  convallis.\n</div>\n*/\n```\n\n### Ignore\nTell htmlfy to not process some elements' content and leave them as-is. Note this still minifies the tags themselves.\n\n```js\nimport { prettify } from 'htmlfy'\n\nconst html = `\n<main><div>Hello World</div></main>\n<style  >\nbody {\n  width: 100\n}\n</style>`\nconsole.log(prettify(html, { ignore: ['style'] }))\n/*\n<main>\n  <div>\n    Hello World\n  </div>\n</main>\n<style>\nbody {\n  width: 100;\n}\n</style>\n*/\n```\n\n### Ignore With\nYou can pass in your own string, for ignoring elements, if the default is actually being used in the elements you want to ignore.\n\n```js\nprettify(html, { ignore: ['p'], ignore_with: 'some-string-that-wont-be-in-your-ignored-elements' })\n```\n\n### Strict\nIf set to `true`, removes comments and ensures void elements are not self-closing.\n\n```js\nimport { prettify } from 'htmlfy'\n\nconst html = `<main><br /><div><!-- Hello World --></div></main>`\nconsole.log(prettify(html, { strict: true }))\n/*\n<main>\n  <br>\n  <div></div>\n</main>\n*/\n```\n\n### Tab Size\nDetermines the number of spaces, per tab, for indentation. For sanity reasons, the valid range is between 1 and 16.\n\n```js\nimport { prettify } from 'htmlfy'\n\nconst html = `<main class=\"hello   there world\"><div>Welcome to htmlfy!  </div></main>`\nconsole.log(prettify(html, { tab_size: 4 }))\n/*\n<main class=\"hello there world\">\n    <div>\n        Welcome to htmlfy!\n    </div>\n</main>\n*/\n```\n\n### Tag Wrap\nWrap and prettify attributes within opening tags and void elements if they're overall length is above a certain character width. Default is `0`, which does not wrap.\n\nIn the below example, the `<input>` element is well over 40 characters long, so it's wrapped and prettified.\n\n```js\nimport { prettify } from 'htmlfy'\n\nconst html = `<form><input id=\"email-0\" type=\"email\" title=\"We need your email for verification.\" name=\"email\" required /></form>`\nconsole.log(prettify(html, { tag_wrap: 40 }))\n/*\n<form>\n  <input\n    id=\"email-0\"\n    type=\"email\"\n    title=\"We need your email for verification.\"\n    name=\"email\"\n    required\n  />\n</form>\n*/\n```\n\n### Trim\nTrim leading and trailing whitespace within elements. Good for when you are ignoring certain elements, but still want to remove this whitespace.\n\n```js\nimport { prettify } from 'htmlfy'\n\nconst html = '<textarea>    Hello   World    </textarea>'\nconsole.log(prettify(html, { trim: ['textarea'], ignore: ['textarea']}))\n/*<textarea>Hello   World</textarea>*/\n```\n","publish_time":1737482182983,"_cnpm_publish_time":1737482182983,"dist-tags":{"latest":"1.1.0","next":"0.6.7-next.0"}}