Package detail

ent

ljharb22.3mMIT2.2.2

Encode and decode HTML entities

entities, entitify, entity, html

readme

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

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v2.2.2 - 2024-12-16

Commits

  • Only apps should have lockfiles 47ef756
  • [Dev Deps] add eslint, safe-publish-latest, evalmd 57ae197
  • [Tests] migrate from travis to GHA 7ff7938
  • [meta] use auto-changelog 9881b78
  • [Robustness] use call-bound, es-errors, safe-regex-test 481fb1a
  • [meta] make LICENSE text match what some things expect for MIT e55a84c
  • [actions] split out node 10-20, and 20+ 353c9bb
  • [Refactor] avoid recreating default specials object; cache punycode methods b34a99f
  • [Dev Deps] update tape 89a220a
  • [readme] fix badges aabaa1f
  • [meta] update URLs 770d069
  • [Fix] use punycode package instead of the deprecated node core module 68a5239
  • [meta] use npmignore 444eb43
  • [Dev Deps] update auto-changelog, tape 2eea295
  • [Tests] replace aud with npm audit 9d1775b
  • [Tests] add coverage f2570f0
  • [meta] add missing engines.node 54881fb
  • [readme] use conventional filename 3a6fce4
  • [meta] add sideEffects flag 0f15cde
  • [Dev Deps] add missing peer dep 1d51d22
  • Merge tag 'v0.0.8' a57fc5d

v2.2.1 - 2024-06-20

Fixed

  • Give credits to whatwg, instead of HTML::Entities #23

Commits

  • [Dev Deps] add eslint, safe-publish-latest, evalmd a54380e
  • Only apps should have lockfiles 5369429
  • [Tests] migrate from travis to GHA 0ce07a1
  • [Dev Deps] update tape da07969
  • [meta] use npmignore 153e114
  • [meta] update URLs 758c132
  • [meta] use auto-changelog c1b7129
  • [Fix] use punycode package instead of the deprecated node core module 67568c3
  • [meta] add missing engines.node 0f25e78
  • [Dev Deps] update tape 2d900f7

v2.2.0 - 2015-01-16

Commits

  • encode: allow for a custom special object 3785147
  • readme: document encode special option 901057f

v2.1.1 - 2015-01-14

Fixed

  • test: more named entity and ambiguous ampersands tests #11

Commits

  • decode: use correct & symbol and return match without semicolon when appropriate fc894e4

v2.1.0 - 2015-01-14

Fixed

  • decode: avoid multiple decoding passes #13
  • encode: use punycode to iterate over code points #17

Commits

  • separate out into encoder.js and decoder.js files 945479a
  • decode: tweak spacing a71309e
  • index: remove trailing whitespace 3247899
  • test: add encode() equals tests for "nested escapes" 373d1dd
  • document /encode, /decode de61f6e
  • test: add encode() equals tests for "astral num" db534b7
  • encode: remove dead code 73bae6e
  • encode: use test() instead of match() 24447ff
  • decode: fix case where named entity is not defined d008a48
  • decode: fix breaking regexp typo 934fdb4

v2.0.0 - 2014-04-10

Commits

v1.0.0 - 2014-04-09

Commits

v0.1.0 - 2013-07-29

Fixed

  • Add all the missing entities [closes #8] #8

Commits

  • Only include named entities with semicolons in reverse 3d1ad32
  • Add test for a more obscure entity [see #8] e7dc91b
  • Just call the method escape (apparently it's not utf8) 91c3587

v0.0.8 - 2024-06-21

Commits

  • Only apps should have lockfiles 47ef756
  • [Dev Deps] add eslint, safe-publish-latest, evalmd 57ae197
  • [Tests] migrate from travis to GHA 7ff7938
  • [meta] use auto-changelog 9881b78
  • [Dev Deps] update tape 89a220a
  • [meta] update URLs 770d069
  • [Fix] use punycode package instead of the deprecated node core module 68a5239
  • [meta] use npmignore 444eb43
  • [meta] add missing engines.node 54881fb

v0.0.7 - 2013-07-29

Fixed

  • Fix astral symbols [closes #7] #7

Commits

  • Add test for astral symbols [see #7] 4e59dc3

v0.0.6 - 2013-07-17

Commits