{"maintainers":[{"name":"domenic","email":"d@domenic.me"}],"keywords":["encoding","html"],"dist-tags":{"latest":"1.0.1"},"author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"description":"Sniff the encoding from a HTML byte stream","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 htmlBuffer = fs.readFileSync(\"./html-page.html\");\nconst sniffedEncoding = htmlEncodingSniffer(htmlBuffer);\n```\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 [whatwg-encoding](https://github.com/jsdom/whatwg-encoding) package to decode the result:\n\n```js\nconst whatwgEncoding = require(\"whatwg-encoding\");\nconst htmlString = whatwgEncoding.decode(htmlBuffer, sniffedEncoding);\n```\n\n## Options\n\nYou can pass two potential options to `htmlEncodingSniffer`:\n\n```js\nconst sniffedEncoding = htmlEncodingSniffer(htmlBuffer, {\n  transportLayerEncodingLabel,\n  defaultEncoding\n});\n```\n\nThese represent two possible inputs into the [encoding sniffing algorithm](https://html.spec.whatwg.org/multipage/syntax.html#encoding-sniffing-algorithm):\n\n- `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- `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. It defaults to `\"windows-1252\"`, as recommended by the algorithm's table of suggested defaults for \"All other locales\" (including the `en` locale).\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","repository":{"type":"git","url":"git+https://github.com/jsdom/html-encoding-sniffer.git"},"bugs":{"url":"https://github.com/jsdom/html-encoding-sniffer/issues"},"license":"WTFPL","versions":{"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","tarball":"http://nexus.dui88.com:8081/nexus/content/repositories/npm-registry/html-encoding-sniffer/-/html-encoding-sniffer-1.0.0.tgz"},"maintainers":[{"name":"domenic","email":"d@domenic.me"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/html-encoding-sniffer-1.0.0.tgz_1476589995029_0.5327760553918779"},"directories":{}},"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","tarball":"http://nexus.dui88.com:8081/nexus/content/repositories/npm-registry/html-encoding-sniffer/-/html-encoding-sniffer-1.0.1.tgz"},"maintainers":[{"name":"domenic","email":"d@domenic.me"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/html-encoding-sniffer-1.0.1.tgz_1476591787938_0.5426098443567753"},"directories":{}}},"name":"html-encoding-sniffer","time":{"modified":"2016-10-16T04:23:09.751Z","created":"2016-10-16T03:53:16.596Z","1.0.0":"2016-10-16T03:53:16.596Z","1.0.1":"2016-10-16T04:23:09.751Z"},"readmeFilename":"README.md","homepage":"https://github.com/jsdom/html-encoding-sniffer#readme"}