{"name":"entities","version":"7.0.0","keywords":["html entities","entity decoder","entity encoding","html decoding","html encoding","xml decoding","xml encoding"],"author":{"name":"Felix Boehm","email":"me@feedic.com"},"license":"BSD-2-Clause","_id":"entities@7.0.0","maintainers":[{"name":"feedic","email":"me@feedic.com"}],"homepage":"https://github.com/fb55/entities#readme","bugs":{"url":"https://github.com/fb55/entities/issues"},"dist":{"shasum":"2ae4e443f3f17d152d3f5b0f79b932c1e59deb7a","tarball":"http://registry-npm.ywwl.com/entities/download/entities-7.0.0.tgz","fileCount":113,"integrity":"sha512-FDWG5cmEYf2Z00IkYRhbFrwIwvdFKH07uV8dvNy0omp/Qb1xcyCWp2UDtcwJF4QZZvk0sLudP6/hAu42TaqVhQ==","signatures":[{"sig":"MEUCIQDwJn8MC3YIfKMouaKfCfBAU2hHtPJQY2d02AWFYIiRZAIgY5Xt94vBFciwkFP3M8Xucq8HrZ42CHufUpvIOlGOTYE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":412734,"size":117237,"noattachment":false,"key":"/entities/-/entities-7.0.0.tgz"},"main":"./dist/commonjs/index.js","tshy":{"exclude":["**/*.spec.ts","**/__fixtures__/*","**/__tests__/*","**/__snapshots__/*"],"exports":{".":"./src/index.ts","./decode":"./src/decode.ts","./escape":"./src/escape.ts"}},"type":"module","types":"./dist/commonjs/index.d.ts","module":"./dist/esm/index.js","engines":{"node":">=0.12"},"exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}},"./decode":{"import":{"types":"./dist/esm/decode.d.ts","default":"./dist/esm/decode.js"},"require":{"types":"./dist/commonjs/decode.d.ts","default":"./dist/commonjs/decode.js"}},"./escape":{"import":{"types":"./dist/esm/escape.d.ts","default":"./dist/esm/escape.js"},"require":{"types":"./dist/commonjs/escape.d.ts","default":"./dist/commonjs/escape.js"}}},"funding":"https://github.com/fb55/entities?sponsor=1","gitHead":"45131adf3da5377520863bf899f0bc0928939f14","scripts":{"lint":"npm run lint:es && npm run lint:ts && npm run lint:biome","test":"npm run test:vi && npm run lint","format":"npm run format:es && npm run format:biome","lint:es":"eslint . --ignore-path .gitignore","lint:ts":"tsc --noEmit","test:vi":"vitest run","format:es":"npm run lint:es -- --fix","build:docs":"typedoc --hideGenerator src/index.ts","build:trie":"node --import=tsx scripts/write-decode-map.ts","lint:biome":"biome check .","format:biome":"biome check --fix .","prepublishOnly":"tshy","build:encode-trie":"node --import=tsx scripts/write-encode-map.ts"},"_npmUser":{"name":"feedic","email":"me@feedic.com"},"repository":{"url":"git+https://github.com/fb55/entities.git","type":"git"},"_npmVersion":"11.5.1","description":"Encode & decode XML and HTML entities with ease & speed","directories":{},"sideEffects":false,"_nodeVersion":"24.6.0","_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.20.5","tshy":"^3.0.2","eslint":"^8.57.1","vitest":"^3.2.4","typedoc":"^0.28.12","typescript":"^5.9.2","@types/node":"^24.3.1","@biomejs/biome":"^2.2.3","eslint-plugin-n":"^17.21.3","@vitest/coverage-v8":"^3.2.4","eslint-config-biome":"^2.1.3","eslint-plugin-unicorn":"^56.0.1","@typescript-eslint/parser":"^8.33.1","@typescript-eslint/eslint-plugin":"^8.42.0"},"_npmOperationalInternal":{"tmp":"tmp/entities_7.0.0_1757197154191_0.7527010909895411","host":"s3://npm-registry-packages-npm-production"},"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; &#xfc;\"\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 September 2025 with Node v24.6.0 on Apple M2 using `tinybench`.\nHigher ops/s is better; `avg (μs)` is the mean time per operation.\nSee `scripts/benchmark.ts` to reproduce.\n\n### Decoding\n\n| Library        | Version | ops/s     | avg (μs) | ±%   | slower |\n| -------------- | ------- | --------- | -------- | ---- | ------ |\n| entities       | 7.0.0   | 5,838,416 | 175.57   | 0.06 | —      |\n| html-entities  | 2.6.0   | 2,919,637 | 347.77   | 0.33 | 50.0%  |\n| he             | 1.2.0   | 2,318,438 | 446.48   | 0.70 | 60.3%  |\n| parse-entities | 4.0.2   |   852,855 | 1,199.51 | 0.36 | 85.4%  |\n\n### Encoding\n\n| Library        | Version | ops/s     | avg (μs) | ±%   | slower |\n| -------------- | ------- | --------- | -------- | ---- | ------ |\n| entities       | 7.0.0   | 2,770,115 | 368.09   | 0.11 | —      |\n| html-entities  | 2.6.0   | 1,491,963 | 679.96   | 0.58 | 46.2%  |\n| he             | 1.2.0   |   481,278 | 2,118.25 | 0.61 | 82.6%  |\n\n### Escaping\n\n| Library        | Version | ops/s     | avg (μs) | ±%   | slower |\n| -------------- | ------- | --------- | -------- | ---- | ------ |\n| entities       | 7.0.0   | 4,616,468 | 223.84   | 0.17 | —      |\n| he             | 1.2.0   | 3,659,301 | 280.76   | 0.58 | 20.7%  |\n| html-entities  | 2.6.0   | 3,555,301 | 296.63   | 0.84 | 23.0%  |\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 September 2025, `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":1757197154428,"_cnpm_publish_time":1757197154428,"dist-tags":{"latest":"9.0.0"}}