{"name":"whatwg-encoding","description":"Decode strings according to the WHATWG Encoding Standard","keywords":["encoding","whatwg"],"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/whatwg-encoding.git"},"main":"lib/whatwg-encoding.js","scripts":{"test":"mocha","lint":"eslint .","prepare":"node scripts/update.js"},"dependencies":{"iconv-lite":"0.6.3"},"devDependencies":{"@domenic/eslint-config":"^1.3.0","eslint":"^7.32.0","minipass-fetch":"^1.4.1","mocha":"^9.1.1"},"engines":{"node":">=12"},"gitHead":"8d9446b437a613d6337044b60e2d1f2267ea1ddd","bugs":{"url":"https://github.com/jsdom/whatwg-encoding/issues"},"homepage":"https://github.com/jsdom/whatwg-encoding#readme","_id":"whatwg-encoding@2.0.0","_nodeVersion":"16.9.1","_npmVersion":"7.21.1","dist":{"integrity":"sha512-p41ogyeMUrw3jWclHWTQg1k05DSVXPLcVxRTYsXUk+ZooOCZLcoYgPZ/HL/D/N+uQPOtcp1me1WhBEaX02mhWg==","shasum":"e7635f597fd87020858626805a2729fa7698ac53","tarball":"http://registry-npm.ywwl.com/whatwg-encoding/download/whatwg-encoding-2.0.0.tgz","fileCount":6,"unpackedSize":12840,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhPmXKCRA9TVsSAnZWagAAmIsP/jJIgz7s+kXxIDdn9v3w\nxJ0BFisFDUGHYNQPlUjoUgqXmhZXFhY+XwnSSMu4RxAjhxKnNBYsN71pS/Q+\nEVV0Qsz2M2DvdgQfVvtoQDLqNBcEF4v0QJu+RdjrGBhXrIncOyxkVIRJG45v\nDlsf5PvprQAYpShxkW14WivQZqGH+g8wx7tj2Vmgu6w//AQGyL6aPx+qNFN0\nje7XvJJ5AVCvzN657wGr4HYGM/Agg3IZ2ROhf17bNLDZHDNqsrN0GB/zg9IH\nJcKzHZ/Ylw0FN/aOosJ4WQTlhZ42KbGR9xV9fcWS1dxfhqapuYPspTLeJzzM\nEJ0Ryjs6QTNqqDu6S6KN44KI0/qSEiPqiCwONHvGo06l7ZSEH9aybBG6H/QM\nbTrgyEf+ocbOeAw84MaUkQ7xmN/AQSOX+cUYQOZgfkphUSnEuNz+v1ykoAVG\n6YiM9VAcsPbZrBqmqzksnY0qIuarNgg74wkt0Ui6woqzBZWM2T2HGvh8M+4a\ni4+bipw/6gg+r2f8YlgEKYf17naXLPQ/Zqj6GwUH4ZHIVc/gynQpheIpmSSq\nOjSxq0ZJ/G1uAGN4eyGkT3Zs5qLMUqqKXG3yV+zPvgPNPXQZhRDxHaEn2koj\nqQDu0JcYi4JXjL1eGj12bM0baJRFwfwsHFSg1g7MSazxJjfQ1FzbBRFTIzIc\nMaQx\r\n=Ng2T\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCZV9AGK5nlVZ8RHcTYsFRDcg97JkMZ75NtvbZwu2rpLwIhAK1RZr/hvSnBychJ4cTTvgpsrQwYd7Ll++BiZon+Ybjh"}],"size":4041,"noattachment":false,"key":"/whatwg-encoding/-/whatwg-encoding-2.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/whatwg-encoding_2.0.0_1631479242718_0.11208519588071741"},"_hasShrinkwrap":false,"readme":"# Decode According to the WHATWG Encoding Standard\n\nThis package provides a thin layer on top of [iconv-lite](https://github.com/ashtuchkin/iconv-lite) which makes it expose some of the same primitives as the [Encoding Standard](https://encoding.spec.whatwg.org/).\n\n```js\nconst whatwgEncoding = require(\"whatwg-encoding\");\n\nconsole.assert(whatwgEncoding.labelToName(\"latin1\") === \"windows-1252\");\nconsole.assert(whatwgEncoding.labelToName(\"  CYRILLic \") === \"ISO-8859-5\");\n\nconsole.assert(whatwgEncoding.isSupported(\"IBM866\") === true);\n\n// Not supported by the Encoding Standard\nconsole.assert(whatwgEncoding.isSupported(\"UTF-32\") === false);\n\n// In the Encoding Standard, but this package can't decode it\nconsole.assert(whatwgEncoding.isSupported(\"x-mac-cyrillic\") === false);\n\nconsole.assert(whatwgEncoding.getBOMEncoding(new Uint8Array([0xFE, 0xFF])) === \"UTF-16BE\");\nconsole.assert(whatwgEncoding.getBOMEncoding(new Uint8Array([0x48, 0x69])) === null);\n\nconsole.assert(whatwgEncoding.decode(new Uint8Array([0x48, 0x69]), \"UTF-8\") === \"Hi\");\n```\n\n## API\n\n- `decode(uint8Array, fallbackEncodingName)`: performs the [decode](https://encoding.spec.whatwg.org/#decode) algorithm (in which any BOM will override the passed fallback encoding), and returns the resulting string\n- `labelToName(label)`: performs the [get an encoding](https://encoding.spec.whatwg.org/#concept-encoding-get) algorithm and returns the resulting encoding's name, or `null` for failure\n- `isSupported(name)`: returns whether the encoding is one of [the encodings](https://encoding.spec.whatwg.org/#names-and-labels) of the Encoding Standard, _and_ is an encoding that this package can decode (via iconv-lite)\n- `getBOMEncoding(uint8Array)`: sniffs the first 2–3 bytes of the supplied `Uint8Array`, returning one of the encoding names `\"UTF-8\"`, `\"UTF-16LE\"`, or `\"UTF-16BE\"` if the appropriate BOM is present, or `null` if no BOM is present\n\n## Unsupported encodings\n\nSince we rely on iconv-lite, we are limited to support only the encodings that they support. Currently we are missing support for:\n\n- ISO-2022-JP\n- ISO-8859-8-I\n- replacement\n- x-mac-cyrillic\n- x-user-defined\n\nPassing these encoding names will return `false` when calling `isSupported`, and passing any of the possible labels for these encodings to `labelToName` will return `null`.\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/7ce11776ce161e8d5921a7a183585327400f786b/lib/jsdom/living/helpers/encoding.js). It has since been pulled out into this separate package.\n\n## Alternatives\n\nIf you are looking for a JavaScript implementation of the Encoding Standard's `TextEncoder` and `TextDecoder` APIs, you'll want [@inexorabletash](https://github.com/inexorabletash)'s [text-encoding](https://github.com/inexorabletash/text-encoding) package. Node.js also has them [built-in](https://nodejs.org/dist/latest/docs/api/globals.html#globals_textdecoder).\n","publish_time":1631479242859,"deprecated":"Use @exodus/bytes instead for a more spec-conformant and faster implementation","_cnpm_publish_time":1631479242859,"dist-tags":{"latest":"3.1.1"}}