{"_id":"html-encoding-sniffer","_rev":"4194679","name":"html-encoding-sniffer","description":"Sniff the encoding from a HTML byte stream","dist-tags":{"latest":"6.0.0"},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":"joris@jorisvanderwel.com"},{"name":"sebmaster","email":""},{"name":"timothygu","email":"timothygu99@gmail.com"},{"name":"tmpvar","email":"tmpvar@gmail.com"},{"name":"zirro","email":"code@zirro.se"}],"time":{"modified":"2026-03-02T02:52:19.000Z","created":"2016-10-16T03:53:16.596Z","6.0.0":"2025-12-26T03:54:44.115Z","5.0.0":"2025-12-23T05:04:24.244Z","4.0.0":"2023-11-12T07:38:15.637Z","3.0.0":"2021-09-18T22:40:10.894Z","2.0.1":"2020-02-23T22:27:41.834Z","2.0.0":"2020-01-05T17:12:58.185Z","1.0.2":"2017-10-23T00:15:57.146Z","1.0.1":"2016-10-16T04:23:09.751Z","1.0.0":"2016-10-16T03:53:16.596Z"},"users":{},"author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"repository":{"type":"git","url":"git+https://github.com/jsdom/html-encoding-sniffer.git"},"versions":{"6.0.0":{"name":"html-encoding-sniffer","description":"Sniff the encoding from a HTML byte stream","keywords":["encoding","html"],"version":"6.0.0","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jsdom/html-encoding-sniffer.git"},"main":"lib/html-encoding-sniffer.js","scripts":{"test":"node --test","lint":"eslint"},"dependencies":{"@exodus/bytes":"^1.6.0"},"devDependencies":{"@domenic/eslint-config":"^4.0.1","eslint":"^9.39.2","globals":"^16.5.0"},"engines":{"node":"^20.19.0 || ^22.12.0 || >=24.0.0"},"gitHead":"a2f5ea718eea331aa7b098f40044f72adc49d45e","_id":"html-encoding-sniffer@6.0.0","bugs":{"url":"https://github.com/jsdom/html-encoding-sniffer/issues"},"homepage":"https://github.com/jsdom/html-encoding-sniffer#readme","_nodeVersion":"24.12.0","_npmVersion":"11.6.2","dist":{"shasum":"f8d9390b3b348b50d4f61c16dd2ef5c05980a882","size":4099,"noattachment":false,"key":"/html-encoding-sniffer/-/html-encoding-sniffer-6.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/html-encoding-sniffer/download/html-encoding-sniffer-6.0.0.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:3e41e1dd-6fba-4b18-a39b-23d35ea8520a"}},"directories":{},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":"joris@jorisvanderwel.com"},{"name":"sebmaster","email":""},{"name":"timothygu","email":"timothygu99@gmail.com"},{"name":"tmpvar","email":"tmpvar@gmail.com"},{"name":"zirro","email":"code@zirro.se"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/html-encoding-sniffer_6.0.0_1766721283929_0.05459638768167974"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-12-26T03:54:44.115Z","publish_time":1766721284115,"_source_registry_name":"default","_cnpm_publish_time":1766721284115},"5.0.0":{"name":"html-encoding-sniffer","description":"Sniff the encoding from a HTML byte stream","keywords":["encoding","html"],"version":"5.0.0","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jsdom/html-encoding-sniffer.git"},"main":"lib/html-encoding-sniffer.js","scripts":{"test":"node --test","lint":"eslint"},"dependencies":{"@exodus/bytes":"^1.2.0"},"devDependencies":{"@domenic/eslint-config":"^4.0.1","eslint":"^9.39.2","globals":"^16.5.0"},"engines":{"node":"^20.19.0 || ^22.12.0 || >=24.0.0"},"gitHead":"fab2967107d2caea4fa032fc247537a403f12461","_id":"html-encoding-sniffer@5.0.0","bugs":{"url":"https://github.com/jsdom/html-encoding-sniffer/issues"},"homepage":"https://github.com/jsdom/html-encoding-sniffer#readme","_nodeVersion":"24.12.0","_npmVersion":"11.6.2","dist":{"shasum":"7cc221eb3cd85c9a38f43335e83c941156874984","size":3968,"noattachment":false,"key":"/html-encoding-sniffer/-/html-encoding-sniffer-5.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/html-encoding-sniffer/download/html-encoding-sniffer-5.0.0.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:3e41e1dd-6fba-4b18-a39b-23d35ea8520a"}},"directories":{},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":"joris@jorisvanderwel.com"},{"name":"sebmaster","email":""},{"name":"timothygu","email":"timothygu99@gmail.com"},{"name":"tmpvar","email":"tmpvar@gmail.com"},{"name":"zirro","email":"code@zirro.se"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/html-encoding-sniffer_5.0.0_1766466264105_0.3090489086520247"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-12-23T05:04:24.244Z","publish_time":1766466264244,"_source_registry_name":"default","_cnpm_publish_time":1766466264244},"4.0.0":{"name":"html-encoding-sniffer","description":"Sniff the encoding from a HTML byte stream","keywords":["encoding","html"],"version":"4.0.0","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jsdom/html-encoding-sniffer.git"},"main":"lib/html-encoding-sniffer.js","scripts":{"test":"node --test","lint":"eslint ."},"dependencies":{"whatwg-encoding":"^3.1.1"},"devDependencies":{"@domenic/eslint-config":"^3.0.0","eslint":"^8.53.0"},"engines":{"node":">=18"},"_id":"html-encoding-sniffer@4.0.0","gitHead":"d655e5adef00678d24d228c1cd8e34f1299c2e1f","bugs":{"url":"https://github.com/jsdom/html-encoding-sniffer/issues"},"homepage":"https://github.com/jsdom/html-encoding-sniffer#readme","_nodeVersion":"21.1.0","_npmVersion":"10.2.0","dist":{"shasum":"696df529a7cfd82446369dc5193e590a3735b448","size":3850,"noattachment":false,"key":"/html-encoding-sniffer/-/html-encoding-sniffer-4.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/html-encoding-sniffer/download/html-encoding-sniffer-4.0.0.tgz"},"_npmUser":{"name":"domenic","email":"d@domenic.me"},"directories":{},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":"joris@jorisvanderwel.com"},{"name":"sebmaster","email":""},{"name":"timothygu","email":"timothygu99@gmail.com"},{"name":"tmpvar","email":"tmpvar@gmail.com"},{"name":"zirro","email":"code@zirro.se"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/html-encoding-sniffer_4.0.0_1699774695445_0.18692303422369672"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-11-12T07:38:15.637Z","publish_time":1699774695637,"_source_registry_name":"default","_cnpm_publish_time":1699774695637},"3.0.0":{"name":"html-encoding-sniffer","description":"Sniff the encoding from a HTML byte stream","keywords":["encoding","html"],"version":"3.0.0","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jsdom/html-encoding-sniffer.git"},"main":"lib/html-encoding-sniffer.js","scripts":{"test":"mocha","lint":"eslint ."},"dependencies":{"whatwg-encoding":"^2.0.0"},"devDependencies":{"@domenic/eslint-config":"^1.4.0","eslint":"^7.32.0","mocha":"^9.1.1"},"engines":{"node":">=12"},"gitHead":"7de54310087887b3fbb2c89b05d5fbc36da82078","bugs":{"url":"https://github.com/jsdom/html-encoding-sniffer/issues"},"homepage":"https://github.com/jsdom/html-encoding-sniffer#readme","_id":"html-encoding-sniffer@3.0.0","_nodeVersion":"16.9.1","_npmVersion":"7.21.1","dist":{"shasum":"2cb1a8cf0db52414776e5b2a7a04d5dd98158de9","size":3840,"noattachment":false,"key":"/html-encoding-sniffer/-/html-encoding-sniffer-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/html-encoding-sniffer/download/html-encoding-sniffer-3.0.0.tgz"},"_npmUser":{"name":"domenic","email":"d@domenic.me"},"directories":{},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":"joris@jorisvanderwel.com"},{"name":"sebmaster","email":""},{"name":"timothygu","email":"timothygu99@gmail.com"},{"name":"tmpvar","email":"tmpvar@gmail.com"},{"name":"zirro","email":"code@zirro.se"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/html-encoding-sniffer_3.0.0_1632004810793_0.020944850433149753"},"_hasShrinkwrap":false,"publish_time":1632004810894,"_cnpm_publish_time":1632004810894},"2.0.1":{"name":"html-encoding-sniffer","description":"Sniff the encoding from a HTML byte stream","keywords":["encoding","html"],"version":"2.0.1","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jsdom/html-encoding-sniffer.git"},"main":"lib/html-encoding-sniffer.js","scripts":{"test":"mocha","lint":"eslint ."},"dependencies":{"whatwg-encoding":"^1.0.5"},"devDependencies":{"eslint":"^6.8.0","mocha":"^7.0.0"},"engines":{"node":">=10"},"gitHead":"24a3f567dcffa23ef6d2c3f238b1299f7a71569f","bugs":{"url":"https://github.com/jsdom/html-encoding-sniffer/issues"},"homepage":"https://github.com/jsdom/html-encoding-sniffer#readme","_id":"html-encoding-sniffer@2.0.1","_nodeVersion":"13.6.0","_npmVersion":"6.13.4","dist":{"shasum":"42a6dc4fd33f00281176e8b23759ca4e4fa185f3","size":3812,"noattachment":false,"key":"/html-encoding-sniffer/-/html-encoding-sniffer-2.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/html-encoding-sniffer/download/html-encoding-sniffer-2.0.1.tgz"},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":"joris@jorisvanderwel.com"},{"name":"sebmaster","email":""},{"name":"timothygu","email":"timothygu99@gmail.com"},{"name":"tmpvar","email":"tmpvar@gmail.com"},{"name":"zirro","email":"code@zirro.se"}],"_npmUser":{"name":"domenic","email":"d@domenic.me"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/html-encoding-sniffer_2.0.1_1582496861635_0.25573667939106226"},"_hasShrinkwrap":false,"publish_time":1582496861834,"_cnpm_publish_time":1582496861834},"2.0.0":{"name":"html-encoding-sniffer","description":"Sniff the encoding from a HTML byte stream","keywords":["encoding","html"],"version":"2.0.0","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jsdom/html-encoding-sniffer.git"},"main":"lib/html-encoding-sniffer.js","scripts":{"test":"mocha","lint":"eslint ."},"dependencies":{"whatwg-encoding":"^1.0.5"},"devDependencies":{"eslint":"^6.8.0","mocha":"^7.0.0"},"engines":{"node":">=10"},"gitHead":"c5e8fe3539a6ad4be2ffe5e5d61060885e3f6d64","bugs":{"url":"https://github.com/jsdom/html-encoding-sniffer/issues"},"homepage":"https://github.com/jsdom/html-encoding-sniffer#readme","_id":"html-encoding-sniffer@2.0.0","_nodeVersion":"12.1.0","_npmVersion":"6.9.0","dist":{"shasum":"70b3b69bb5999f35d0d4495d79079f35630e71ae","size":3706,"noattachment":false,"key":"/html-encoding-sniffer/-/html-encoding-sniffer-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/html-encoding-sniffer/download/html-encoding-sniffer-2.0.0.tgz"},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":"joris@jorisvanderwel.com"},{"name":"sebmaster","email":""},{"name":"timothygu","email":"timothygu99@gmail.com"},{"name":"tmpvar","email":"tmpvar@gmail.com"},{"name":"zirro","email":"code@zirro.se"}],"_npmUser":{"name":"domenic","email":"d@domenic.me"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/html-encoding-sniffer_2.0.0_1578244378061_0.49863360811709123"},"_hasShrinkwrap":false,"publish_time":1578244378185,"_cnpm_publish_time":1578244378185},"1.0.2":{"name":"html-encoding-sniffer","description":"Sniff the encoding from a HTML byte stream","keywords":["encoding","html"],"version":"1.0.2","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jsdom/html-encoding-sniffer.git"},"main":"lib/html-encoding-sniffer.js","files":["lib/"],"scripts":{"test":"mocha","lint":"eslint lib test"},"dependencies":{"whatwg-encoding":"^1.0.1"},"devDependencies":{"eslint":"^3.8.0","mocha":"^3.1.2"},"gitHead":"8d69308c38af4b19170d2caeac6e16c6f52f5e01","bugs":{"url":"https://github.com/jsdom/html-encoding-sniffer/issues"},"homepage":"https://github.com/jsdom/html-encoding-sniffer#readme","_id":"html-encoding-sniffer@1.0.2","_npmVersion":"5.4.2","_nodeVersion":"8.6.0","_npmUser":{"name":"domenic","email":"d@domenic.me"},"dist":{"shasum":"e70d84b94da53aa375e11fe3a351be6642ca46f8","size":3713,"noattachment":false,"key":"/html-encoding-sniffer/-/html-encoding-sniffer-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/html-encoding-sniffer/download/html-encoding-sniffer-1.0.2.tgz"},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":"joris@jorisvanderwel.com"},{"name":"sebmaster","email":""},{"name":"timothygu","email":"timothygu99@gmail.com"},{"name":"tmpvar","email":"tmpvar@gmail.com"},{"name":"zirro","email":"code@zirro.se"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/html-encoding-sniffer-1.0.2.tgz_1508717756193_0.17921806732192636"},"directories":{},"publish_time":1508717757146,"_hasShrinkwrap":false,"_cnpm_publish_time":1508717757146},"1.0.1":{"name":"html-encoding-sniffer","description":"Sniff the encoding from a HTML byte stream","keywords":["encoding","html"],"version":"1.0.1","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"license":"WTFPL","repository":{"type":"git","url":"git+https://github.com/jsdom/html-encoding-sniffer.git"},"main":"lib/html-encoding-sniffer.js","files":["lib/"],"scripts":{"test":"mocha","lint":"eslint lib test"},"dependencies":{"whatwg-encoding":"^1.0.1"},"devDependencies":{"eslint":"^3.8.0","mocha":"^3.1.2"},"gitHead":"9b4a785caf193f8852770b7dfc7194431fbf8bed","bugs":{"url":"https://github.com/jsdom/html-encoding-sniffer/issues"},"homepage":"https://github.com/jsdom/html-encoding-sniffer#readme","_id":"html-encoding-sniffer@1.0.1","_shasum":"79bf7a785ea495fe66165e734153f363ff5437da","_from":".","_npmVersion":"3.9.5","_nodeVersion":"6.2.2","_npmUser":{"name":"domenic","email":"d@domenic.me"},"dist":{"shasum":"79bf7a785ea495fe66165e734153f363ff5437da","size":3471,"noattachment":false,"key":"/html-encoding-sniffer/-/html-encoding-sniffer-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/html-encoding-sniffer/download/html-encoding-sniffer-1.0.1.tgz"},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":"joris@jorisvanderwel.com"},{"name":"sebmaster","email":""},{"name":"timothygu","email":"timothygu99@gmail.com"},{"name":"tmpvar","email":"tmpvar@gmail.com"},{"name":"zirro","email":"code@zirro.se"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/html-encoding-sniffer-1.0.1.tgz_1476591787938_0.5426098443567753"},"directories":{},"publish_time":1476591789751,"_cnpm_publish_time":1476591789751,"_hasShrinkwrap":false},"1.0.0":{"name":"html-encoding-sniffer","description":"Sniff the encoding from a HTML byte stream","keywords":["encoding","html"],"version":"1.0.0","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"license":"WTFPL","repository":{"type":"git","url":"git+https://github.com/jsdom/html-encoding-sniffer.git"},"main":"lib/html-encoding-sniffer.js","files":["lib/"],"scripts":{"test":"mocha","lint":"eslint lib test"},"dependencies":{"whatwg-encoding":"^1.0.1"},"devDependencies":{"eslint":"^3.8.0","mocha":"^3.1.2"},"gitHead":"8cd325d2e567e33dec4f0fa489c556e0e290db5d","bugs":{"url":"https://github.com/jsdom/html-encoding-sniffer/issues"},"homepage":"https://github.com/jsdom/html-encoding-sniffer#readme","_id":"html-encoding-sniffer@1.0.0","_shasum":"19f93ff0d070bd3c238f1ff16ea2f68cc0d42c96","_from":".","_npmVersion":"3.9.5","_nodeVersion":"6.2.2","_npmUser":{"name":"domenic","email":"d@domenic.me"},"dist":{"shasum":"19f93ff0d070bd3c238f1ff16ea2f68cc0d42c96","size":3472,"noattachment":false,"key":"/html-encoding-sniffer/-/html-encoding-sniffer-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/html-encoding-sniffer/download/html-encoding-sniffer-1.0.0.tgz"},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":"joris@jorisvanderwel.com"},{"name":"sebmaster","email":""},{"name":"timothygu","email":"timothygu99@gmail.com"},{"name":"tmpvar","email":"tmpvar@gmail.com"},{"name":"zirro","email":"code@zirro.se"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/html-encoding-sniffer-1.0.0.tgz_1476589995029_0.5327760553918779"},"directories":{},"publish_time":1476589996596,"_cnpm_publish_time":1476589996596,"_hasShrinkwrap":false}},"readme":"# Determine the Encoding of a HTML Byte Stream\n\nThis package implements the HTML Standard's [encoding sniffing algorithm](https://html.spec.whatwg.org/multipage/syntax.html#encoding-sniffing-algorithm) in all its glory. The most interesting part of this is how it pre-scans the first 1024 bytes in order to search for certain `<meta charset>`-related patterns.\n\n```js\nconst htmlEncodingSniffer = require(\"html-encoding-sniffer\");\nconst fs = require(\"fs\");\n\nconst htmlBytes = fs.readFileSync(\"./html-page.html\");\nconst sniffedEncoding = htmlEncodingSniffer(htmlBytes);\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\");\nconst htmlString = (new TextDecoder(sniffedEncoding)).decode(htmlBytes);\n```\n\n## Options\n\nYou can pass the following options to `htmlEncodingSniffer`:\n\n```js\nconst sniffedEncoding = htmlEncodingSniffer(htmlBytes, {\n  xml,\n  transportLayerEncodingLabel,\n  defaultEncoding,\n});\n```\n\nThe `xml` option is a boolean, defaulting to `false`. If set to `true`, then we bypass the [HTML encoding sniffing algorithm](https://html.spec.whatwg.org/multipage/syntax.html#encoding-sniffing-algorithm) and compute the encoding based on the presence of a BOM, or the other options provided. (In the future, we may perform sniffing of the `<?xml?>` declaration, but for now that is not implemented.)\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\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","_attachments":{},"homepage":"https://github.com/jsdom/html-encoding-sniffer#readme","bugs":{"url":"https://github.com/jsdom/html-encoding-sniffer/issues"},"license":"MIT"}