{"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":{"integrity":"sha512-Y9prnPKkM7FXxQevZ5UH8Z6aVTY0ede1tHquck5UxGmKWDshxXh95gSa2xXYjS8AsGO5iOvrCI5+GttRKnLdNA==","shasum":"70b3b69bb5999f35d0d4495d79079f35630e71ae","tarball":"http://registry-npm.ywwl.com/html-encoding-sniffer/download/html-encoding-sniffer-2.0.0.tgz","fileCount":4,"unpackedSize":11183,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeEhkaCRA9TVsSAnZWagAAY3gP/A2kdlKGHR8WGwgG6fU/\nUvrYvRfaNQddDNedUwRuZG8Va63QMeeU8tTe8UyphPyqrbhOJLN88oTR7sOm\n//ZZGL8PIHIr+KCqPUWbld8Jf7DcJBQ/8VgyyH1vlQhQ33M5TEEFsjNesoSz\nWY8fvZGBgd4oAbt3rd9gh2f2DTlcwD28t6Oy6V5U1K+BfHm3hi/hnsYuGaa4\nH/6EyoE5Zbjg0rlMZo6TX7LRk90/K4SEkf0MoDsGN1zjg3JJE1QtFI+JEJsc\nkzlEWhRoCAMwGjzc8JjhsaYmRd42BG8EAmhc67sFX4UUOwGQIbQCXrVdxVCY\nHbVbw+qGkwiHO4KExBDVrdUVM9HpZdSp+N8mOufSNUXKOSiAomZlt9xYoFFG\nDvna8ZAELVeXKdsEVKRqtlmEjy2NCCJvannsHMtjq83iAKmrNCKNsBQbxDqY\nwT52Y6PDelZ2/DWJY8b5Qexw/vpdPq84bbBoAvDHCsxRpX7GegyBcOMOdczC\nFgB+eEquEx/0I6M6sHpRLWW2ksSfci9q9MTPZFVGNo6/IrXRmxebAixwoqYY\nqWq9F4es5uig7PR2BAgfmk28bv9ITrUk1bFGpOVu3mO+MyT32bNQpkabnnkR\nPFXXTFqPSrU6Iu78brd4owMlYuAMiOIceQQqWgsFd31urNXIGoqymCM7hgL3\nozTt\r\n=L2Z3\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGc7V5pPGIk3cL5WGoGnTl/t4V1y3r3SwGcniGzQEKsHAiEA86Gz5a85UAWSXOVTV+VnMFBX6SjaNWQEjT7xNgEbudI="}],"size":3706,"noattachment":false,"key":"/html-encoding-sniffer/-/html-encoding-sniffer-2.0.0.tgz"},"maintainers":[{"email":"d@domenic.me","name":"domenic"},{"email":"joris@jorisvanderwel.com","name":"joris-van-der-wel"},{"email":"sebmaster16@gmail.com","name":"sebmaster"},{"email":"timothygu99@gmail.com","name":"timothygu"},{"email":"tmpvar@gmail.com","name":"tmpvar"},{"email":"code@zirro.se","name":"zirro"}],"_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,"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":1578244378185,"_cnpm_publish_time":1578244378185,"dist-tags":{"latest":"7.0.0"}}