Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smikhalevski/speedy-entities
๐๐จโThe fastest XML/HTML entity encoder/decoder in 20 kB gzipped.
https://github.com/smikhalevski/speedy-entities
decoder entities html-entities
Last synced: 4 days ago
JSON representation
๐๐จโThe fastest XML/HTML entity encoder/decoder in 20 kB gzipped.
- Host: GitHub
- URL: https://github.com/smikhalevski/speedy-entities
- Owner: smikhalevski
- License: mit
- Created: 2021-07-21T11:23:35.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-09-04T18:17:46.000Z (about 1 year ago)
- Last Synced: 2024-10-13T22:48:53.992Z (about 1 month ago)
- Topics: decoder, entities, html-entities
- Language: TypeScript
- Homepage: https://smikhalevski.github.io/speedy-entities/
- Size: 478 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# speedy-entitiesโ๐๐จโ[![build](https://github.com/smikhalevski/speedy-entities/actions/workflows/master.yml/badge.svg?branch=master&event=push)](https://github.com/smikhalevski/speedy-entities/actions/workflows/master.yml)
[The fastest](#performance) XML/HTML entity encoder/decoder in
[20 kB gzipped](https://bundlephobia.com/package/speedy-entities).```shell
npm install --save-prod speedy-entities
```# Decode
There are two preconfigured decoders: `decodeXML` and `decodeHTML`.
```ts
import { decodeXML, decodeHTML } from 'speedy-entities';decodeXML('ab<');
// โฎ 'ab<'decodeHTML('<fooÆ');
// โฎ '();// Register named entities
trieSet('foo;', 'okay');
trieSet('qux;', 'yeah');// Encode a trie
const entitiesTrie = arrayTrieEncode(trie);// Create a decoder
const decode = createEntityDecoder({
entitiesTrie,
numericReferenceSemicolonRequired: true,
});// Decode entities
decode('&foo;');
// โฎ 'okay'decode('&foo');
// โฎ '&foo'// Decode numeric character references
decode('abc');
// โฎ 'abc'
```# Encode
`encodeXML` encodes non-ASCII characters as named XML entities or as numeric references.
`escapeXML` escapes only `"&'<>` characters.
```ts
import { encodeXML, escapeXML } from 'speedy-entities';encodeXML('&๐โค๏ธ');
// โฎ '&๐โค๏ธ'escapeXML('&๐โค๏ธ');
// โฎ '&๐โค'
```# Performance
Clone this repo and use `npm ci && npm run perf` to run the performance testsuite.
Results are in millions of operations per second. The higher number is better.
### Decode
![Decode HTML performance chart](./images/perf-decode-html.svg)
### Encode
![Encode XML performance chart](./images/perf-encode-xml.svg)