Encode and decode HTML entities for special characters, named, and numeric.
import { htmlEntity } from 'toolmetry';| Function | Parameters | Returns | Description |
|---|---|---|---|
htmlEntity.encode | input: string | string | Encode HTML special characters |
htmlEntity.decode | input: string | string | Decode HTML entities to characters |
htmlEntity.encodeAll | input: string | string | Encode all non-ASCII as numeric entities |
htmlEntity.encodeChars | input: string, chars: string[] | string | Encode only specific characters |
import { htmlEntity } from 'toolmetry';
const encoded = htmlEntity.encode('<div class="test">Hello & World</div>');
// "<div class="test">Hello & World</div>"
const decoded = htmlEntity.decode(encoded);
// "<div class="test">Hello & World</div>"import { htmlEntity } from 'toolmetry';
const result = htmlEntity.encodeAll('Cafe\u0301');
// "Café"import { htmlEntity } from 'toolmetry';
const result = htmlEntity.encodeChars('Hello & "World"', ['&', '"']);
// 'Hello & "World"'