{"_id":"entities@9.0.0","bugs":{"url":"https://github.com/fb55/entities/issues"},"dist":{"shasum":"c45df3cdbc5ce805474759f4ec4ea7907d9d5477","tarball":"http://registry-npm.ywwl.com/entities/download/entities-9.0.0.tgz","fileCount":43,"integrity":"sha512-oJFNDJg3kTPwAD1cNn2+WmUq4wFoo09npc3Ydf1D7ED4smRiWrsKnaLxykrTWgyGEcusc87P5dxlAleol9kpkg==","signatures":[{"sig":"MEYCIQCIWlIrVK04slqCUKBEEohOVVs44N4wQrAcKklqOxBjlAIhAPN0DLNGBmNj4k8KvhvoHuyCw/DSNzwYSQSqcvvOxPLI","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCID8Mleba+PwiVcpkLel+q+QyCqOoxgiLf3vMIIDhg+CfAiEAuCgvg/1s+dzW1vc6sPYoBpmdC3Pk9J/nuAb6gHrsumI="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/entities@9.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":327668,"size":92324,"noattachment":false,"key":"/entities/-/entities-9.0.0.tgz"},"main":"./dist/index.js","name":"entities","type":"module","types":"./dist/index.d.ts","author":{"name":"Felix Boehm","email":"me@feedic.com"},"engines":{"node":">=20.19.0"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./decode":{"types":"./dist/decode.d.ts","default":"./dist/decode.js"},"./escape":{"types":"./dist/escape.d.ts","default":"./dist/escape.js"}},"funding":"https://github.com/fb55/entities?sponsor=1","gitHead":"a007e7256d47924f43389e3eaf66d2825f6773ef","license":"BSD-2-Clause","scripts":{"lint":"npm run lint:es && npm run lint:ts && npm run lint:biome","test":"npm run test:vi && npm run lint","build":"npm run clean && tsc","clean":"node -e \"fs.rmSync('dist', { recursive: true, force: true })\"","format":"npm run format:es && npm run format:biome","lint:es":"eslint .","lint:ts":"tsc --noEmit -p tsconfig.eslint.json","test:vi":"vitest run","benchmark":"npm --prefix scripts/benchmark run benchmark --","format:es":"npm run lint:es -- --fix","build:docs":"typedoc --hideGenerator src/index.ts","lint:biome":"biome check .","format:biome":"biome check --fix .","prebenchmark":"npm ci --prefix scripts/benchmark","prepublishOnly":"npm run build","build:decode-map":"node --import=tsx scripts/write-decode-map.ts","build:encode-trie":"node --import=tsx scripts/write-encode-map.ts"},"version":"9.0.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"9191d3f6-c47f-4f03-a389-9d3e9da1759c"}},"homepage":"https://github.com/fb55/entities#readme","keywords":["html entities","entity decoder","entity encoding","html decoding","html encoding","xml decoding","xml encoding"],"repository":{"url":"git+https://github.com/fb55/entities.git","type":"git"},"_npmVersion":"11.19.1","description":"Encode & decode XML and HTML entities with ease & speed","directories":{},"maintainers":[{"name":"fb55","email":"me@feedic.com"}],"sideEffects":false,"_nodeVersion":"24.22.1","_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.23.15","eslint":"^10.13.0","vitest":"^5.0.5","typedoc":"^0.28.20","typescript":"^6.0.3","@types/node":"^26.6.5","@biomejs/biome":"^2.5.15","@eslint/compat":"^2.1.1","typescript-eslint":"^8.71.2","eslint-config-biome":"^2.1.3","@feedic/eslint-config":"^0.5.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/entities_9.0.0_1793232495343_0.6570347974798213"},"readme":"# entities [![NPM version](https://img.shields.io/npm/v/entities.svg)](https://npmjs.org/package/entities) [![Downloads](https://img.shields.io/npm/dm/entities.svg)](https://npmjs.org/package/entities) [![Node.js CI](https://github.com/fb55/entities/actions/workflows/nodejs-test.yml/badge.svg)](https://github.com/fb55/entities/actions/workflows/nodejs-test.yml)\n\nEncode & decode HTML & XML entities with ease & speed.\n\n## Features\n\n- 😇 Tried and true: `entities` is used by many popular libraries; eg.\n  [`htmlparser2`](https://github.com/fb55/htmlparser2), the official\n  [AWS SDK](https://github.com/aws/aws-sdk-js-v3) and\n  [`commonmark`](https://github.com/commonmark/commonmark.js) use it to process\n  HTML entities.\n- ⚡️ Fast: `entities` is the fastest library for decoding HTML entities (as of\n  September 2025); see [performance](#performance).\n- 🎛 Configurable: Get an output tailored for your needs. You are fine with\n  UTF8? That'll save you some bytes. Prefer to only have ASCII characters? We\n  can do that as well!\n\n## How to…\n\n### …install `entities`\n\n    npm install entities\n\n### …use `entities`\n\n```javascript\nimport * as entities from \"entities\";\n\n// Encoding\nentities.escapeUTF8(\"&#38; ü\"); // \"&amp;#38; ü\"\nentities.encodeXML(\"&#38; ü\"); // \"&amp;#38; &#252;\"\nentities.encodeHTML(\"&#38; ü\"); // \"&amp;&num;38&semi; &uuml;\"\n\n// Decoding\nentities.decodeXML(\"asdf &amp; &#xFF; &#xFC; &apos;\"); // \"asdf & ÿ ü '\"\nentities.decodeHTML(\"asdf &amp; &yuml; &uuml; &apos;\"); // \"asdf & ÿ ü '\"\n```\n\n## Performance\n\nBenchmarked in October 2026 with Node v26.9.0 on AMD Ryzen 7 5800X3D\n(median of three runs). Other libraries are shown relative to `entities`.\n\n### Decoding\n\n| Library              | Short text (49 B) | Plain prose (4.0 KiB) | Prose with references (4.0 KiB) | All named references (19.9 KiB) | Numeric references (4.0 KiB) |\n| -------------------- | ----------------: | --------------------: | ------------------------------: | ------------------------------: | ---------------------------: |\n| entities             |          578 MB/s |          131,381 MB/s |                      1,425 MB/s |                        161 MB/s |                     272 MB/s |\n| html-entities 2.6.0  |       5.5× slower |            61× slower |                     4.8× slower |                     2.7× slower |                  7.1× slower |\n| he 2.0.0             |       7.8× slower |            61× slower |                     7.5× slower |                     5.0× slower |                  8.0× slower |\n| parse-entities 4.0.2 |        14× slower |         1,040× slower |                      30× slower |                      13× slower |                  5.0× slower |\n| ent 2.2.2            |        10× slower |            61× slower |                      10× slower |                     6.9× slower |                   11× slower |\n\n`entities` returns input without `&` after a single `indexOf` scan, hence\nthe plain prose result.\n\n### Encoding\n\n| Library                  | Short text (48 B) | ASCII prose (4.0 KiB) | Accented prose (4.0 KiB) | CJK and emoji (4.0 KiB) |\n| ------------------------ | ----------------: | --------------------: | -----------------------: | ----------------------: |\n| entities                 |          195 MB/s |            1,107 MB/s |                 251 MB/s |                127 MB/s |\n| html-entities 2.6.0      |       3.0× slower |           1.1× slower |              1.6× slower |             2.7× slower |\n| he 2.0.0                 |       9.4× slower |           2.0× slower |              4.3× slower |             4.4× slower |\n| stringify-entities 4.0.4 |       8.0× slower |           1.7× slower |              3.8× slower |             5.6× slower |\n| ent 2.2.2                |        14× slower |            98× slower |               23× slower |             5.3× slower |\n\n### Escaping\n\n| Library                  | Short text (48 B) | Prose (4.0 KiB) | Markup (4.1 KiB) |\n| ------------------------ | ----------------: | --------------: | ---------------: |\n| entities                 |          326 MB/s |      4,447 MB/s |         304 MB/s |\n| html-entities 2.6.0      |       2.3× slower |     1.8× slower |      1.7× slower |\n| he 2.0.0                 |       2.1× slower |     1.7× slower |      1.6× slower |\n| stringify-entities 4.0.4 |       3.6× slower |     2.7× slower |      2.8× slower |\n| html-escaper 3.0.3       |       2.2× slower |     1.7× slower |      1.6× slower |\n| lodash 4.18.1            |       2.4× slower |     1.8× slower |      1.7× slower |\n\n### Unescaping\n\n| Library              | Short text (62 B) | Prose (4.1 KiB) | Markup (5.7 KiB) |\n| -------------------- | ----------------: | --------------: | ---------------: |\n| entities             |          329 MB/s |      4,552 MB/s |         410 MB/s |\n| html-entities 2.6.0  |       3.7× slower |     5.7× slower |      3.7× slower |\n| he 2.0.0             |       5.2× slower |     8.4× slower |      5.8× slower |\n| parse-entities 4.0.2 |       8.0× slower |      75× slower |       13× slower |\n| ent 2.2.2            |       7.8× slower |      11× slower |      8.9× slower |\n| html-escaper 3.0.3   |       2.8× slower |     5.2× slower |      3.0× slower |\n| lodash 4.18.1        |       3.0× slower |     4.8× slower |      3.0× slower |\n\nNote: Micro-benchmarks may vary across machines and Node versions.\n\n---\n\n## FAQ\n\n> What methods should I actually use to encode my documents?\n\nIf your target supports UTF-8, the `escapeUTF8` method is going to be your best\nchoice. Otherwise, use either `encodeHTML` or `encodeXML` based on whether\nyou're dealing with an HTML or an XML document.\n\nYou can have a look at the options for the `encode` and `decode` methods to see\neverything you can configure.\n\n> When should I use strict decoding?\n\nWhen strict decoding, entities not terminated with a semicolon will be ignored.\nThis is helpful for decoding entities in legacy environments.\n\n> Why should I use `entities` instead of alternative modules?\n\nAs of October 2026, `entities` is faster than other modules. Still, this is\nnot a differentiated space and other modules can catch up.\n\n**More importantly**, you might already have `entities` in your dependency graph\n(as a dependency of eg. `cheerio`, or `htmlparser2`), and including it directly\nmight not even increase your bundle size. The same is true for other entity\nlibraries, so have a look through your `node_modules` directory!\n\n> Does `entities` support tree shaking?\n\nYes! Note that for best results, you should not use the `encode` and `decode`\nfunctions, as they wrap around a number of other functions, all of which will\nremain in the bundle. Instead, use the functions that you need directly.\n\n---\n\n## Acknowledgements\n\nThis library wouldn't be possible without the work of these individuals. Thanks\nto\n\n- [@mathiasbynens](https://github.com/mathiasbynens) for his explanations about\n  character encodings, and his library `he`, which was one of the inspirations\n  for `entities`\n- [@inikulin](https://github.com/inikulin) for his work on optimized tries for\n  decoding HTML entities for the `parse5` project\n- [@mdevils](https://github.com/mdevils) for taking on the challenge of\n  producing a quick entity library with his `html-entities` library. `entities`\n  would be quite a bit slower if there wasn't any competition. Right now\n  `entities` is on top, but we'll see how long that lasts!\n\n---\n\nLicense: BSD-2-Clause\n\n## Security contact information\n\nTo report a security vulnerability, please use the\n[Tidelift security contact](https://tidelift.com/security). Tidelift will\ncoordinate the fix and disclosure.\n","publish_time":1793232495446,"_cnpm_publish_time":1793232495446,"dist-tags":{"latest":"9.0.0"}}