An open API service indexing awesome lists of open source software.

https://github.com/matschik/deno_html_entities

Fast html entities decode & encode library for Deno.
https://github.com/matschik/deno_html_entities

deno encoder-decoder html

Last synced: 6 months ago
JSON representation

Fast html entities decode & encode library for Deno.

Awesome Lists containing this project

README

          

# deno_html_entities

> Fast html entities decode & encode library for Deno.

This library is [mdevils/node-html-entities](https://github.com/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**

```javascript
import { Html5Entities } from "https://deno.land/x/html_entities@v1.0/mod.js";

Html5Entities.encode('<>"&©®∆'); // <>"&©®∆
Html5Entities.encodeNonUTF('<>"&©®∆'); // <>"&©®∆
Html5Entities.encodeNonASCII('<>"&©®∆'); // <>"&©®∆
Html5Entities.decode('<>"&©®'); // <>"&©®
```

**XML entities**

HTML validity and XSS attack prevention you can achieve from XmlEntities module.

```js
import { XmlEntities } from "https://deno.land/x/html_entities@v1.0/mod.js";

XmlEntities.encode('<>"\'&©®'); // <>"'&©®
XmlEntities.encodeNonUTF('<>"\'&©®'); // <>"'&©®
XmlEntities.encodeNonASCII('<>"\'&©®'); // <>"\'&©®
XmlEntities.decode('<>"'&©®∆'); // <>"'&©®∆
```

## Tests
```sh
$ deno test mod_test.js
```

## License

MIT