{"_id":"html-encoding-sniffer@7.0.0","bugs":{"url":"https://github.com/jsdom/html-encoding-sniffer/issues"},"dist":{"shasum":"cf995009e50fa6f90d74906ab5137f8ee9b7c9d8","tarball":"http://registry-npm.ywwl.com/html-encoding-sniffer/download/html-encoding-sniffer-7.0.0.tgz","fileCount":4,"integrity":"sha512-UikN5yr7xsCDAq87Or5or0PAlD3HJJOKVzM05az588WnpDJ4Ux7a2A53Qi6gofGg2/EtvF/H4hCi/TXfCW4Y6w==","signatures":[{"sig":"MEUCIH/9MCechqUHDY4Cl35UwF+ALx5rVQpot+j+LnL1eHW3AiEA/ewZ+V7liK/SBCxmOKik/nmUFH7spaHVeEs2AYqDPYg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIGF1fwX/hOs5zIyuyUW0G4URHo/7whNBCBF42mRZHRFsAiBBt3pn9kHRWe6Jk1VYKXl/scxhOkuD96anvKp2sKnKIQ=="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/html-encoding-sniffer@7.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":16940,"size":5202,"noattachment":false,"key":"/html-encoding-sniffer/-/html-encoding-sniffer-7.0.0.tgz"},"main":"lib/html-encoding-sniffer.js","name":"html-encoding-sniffer","author":{"url":"https://domenic.me/","name":"Domenic Denicola","email":"d@domenic.me"},"engines":{"node":"^22.13.0 || >=24.0.0"},"gitHead":"b3e1a74ac48df34369a93ad87507147e9531d1d0","license":"MIT","scripts":{"lint":"eslint","test":"node --test"},"version":"7.0.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:3e41e1dd-6fba-4b18-a39b-23d35ea8520a"}},"homepage":"https://github.com/jsdom/html-encoding-sniffer#readme","keywords":["encoding","html","xml"],"repository":{"url":"git+https://github.com/jsdom/html-encoding-sniffer.git","type":"git"},"_npmVersion":"11.19.0","description":"Sniff the encoding of an HTML or XML byte stream","directories":{},"maintainers":[{"name":"timothygu","email":"timothygu99@gmail.com"},{"name":"domenic","email":"d@domenic.me"},{"name":"sebmaster","email":"sebmaster16@gmail.com"},{"name":"zirro","email":"code@zirro.se"},{"name":"tmpvar","email":"tmpvar@gmail.com"},{"name":"joris-van-der-wel","email":"joris@jorisvanderwel.com"}],"_nodeVersion":"24.20.0","dependencies":{"@exodus/bytes":"^1.15.1"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"^10.11.0","globals":"^17.12.0","@domenic/eslint-config":"^5.1.0","@stylistic/eslint-plugin":"^5.10.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/html-encoding-sniffer_7.0.0_1789974287175_0.05909577454179704"},"readme":"# Determine the Encoding of an HTML or XML Byte Stream\n\nThis package determines the character encoding of an HTML or XML byte stream. It follows the HTML Standard's [encoding sniffing algorithm](https://html.spec.whatwg.org/multipage/parsing.html#encoding-sniffing-algorithm) for HTML, and WebKit's encoding sniffing behavior for XML.\n\n```js\nconst htmlEncodingSniffer = require(\"html-encoding-sniffer\");\nconst fs = require(\"node:fs\");\n\nconst bytes = fs.readFileSync(\"./page.html\");\nconst sniffedEncoding = htmlEncodingSniffer(bytes);\n```\n\nFor XML, pass `{ xml: true }`:\n\n```js\nconst bytes = fs.readFileSync(\"./document.xml\");\nconst sniffedEncoding = htmlEncodingSniffer(bytes, { xml: true });\n```\n\nThe passed bytes are given as a `Uint8Array`; the Node.js `Buffer` subclass of `Uint8Array` will also work, as shown above.\n\nThe returned value will be a canonical [encoding name](https://encoding.spec.whatwg.org/#names-and-labels) (not a label). You might then combine this with the [`@exodus/bytes`](https://github.com/ExodusOSS/bytes/) package to decode the result:\n\n```js\nconst { TextDecoder } = require(\"@exodus/bytes/encoding.js\");\nconst decodedString = (new TextDecoder(sniffedEncoding)).decode(bytes);\n```\n\n## Options\n\nYou can pass the following options to `htmlEncodingSniffer`:\n\n```js\nconst sniffedEncoding = htmlEncodingSniffer(bytes, {\n  xml,\n  transportLayerEncodingLabel,\n  defaultEncoding,\n  maxPrescanBytes\n});\n```\n\nThe `xml` option is a boolean, defaulting to `false`. It selects XML sniffing when `true` and HTML sniffing when `false`. XML sniffing ignores HTML `<meta>` declarations and leaves well-formedness validation to the caller's XML parser.\n\nThe `transportLayerEncodingLabel` is an encoding label that is obtained from the \"transport layer\" (probably a HTTP `Content-Type` header), which overrides everything but a BOM.\n\nThe `defaultEncoding` is the ultimate fallback encoding used if no valid encoding is supplied by the transport layer, and no encoding is sniffed from the bytes. For HTML, it defaults to `\"windows-1252\"`, as recommended by the algorithm's table of suggested defaults for \"All other locales\" (including the `en` locale). For XML, it defaults to `\"UTF-8\"`.\n\nThe `maxPrescanBytes` option sets how many bytes to scan for HTML `<meta>` encoding declarations, defaulting to `1024`. Set a larger value to recognize declarations later in the input, `Infinity` to scan the entire input, or `0` to skip meta scanning. It must be a non-negative integer or `Infinity`. This limit does not apply to XML declarations or UTF-16 byte signatures. Supplying it when `xml` is `true` throws a `TypeError`.\n\n## Credits\n\nThis package was originally based on the excellent work of [@nicolashenry](https://github.com/nicolashenry), [in jsdom](https://github.com/tmpvar/jsdom/blob/16fd85618f2705d181232f6552125872a37164bc/lib/jsdom/living/helpers/encoding.js). It has since been pulled out into this separate package.\n","publish_time":1789974287276,"_cnpm_publish_time":1789974287276,"dist-tags":{"latest":"7.0.0"}}