{"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":{"integrity":"sha512-oWv4T4yJ52iKrufjnyZPkrN0CH3QnrUqdB6In1g5Fe1mia8GmF36gnfNySxoZtxD5+NmYw1EElVXiBk93UeskA==","shasum":"2cb1a8cf0db52414776e5b2a7a04d5dd98158de9","tarball":"http://registry-npm.ywwl.com/html-encoding-sniffer/download/html-encoding-sniffer-3.0.0.tgz","fileCount":4,"unpackedSize":11679,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh2tqcCRA9TVsSAnZWagAAEAwP/jj89iMOgV3PssvMtzfk\nVKg21813w27zJEqNya/zc7xXVobfaVILk5XuT6UIr6H4/LEeYcAVWJRVHQuH\nJqSFVMjryVcMXVrAldneVDPTGn/NvpJQrKAOkzABvGifEBw1FAwhcZCr+W/D\nirWkpieFsEhM00gFj76N3SNgjnUR9ufx2w8DhKobSsmSpCeAlG2mBhqLordN\ns8AT7LJKpyUS6qFDfeyLpQVzTDsbnl6WmBV1cOYSE8/0VEqMUv1AHY/HmU0A\n38PzBC4eM8t2o85HQ7psEixuUvU5hJr+gwjC6vmGg0j2rCaG0xM1cc3Q8SO1\npYqKFZoZRDZOj/JZL4oTRBBoZojxjlmPydVPz6Ablmp8VxaIEQ3G5xYU+SMb\nRS3+yMcgaBLLULp890Cc1ASXYfmTUsuRHvlHbyCB9y+j4Bl+TisLfFea4TxL\nMqTAxU+37E1os13iMXWrtr/j3J1tVRgqbysZSGwE5FoewqrxIXb89QXzom2Q\nlKtA8yhE2sBZ/TPSHsCzfLPPbq93Mg1VaOcfQlmJzlCVkS+3uqQFLOGxQIf2\nLgCgsBKCXFZlPXFnXhu+TtBFew/oOl7RlYPDD8Dgnn/NfslPy63czWUent7w\ntm6wAGtrQv1VV4zpiCtos06uoUdOcFG1Dhxl4zIEaqVouMlUT7CWo2ADx5pC\nkC0m\r\n=X8Aj\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDD2Auim96lEI5XZM090xuCmLpyzetKPrqqKJv5zZkF7gIhAPQisGTiiGJXXzvkxPKB6nx3DRtuY6MoXKncmNDh8LRR"}],"size":3840,"noattachment":false,"key":"/html-encoding-sniffer/-/html-encoding-sniffer-3.0.0.tgz"},"_npmUser":{"name":"domenic","email":"d@domenic.me"},"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"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/html-encoding-sniffer_3.0.0_1632004810793_0.020944850433149753"},"_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 [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(htmlBytes, sniffedEncoding);\n```\n\n## Options\n\nYou can pass two potential options to `htmlEncodingSniffer`:\n\n```js\nconst sniffedEncoding = htmlEncodingSniffer(htmlBytes, {\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","publish_time":1632004810894,"_cnpm_publish_time":1632004810894,"dist-tags":{"latest":"7.0.0"}}