encode & decode HTML & XML entities with ease & speed
entities
now features an EntityDecoder
class that can be used to decode entities across multiple chunks. This is needed to parse streams, and will be the foundation for entity decoding in htmlparser2
and parse5
.
For users of this library, the most welcome addition will be a new attribute decoding mode, which will ignore some entities that were previously parsed (eg. `foo=bar&=boo' will be left unchanged).
entities
' decode
functions all use the new decoder under the hood. There is a new decodeHTMLAttribute
function for attribute parsing, and some rare edge-cases where entities diverged from the HTML spec have been eliminated.
EntityDecoder
class by @fb55 in https://github.com/fb55/entities/pull/1136
Full Changelog: https://github.com/fb55/entities/compare/v4.4.0...v4.5.0
Please note that some JavaScript minifiers, such as terser, will now produce non-ASCII output. If you use entities in the browser, please make sure you are set up to ship UTF-8 to clients, or set eg. terser's ascii_only
option to false
.
Full Changelog: https://github.com/fb55/entities/compare/v4.3.1...v4.4.0
escape
file, which is available as an export https://github.com/fb55/entities/pull/786
sourceRoot
property in source maps https://github.com/fb55/entities/pull/788
Full Changelog: https://github.com/fb55/entities/compare/v4.2.0...v4.3.0
Fixes:
encode
413c48bFeatures:
replaceCodePoint
from entities/lib/decode
2247ebeOther:
strict-boolean-expressions
(#779) ce2b30bisHighSurrogate
check 03a8f4aits/*
instead of Node 10 1a69212.eslintrc.json
bf89c65New Features:
entities
is now both an ESM and a CommonJS module (#775)entities
now has a new documentation website! (Added in 720a36d.)escapeAttribute
and escapeText
functions, implementing the escaping required by the HTML serializer algorithm (#770)Breaking:
Docs:
Refactors:
[email protected]
features more configurable encode
and decode
functions and rewritten decode & encode functions, resulting in a huge speedup.
encode
, decode
functions 817ae67You can now pass an object with additional configuration options to the exported encode
and decode
function. You can still use the relevant function directly, but this will make it easier to figure out what you want to do in the first place!
entities
is now using tries for encoding and decoding entities. Especially when decoding, this leads to considerable performance improvements. The simple benchmark in scripts/benchmark.ts
is useful for comparing the performance of these two versions:
Version | decode perf |
encode perf |
escape perf |
---|---|---|---|
3.0.0 | 1.418s | 6.786s | 2.196s |
2.2.0 | 4.085s | 14.842s | 5.166s |
Speedup | 2.9x | 2.1x | 2.4x |
entities
was the fastest library in the space for a while. The friendly competition was a great reason to come up with smarter algorithms to push the envelope just a bit further. Now entities
is on top again, but we'll see how long that lasts!