{"name":"@nodable/entities","version":"1.0.0","keywords":["fast","xml","html","entity"],"author":{"url":"https://solothought.com","name":"Amit Gupta"},"license":"MIT","_id":"@nodable/entities@1.0.0","maintainers":[{"name":"amitgupta","email":"amitgupta.gwl@gmail.com"}],"homepage":"https://github.com/nodable/val-parsers#readme","bugs":{"url":"https://github.com/nodable/val-parsers/issues"},"dist":{"shasum":"289270d478e779f8abcfc2d79172d94190a63e83","tarball":"http://registry-npm.ywwl.com/@nodable/entities/download/@nodable/entities-1.0.0.tgz","fileCount":7,"integrity":"sha512-JoyscCJg4De1NJAZhJHxcYjN8snyl2kHcjYYmeLZ9xfGoPVE6Fiz/q3mMbxLOKRuWgshTYFSH118mQe8AmHmyA==","signatures":[{"sig":"MEUCIA6FTUigYBsTbkqd8pVGUPqE8bHIaBoy8veGUAkGBEYOAiEAiqWEsY2WN6uZCEBd6SmpWX1HhrH0UILGRILRuH8Q0DI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":55841,"size":13713,"noattachment":false,"key":"/@nodable/entities/-/@nodable/entities-1.0.0.tgz"},"jest":{"testMatch":["**/?(*.)+(spec|test).[jt]s?(x)","**/*_spec.[jt]s?(x)"]},"main":"./src/index.js","type":"module","types":"./src/index.d.ts","funding":[{"url":"https://github.com/sponsors/nodable","type":"github"}],"gitHead":"c8e2a5d5bdf010e38eb8bee200f81b7a4dc43488","scripts":{"lint":"eslint src/ test/","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"},"_npmUser":{"name":"amitgupta","email":"amitgupta.gwl@gmail.com"},"repository":{"url":"git+https://github.com/nodable/val-parsers.git","type":"git"},"_npmVersion":"11.11.0","description":"Replace XML, HTML, External entites with security controls","directories":{},"sideEffects":false,"_nodeVersion":"22.14.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0"},"_npmOperationalInternal":{"tmp":"tmp/entities_1.0.0_1776135392824_0.850104485117515","host":"s3://npm-registry-packages-npm-production"},"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":1776135392987,"_cnpm_publish_time":1776135392987,"dist-tags":{"latest":"3.1.0"}}