Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add entities-encode map #771

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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