deno_html_entities
Fast html entities decode & encode library for Deno.
This library is mdevils/node-html-entities with ES Modules syntax.
Usage
Supports 4 methods for each module (Html5Entities, XmlEntities, Html4Entities):
- encode — encodes, replacing characters to its entity representations. Ignores UTF characters with no entity representation.
- encodeNonUTF — encodes, replacing characters to its entity representations. Inserts numeric entities for UTF characters.
- encodeNonASCII — encodes, replacing only non-ASCII characters to its numeric entity representations.
- decode — decodes, replacing entities to characters. Unknown entities are left as is.
All HTML entities encoding/decoding
import { Html5Entities } from "https://deno.land/x/html_entities/mod.ts";
Html5Entities.encode('<>"&©®∆'); // <>"&©®∆
Html5Entities.encodeNonUTF('<>"&©®∆'); // <>"&©®∆
Html5Entities.encodeNonASCII('<>"&©®∆'); // <>"&©®∆
Html5Entities.decode('<>"&©®'); // <>"&©®
XML entities
HTML validity and XSS attack prevention you can achieve from XmlEntities module.
import { XmlEntities } from "https://deno.land/x/html_entities/mod.ts";
XmlEntities.encode('<>"\'&©®'); // <>"'&©®
XmlEntities.encodeNonUTF('<>"\'&©®'); // <>"'&©®
XmlEntities.encodeNonASCII('<>"\'&©®'); // <>"\'&©®
XmlEntities.decode('<>"'&©®∆'); // <>"'&©®∆
Tests
$ deno test mod_test.js
License
MIT