var decode = require('{%= name %}');
console.log(decode('<div>abc</div>'));
//=> '<div>abc</div>'
// get the default entities directly
console.log(decode.chars);
For performance, this library only handles the following common entities (split into groups for backward compatibility).
Only the following entities are converted by default.
Character | Description | Entity Name | Entity Number |
---|---|---|---|
< |
less than | < |
< |
> |
greater than | > |
> |
& |
ampersand | & |
& |
" |
double quotation mark | " |
" |
' |
single quotation mark (apostrophe) | ' |
' |
Get the default entities as an object:
console.log(decode.chars);
Only the following entities are converted when 'extras'
is passed as the second argument.
| Character | Description | Entity Name | Entity Number |
| ¢
| cent | ¢
| ¢
|
| £
| pound | £
| £
|
| ¥
| yen | ¥
| ¥
|
| €
| euro | €
| €
|
| ©
| copyright | ©
| ©
|
| ®
| registered trademark | ®
| ®
|
Example:
// convert only the "extras" characters
decode(str, 'extras');
// get the object of `extras` characters
console.log(decode.extras);
Convert both the defaults and extras:
decode(str, 'all');
Get all entities as an object:
console.log(decode.all);
If you need a more robust implementation, try one of the following libraries:
- [html-entities][]
- [ent][]