Skip to content
Encode and decode HTML entities
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
build Just call the method escape (apparently it's not utf8) Jun 24, 2013
examples and an example even Feb 16, 2011
test encode: allow for a custom `special` object Jan 16, 2015
.npmignore Add all the missing entities [closes #8] Jun 24, 2013
.travis.yml updated readme, using travis Dec 12, 2012
LICENSE re-licensing to MIT as per Feist v Rural (https://en.wikipedia.org/wi… Jul 17, 2013
decode.js
encode.js encode: allow for a custom `special` object Jan 16, 2015
entities.json Only include named entities with semicolons in reverse Jun 24, 2013
index.js separate out into `encoder.js` and `decoder.js` files Jan 14, 2015
package.json 2.2.0 Jan 16, 2015
readme.markdown Give credits to whatwg, instead of HTML::Entities Feb 11, 2015
reversed.json Only include named entities with semicolons in reverse Jun 24, 2013

readme.markdown

ent

Encode and decode HTML entities

browser support

build status

example

var ent = require('ent');
console.log(ent.encode('<span>©moo</span>'))
console.log(ent.decode('&pi; &amp; &rho;'));
&#60;span&#62;&#169;moo&#60;/span&#62;
π & ρ

ent

methods

var ent = require('ent');
var encode = require('ent/encode');
var decode = require('ent/decode');

encode(str, opts={})

Escape unsafe characters in str with html entities.

By default, entities are encoded with numeric decimal codes.

If opts.numeric is false or opts.named is true, encoding will used named codes like &pi;.

If opts.special is set to an Object, the key names will be forced to be encoded (defaults to forcing: <>'"&). For example:

console.log(encode('hello', { special: { l: true } }));
he&#108;&#108;o

decode(str)

Convert html entities in str back to raw text.

credits

HTML entity tables are from the official entities.json file for the whatwg HTML specification.

install

With npm do:

npm install ent

license

MIT

You can’t perform that action at this time.