Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
HTML formatter yo! Prettify, minify and more!
htmlfy
is a fork of html-formatter. Most of the processing logic has been preserved, and full credit for that goes to the original author. I've made the following major enhancements.
npm install htmlfy
Turn single-line or ugly HTML into highly formatted HTML. This is a wrapper for all other functions, and then it adds indentation.
import { prettify } from 'htmlfy'
const html = `<main class="hello there world"><div>Welcome to htmlfy! </div></main>`
console.log(prettify(html))
/*
<main class="hello there world">
<div>
Welcome to htmlfy!
</div>
</main>
*/
Turn well-formatted or ugly HTML into a single-line of HTML.
import { minify } from 'htmlfy'
const html =
`<main class="hello there world">
<div>
Welcome to htmlfy!
</div>
</main>`
console.log(minify(html))
/*
<main class="hello there world"><div>Welcome to htmlfy!</div></main>
*/
Ensure void elements are "self-closing".
import { closify } from 'htmlfy'
const html = `<br><input type="text">`
console.log(closify(html))
/*
<br /><input type="text" />
*/
Enforce entity characters for textarea content. This also performs basic minification on textareas before setting entities. When running this function as a standalone, you'll likely want to pass minify
as true
for full minification of the textarea. The minification does not process any other tags.
import { entify } from 'htmlfy'
const html = `<main class="hello there world"><div>Welcome to htmlfy! </div></main><textarea >
Did you know that 3 > 2?
This is another paragraph.
</textarea><textarea class=" more stuff "> </textarea>`
console.log(entify(html, true))
/*
<main class="hello there world"><div>Welcome to htmlfy! </div></main><textarea>Did you know that 3 > 2? This is another paragraph.</textarea><textarea class="more stuff"></textarea>
*/
If needed, you can use a default import for htmlfy
.
import * as htmlfy from 'htmlfy'
console.log(htmlfy.prettify('<main><div>Hello World</div></main'))
These configuration options can only be passed to prettify
.
Default config:
{
strict: false,
tab_size: 2
}
If set to true
, removes comments and ensures void elements are not self-closing.
import { prettify } from 'htmlfy'
const html = `<main><br /><div><!-- Hello World --></div></main>`
console.log(prettify(html, { strict: true }))
/*
<main>
<br>
<div></div>
</main>
*/
Determines the number of spaces, per tab, for indentation.
import { prettify } from 'htmlfy'
const html = `<main class="hello there world"><div>Welcome to htmlfy! </div></main>`
console.log(prettify(html, { tab_size: 4 }))
/*
<main class="hello there world">
<div>
Welcome to htmlfy!
</div>
</main>
*/
FAQs
HTML formatter yo!. Prettify, minify, and more!
We found that htmlfy demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.