@ivangsm0/hehe
v2.0.1
Published
An ultra-lite, 100% WHATWG-compliant HTML entity encoder/decoder. Optimized for size and performance.
Maintainers
Readme
@ivangsm0/hehe 🚀
An ultra-lite, 100% WHATWG-compliant HTML entity encoder/decoder. Rewritten in TypeScript. Optimized for maximum performance and minimal footprint.
Formerly known as he, @ivangsm0/hehe has been completely modernized and ultra-optimized to break size and performance barriers while maintaining perfect compliance with the HTML specification.
✨ Key Improvements over he
| Metric | he v1.2.0 | @ivangsm0/hehe | Improvement |
|:---|:---:|:---:|:---:|
| Minified Bundle (ESM) | ~55 KB* | 36.48 KB | ~35% smaller |
| Unpacked Package Size | 124.1 KB | 84.7 KB | 32% smaller |
| Download Size (Packed) | 40.3 KB | 31.3 KB | 22% smaller |
| Execution Performance | 225.8 ms | 65.9 ms | 3.4x faster |
| Language | JavaScript (ES5) | TypeScript | Type-safe |
*Estimated minified size based on original source.
🛠 Installation
# Using Bun (Recommended)
bun add @ivangsm0/hehe
# Using NPM
npm install @ivangsm0/hehe📖 Usage
Encoding
import hehe from '@ivangsm0/hehe';
// Basic encoding
hehe.encode('foo © bar');
// → 'foo © bar'
// Use named references
hehe.encode('foo © bar', { useNamedReferences: true });
// → 'foo © bar'
// Encode everything
hehe.encode('a', { encodeEverything: true });
// → 'a'Decoding
import { decode } from '@ivangsm0/hehe';
// Standard decoding
decode('foo © bar');
// → 'foo © bar'
// Strict mode
decode('&#xZ', { strict: true });
// → Parse error!Escaping (Security first)
import { escape } from '@ivangsm0/hehe';
escape('<img src="x" onerror="prompt(1)">');
// → '<img src="x" onerror="prompt(`1`)">'🚀 Why hehe?
@ivangsm0/hehe uses advanced computer science techniques to provide the smallest possible bundle without sacrificing compliance:
- Trie-based Regex Compression: We compress 2,000+ entity patterns into a prefix-tree (Trie) to generate a high-efficiency matching regex.
- Packed Strings: We store entity data in high-density strings with non-printable delimiters, eliminating JSON overhead.
- Dynamic Map Generation: We generate lookup maps at runtime during module initialization, keeping the wire size tiny.
⚖️ License
MIT License. Developed by Iván Salazar ([email protected]).
Inspired by the original he by Mathias Bynens.
