{"name":"@nodable/entities","version":"3.0.0","description":"Entity parser for XML, HTML, External entites with security and NCR control","main":"./src/index.js","type":"module","sideEffects":false,"types":"./src/index.d.ts","scripts":{"test":"node --experimental-vm-modules node_modules/.bin/jest","test:watch":"node --experimental-vm-modules node_modules/.bin/jest --watch","test:coverage":"node --experimental-vm-modules node_modules/.bin/jest --coverage","lint":"eslint src/ test/"},"repository":{"type":"git","url":"git+https://github.com/nodable/val-parsers.git"},"keywords":["fast","xml","html","entity","entities","stringify","encode","decode","ncr","security","safe","performance"],"author":{"name":"Amit Gupta","url":"https://solothought.com"},"license":"MIT","publishConfig":{"access":"public"},"devDependencies":{"jest":"^29.7.0"},"funding":[{"type":"github","url":"https://github.com/sponsors/nodable"}],"jest":{"testMatch":["**/?(*.)+(spec|test).[jt]s?(x)","**/*_spec.[jt]s?(x)"]},"gitHead":"d2070d76a8ba07e6c7fa142caeb51ffd756e47eb","_id":"@nodable/entities@3.0.0","bugs":{"url":"https://github.com/nodable/val-parsers/issues"},"homepage":"https://github.com/nodable/val-parsers#readme","_nodeVersion":"22.14.0","_npmVersion":"11.18.0","dist":{"integrity":"sha512-8L9xFeTYKhm49xfIypoe2W5wV1m/3Z58kT+7kR9A8OyFxcPduI4VmxaUMQyKYrRjUoLLSXv6EKKID5Tvj9cUVw==","shasum":"694703bc864d30eaed55c2e3def00dbd61493670","tarball":"http://registry-npm.ywwl.com/@nodable/entities/download/@nodable/entities-3.0.0.tgz","fileCount":9,"unpackedSize":74395,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQC//0PLaqJnzHb44FbZe8i7Jf+/p3Ek3rYCRHpFk7t/HwIhANM70mp8rfbgp7ZK90fHGW2fgNHyDY1Bf4+9cdw5GqPy"}],"size":22312,"noattachment":false,"key":"/@nodable/entities/-/@nodable/entities-3.0.0.tgz"},"_npmUser":{"name":"amitgupta","email":"amitgupta.gwl@gmail.com"},"directories":{},"maintainers":[{"name":"amitgupta","email":"amitgupta.gwl@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/entities_3.0.0_1783995729462_0.662104866172041"},"_hasShrinkwrap":false,"readme":"# @nodable/entities\n\nFast, zero-dependency XML/HTML entity encoder and decoder for Node.js.\n\n## Install\n\n```bash\nnpm install @nodable/entities\n```\n\n## Quick start\n\n```js\nimport { EntityEncoder, EntityDecoder, ALL_ENTITIES } from '@nodable/entities';\n\n// Encode: plain text → entity references\n// v3 requires an explicit entity set when encoding named (non‑ASCII) characters\nconst enc = new EntityEncoder({ namedEntities: ALL_ENTITIES });\nenc.encode('Hello © 2024 & <stuff>');\n// → 'Hello &copy; 2024 &amp; &lt;stuff&gt;'\n\n// Decode: entity references → plain text\nconst dec = new EntityDecoder({ namedEntities: ALL_ENTITIES });\ndec.decode('Hello &copy; 2024 &amp; &lt;stuff&gt;');\n// → 'Hello © 2024 & <stuff>'\n```\n\nIf you only need to encode XML‑unsafe characters (`&`, `<`, `>`, `\"`, `'`), you can disable named‑entity encoding entirely and avoid importing any entity set:\n\n```js\nconst enc = new EntityEncoder({ encodeAllNamed: false });\nenc.encode('© <stuff>'); // → '© &lt;stuff&gt;'  (copyright stays literal)\n```\n\nTo encode only a specific subset of characters (e.g. common HTML entities), pass a custom map:\n\n```js\nimport { EntityEncoder, COMMON_HTML, CURRENCY } from '@nodable/entities';\n\nconst enc = new EntityEncoder({ namedEntities: { ...COMMON_HTML, ...CURRENCY } });\nenc.encode('Price: 10 © 2024'); // only COMMON_HTML/CURRENCY entities are recognized\n```\n\n---\n\n## Migration from v2 to v3\n\n**Breaking change:**  \nIn v2, `new EntityEncoder()` automatically used the full built‑in entity set to encode non‑ASCII characters (like `©` → `&copy;`). This caused poor tree‑shaking: every consumer paid the cost of the entire entity table, even if they never used it.\n\nIn v3, **`EntityEncoder` no longer includes a default entity set**.  \nIf you pass no options and `encodeAllNamed` is `true` (the default), the constructor will **throw an error**:\n\n```js\nconst enc = new EntityEncoder(); // throws: \"encodeAllNamed is true but no `namedEntities` was provided\"\n```\n\n### How to update\n\n| What you need | v2 code | v3 code |\n|---------------|---------|---------|\n| **Full built‑in set** (same as v2) | `new EntityEncoder()` | `import { ALL_ENTITIES } from '@nodable/entities';`<br>`new EntityEncoder({ namedEntities: ALL_ENTITIES })` |\n| **Only XML‑unsafe chars** (no named entities) | `new EntityEncoder({ encodeAllNamed: false })` | **Same** – no change |\n| **Custom subset** | `new EntityEncoder({ namedEntities: myMap })` | **Same** – but now your map is required for named‑entity encoding |\n\nThis change allows bundlers to tree‑shake unused entity categories – you only pay for the characters you actually encode.\n\n### Upgrading step‑by‑step\n\n1. Update to `@nodable/entities@3.0.0`.\n2. Find all `new EntityEncoder()` calls in your project.\n3. Decide:\n   - If you need the full set: import `ALL_ENTITIES` and pass it as `namedEntities`.\n   - If you only need XML‑unsafe escaping: add `{ encodeAllNamed: false }`.\n   - If you used a custom set: keep it as‑is – it already worked.\n4. Run your tests – the encoder should now behave as before, but with better bundle size.\n\n## Performance\n\n|  | encode | decode |\n|---|---|---|\n| `entities` (npm) | 3.65 M req/s | 1.76 M req/s |\n| `@nodable/entities` | 3.33 M req/s | **5.19 M req/s** |\n\n## Documentation\n\n- [EntityEncoder](docs/EntityEncoder.md) — options, API, recipes\n- [EntityDecoder](docs/EntityDecoder.md) — options, API, security limits, entity sets\n\n## License\n\nMIT","publish_time":1783995729627,"_cnpm_publish_time":1783995729627,"dist-tags":{"latest":"3.1.0"}}