@bybrave/he2
v2.0.1
Published
Maintained he fork: robust HTML entity encoder/decoder with full Unicode support, now as ESM + CommonJS with built-in TypeScript types and zero dependencies. Drop-in for he.
Downloads
144
Maintainers
Readme
@bybrave/he2
Maintained fork of he — a robust HTML entity encoder/decoder with full Unicode support.
Same battle-tested, HTML-spec-compliant engine, now shipped as native ESM + CommonJS with built-in TypeScript types, zero dependencies, and the he CLI. Encode/decode output is byte-for-byte identical to [email protected].
Install
npm install @bybrave/he2Usage
import he from '@bybrave/he2';
// or: import { encode, decode, escape, unescape } from '@bybrave/he2';
he.encode('foo © bar ≠ baz 𝌆 qux', { useNamedReferences: true });
// → 'foo © bar ≠ baz 𝌆 qux'
he.decode('foo © bar ≠ baz 𝌆 qux');
// → 'foo © bar ≠ baz 𝌆 qux'
he.escape('<img src="x">');
// → '<img src="x">'CommonJS works too — require returns the same { encode, decode, escape, unescape, version } object as the original:
const he = require('@bybrave/he2');API
encode(text, options?)— options:useNamedReferences,decimal,encodeEverything,strict,allowUnsafeSymbols.decode(html, options?)— options:isAttributeValue,strict.escape(text)— escapes only&<>"'and backtick.unescape(html, options?)— alias ofdecode.version— the underlying he version.
CLI
he --escape '<img src="x">'
echo '© 𝌆' | he --decodeWhat's changed vs [email protected]
| Change | Detail |
|---|---|
| ESM + CommonJS | Ships native ESM with a CommonJS build via the exports map — import and require both work. The original was UMD only. |
| Built-in types | TypeScript types are bundled — no separate @types/he needed. |
| Zero dependencies | Same as the original (no runtime deps), now maintained. |
| Engine unchanged | The HTML-spec engine and generated Unicode tables are ported byte-for-byte; encode/decode/escape output matches [email protected] exactly. |
Migration from he
Drop-in — replace the import:
- const he = require('he');
+ const he = require('@bybrave/he2');All output is identical to [email protected]. Unlike entities or html-entities, this keeps the exact he API (encode/decode/escape/unescape with the same options), so no code changes are needed.
Support
If this package saves you time, you can support maintenance:
Bitcoin (BTC): bc1q37557q5jpeaxqydzwvf3jgj7zhnfpn2td3q40q
License
MIT. Copyright © Mathias Bynens; fork © bybrave.
