{"id":18429643,"url":"https://github.com/jsdom/whatwg-encoding","last_synced_at":"2025-04-06T07:10:52.882Z","repository":{"id":47133960,"uuid":"71024806","full_name":"jsdom/whatwg-encoding","owner":"jsdom","description":"Decode strings according to the WHATWG Encoding Standard","archived":false,"fork":false,"pushed_at":"2024-07-21T05:36:32.000Z","size":83,"stargazers_count":24,"open_issues_count":3,"forks_count":10,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-31T14:00:13.313Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsdom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"tidelift":"npm/jsdom"}},"created_at":"2016-10-16T02:05:19.000Z","updated_at":"2025-03-10T03:03:13.000Z","dependencies_parsed_at":"2024-10-22T23:51:12.271Z","dependency_job_id":null,"html_url":"https://github.com/jsdom/whatwg-encoding","commit_stats":{"total_commits":30,"total_committers":5,"mean_commits":6.0,"dds":0.1333333333333333,"last_synced_commit":"18b33289fd6ce29a1b160b30e65f1c15e3a81e6e"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsdom%2Fwhatwg-encoding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsdom%2Fwhatwg-encoding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsdom%2Fwhatwg-encoding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsdom%2Fwhatwg-encoding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsdom","download_url":"https://codeload.github.com/jsdom/whatwg-encoding/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247445669,"owners_count":20939958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T05:18:01.505Z","updated_at":"2025-04-06T07:10:52.863Z","avatar_url":"https://github.com/jsdom.png","language":"JavaScript","funding_links":["https://tidelift.com/funding/github/npm/jsdom"],"categories":[],"sub_categories":[],"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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsdom%2Fwhatwg-encoding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsdom%2Fwhatwg-encoding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsdom%2Fwhatwg-encoding/lists"}