
If you’ve ever worked with HTML, you know the frustration of dealing with those pesky character entities like ‘<‘ and ‘>’.
Well, fear not! htmled is a simple JavaScript library that makes encoding and decoding HTML entities a breeze. It works with both browser and Node.js and currently supports over 2100 HTML entities.
How to use it:
1. Install and import the htmled.js with NPM.
# NPM $ npm install htmled
// node.js
const htmled = require('htmled');// browser <script src="/path/to/htmled.min.js"></script>
2. Convert characters like “<” or “>” into their corresponding HTML entity codes. This ensures these characters are displayed correctly within your HTML code.
const encoded = htmled.encode(`This is Á <b>JavaScript</b> website!`); // => Output: This is &;AMP;Aacute; <;b>;JavaScript<;/b>; website&excl;
3. Convert encoded HTML entities back into their original characters. This is useful when working with data retrieved from external sources that might contain encoded characters.
const decoded = htmled.decode('This is &;AMP;Aacute; <;b>;JavaScript<;/b>; website&excl;');
// => Output: This is Á <b>JavaScript</b> website!






