Skip to content

Commit

Permalink
feat: Add entities-encode map (#771)
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 authored Mar 31, 2022
1 parent 3720a28 commit 4fe3a15
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"build": "tsc && cp -r src/maps lib",
"build:docs": "typedoc --hideGenerator src/index.ts",
"build:trie": "ts-node scripts/write-decode-map.ts",
"build:encode-map": "jq -c 'to_entries | reverse | map( {(.value) : .key } ) | sort | add' maps/entities.json > src/maps/entities-encode.json",
"prepare": "npm run build"
},
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions src/encode-trie.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import htmlMap from "./maps/entities.json";
import htmlMap from "./maps/entities-encode.json";

const enum Surrogate {
Mask = 0b1111_1100_0000_0000,
Expand Down Expand Up @@ -69,8 +69,8 @@ export interface TrieNode {
export function getTrie(map: Record<string, string>): Map<number, TrieNode> {
const trie = new Map<number, TrieNode>();

for (const entity of Object.keys(map)) {
const decoded = map[entity];
for (const decoded of Object.keys(map)) {
const entity = map[decoded];
// Resolve the key
let lastMap = trie;
for (let i = 0; i < decoded.length - 1; i++) {
Expand Down
Loading

0 comments on commit 4fe3a15

Please sign in to comment.