ent
Encode and decode HTML entities
Last updated 2 years ago by ljharb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install ent 
SYNC missed versions from official npm registry.

ent Version Badge

github actions coverage License Downloads

npm badge

Encode and decode HTML entities

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

Current Tags

  • 2.2.2                                ...           latest (2 years ago)
  • 0.0.8                                ...           v0-backport (2 years ago)

16 Versions

  • 2.2.2                                ...           2 years ago
  • 0.0.8                                ...           2 years ago
  • 2.2.1                                ...           2 years ago
  • 2.2.0                                ...           12 years ago
  • 2.1.1                                ...           12 years ago
  • 2.1.0                                ...           12 years ago
  • 2.0.0                                ...           13 years ago
  • 1.0.0                                ...           13 years ago
  • 0.1.0                                ...           13 years ago
  • 0.0.7                                ...           13 years ago
  • 0.0.6                                ...           13 years ago
  • 0.0.5                                ...           14 years ago
  • 0.0.4                                ...           15 years ago
  • 0.0.3                                ...           15 years ago
  • 0.0.2                                ...           16 years ago
  • 0.0.1                                ...           16 years ago
Maintainers (2)
Downloads
Total 46
Today 16
This Week 20
This Month 40
Last Day 0
Last Week 0
Last Month 1
Dependencies (4)
Dev Dependencies (10)

© 2010 - cnpmjs.org x YWFE | Home | YWFE