{"id":18317896,"url":"https://github.com/idiocc/text-decoding","last_synced_at":"2025-04-05T21:32:31.465Z","repository":{"id":60775279,"uuid":"194792051","full_name":"idiocc/text-decoding","owner":"idiocc","description":"[fork] Polyfill for the Encoding Living Standard's API Written In ES6 And Optimised With JavaScript Compiler.","archived":false,"fork":false,"pushed_at":"2019-07-02T11:00:22.000Z","size":758,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T17:07:49.143Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://idio.cc","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/idiocc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-02T05:10:34.000Z","updated_at":"2025-02-11T11:15:19.000Z","dependencies_parsed_at":"2022-10-04T16:37:49.647Z","dependency_job_id":null,"html_url":"https://github.com/idiocc/text-decoding","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Ftext-decoding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Ftext-decoding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Ftext-decoding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Ftext-decoding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/idiocc","download_url":"https://codeload.github.com/idiocc/text-decoding/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406082,"owners_count":20933803,"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-05T18:07:48.688Z","updated_at":"2025-04-05T21:32:30.360Z","avatar_url":"https://github.com/idiocc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# text-decoding\n\n[![npm version](https://badge.fury.io/js/text-decoding.svg)](https://npmjs.org/package/text-decoding)\n\n`text-decoding` is a fork of [Polyfill for the Encoding Living Standard's API](https://github.com/inexorabletash/text-encoding) (`text-encoding`) For Node.JS.\n\nThis is a polyfill for the [Encoding Living Standard](https://encoding.spec.whatwg.org/) API for the Web, allowing encoding and decoding of textual data to and from Typed Array buffers for binary data in JavaScript.\n\nBy default it adheres to the spec and does not support encoding to legacy encodings, only decoding. It is also implemented to match the specification's algorithms, rather than for performance.\n\n```sh\nyarn add text-decoding\n```\n\n## Table Of Contents\n\n- [Table Of Contents](#table-of-contents)\n- [API](#api)\n- [`class TextDecoder`](#class-textdecoder)\n- [`class TextEncoder`](#class-textencoder)\n- [`const EncodingIndexes`](#const-encodingindexes)\n- [`getEncoding(label: string): { name: string, labels: Array\u003cstring\u003e }`](#getencodinglabel-string--name-string-labels-arraystring-)\n- [Encodings](#encodings)\n- [Copyright](#copyright)\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\"/.documentary/section-breaks/0.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## API\n\nThe package is available by importing its named classes and functions:\n\n```js\nimport { TextEncoder, TextDecoder, EncodingIndexes, getEncoding } from 'text-decoding'\n```\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\"/.documentary/section-breaks/1.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## `class TextDecoder`\n\nDecodes a Uint8Array into a string.\n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003eSource\u003c/th\u003e\u003cth\u003eOutput\u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```js\nimport { TextDecoder } from 'text-decoding'\n\nconst decoded = new TextDecoder('utf-8')\n  .decode(new Uint8Array([\n    0x7A, 0xC2, 0xA2, 0xE6, 0xB0, 0xB4, 0xF0,\n    0x9D, 0x84, 0x9E, 0xF4, 0x8F, 0xBF, 0xBD,\n  ]))\nconsole.log(decoded)\n```\n\u003c/td\u003e\n\u003ctd\u003e\n\n```\nz¢水𝄞􏿽\n```\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\"/.documentary/section-breaks/2.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## `class TextEncoder`\n\nEncodes a string into `Uint8Array` for the given encoding.\n\nAs required by the specification, only encoding to utf-8 is supported. If you want to try it out, you can force a non-standard behavior by passing the `NONSTANDARD_allowLegacyEncoding` option to _TextEncoder_ and a label. For example:\n\n```js\nimport { TextEncoder } from 'text-decoding'\n\nconst uint8array = new TextEncoder(\n  'windows-1252', { NONSTANDARD_allowLegacyEncoding: true })\n  .encode('hello world')\n\nconsole.log(uint8array)\n```\n```js\nUint8Array [ 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100 ]\n```\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\"/.documentary/section-breaks/3.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## `const EncodingIndexes`\n\nThis is [a map of indexes](src/encoding-indexes.js) used for encoding.\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\"/.documentary/section-breaks/4.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## `getEncoding(`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`label: string,`\u003cbr/\u003e`): { name: string, labels: Array\u003cstring\u003e }`\n\nReturns the normalised name of the encoding and its associated labels.\n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003eSource\u003c/th\u003e\u003cth\u003eOutput\u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```js\nimport { getEncoding } from 'text-decoding'\n\nconst encoding = getEncoding('ascii')\nconsole.log(encoding)\n```\n\u003c/td\u003e\n\u003ctd\u003e\n\n```js\n{ labels: \n   [ 'ansi_x3.4-1968',\n     'ascii',\n     'cp1252',\n     'cp819',\n     'csisolatin1',\n     'ibm819',\n     'iso-8859-1',\n     'iso-ir-100',\n     'iso8859-1',\n     'iso88591',\n     'iso_8859-1',\n     'iso_8859-1:1987',\n     'l1',\n     'latin1',\n     'us-ascii',\n     'windows-1252',\n     'x-cp1252' ],\n  name: 'windows-1252' }\n```\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\"/.documentary/section-breaks/5.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n\n## Encodings\n\nAll encodings from the Encoding specification are supported:\n\nutf-8 ibm866 iso-8859-2 iso-8859-3 iso-8859-4 iso-8859-5 iso-8859-6 iso-8859-7 iso-8859-8 iso-8859-8-i iso-8859-10 iso-8859-13 iso-8859-14 iso-8859-15 iso-8859-16 koi8-r koi8-u macintosh windows-874 windows-1250 windows-1251 windows-1252 windows-1253 windows-1254 windows-1255 windows-1256 windows-1257 windows-1258 x-mac-cyrillic gb18030 hz-gb-2312 big5 euc-jp iso-2022-jp shift_jis euc-kr replacement utf-16be utf-16le x-user-defined\n\n(Some encodings may be supported under other names, e.g. ascii, iso-8859-1, etc. See [Encoding](https://encoding.spec.whatwg.org/) for additional labels for each encoding.)\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\"/.documentary/section-breaks/6.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## Copyright\n\nOriginal Work By [Joshua Bell](https://github.com/inexorabletash/text-encoding) under dual Unlicense/Apache-2.0 license.\n\n\u003e The encoding indexes, algorithms, and many comments in the code derive from the Encoding Standard https://encoding.spec.whatwg.org/\n\n---\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003e\n      \u003ca href=\"https://artd.eco\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/wrote/wrote/master/images/artdeco.png\" alt=\"Art Deco\"\u003e\n      \u003c/a\u003e\n    \u003c/th\u003e\n    \u003cth\u003e© \u003ca href=\"https://artd.eco\"\u003eArt Deco\u003c/a\u003e for \u003ca href=\"https://idio.cc\"\u003eIdio\u003c/a\u003e 2019\u003c/th\u003e\n    \u003cth\u003e\n      \u003ca href=\"https://idio.cc\"\u003e\n        \u003cimg src=\"https://avatars3.githubusercontent.com/u/40834161?s=100\" width=\"100\" alt=\"Idio\"\u003e\n      \u003c/a\u003e\n    \u003c/th\u003e\n    \u003cth\u003e\n      \u003ca href=\"https://www.technation.sucks\" title=\"Tech Nation Visa\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/artdecoweb/www.technation.sucks/master/anim.gif\"\n          alt=\"Tech Nation Visa\"\u003e\n      \u003c/a\u003e\n    \u003c/th\u003e\n    \u003cth\u003e\u003ca href=\"https://www.technation.sucks\"\u003eTech Nation Visa Sucks\u003c/a\u003e\u003c/th\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\"/.documentary/section-breaks/-1.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiocc%2Ftext-decoding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidiocc%2Ftext-decoding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiocc%2Ftext-decoding/lists"}