{"_id":"text-decoding","_rev":"298570","name":"text-decoding","description":"[fork] TextEncoder and TextDecoder (Polyfill for the Encoding Living Standard's API) For Node.JS.","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"zvr","email":""}],"time":{"modified":"2024-01-15T13:44:11.000Z","created":"2019-07-02T11:00:11.283Z","1.0.0":"2019-07-02T11:00:11.283Z"},"users":{},"author":{"name":"Anton","email":"anton@adc.sh"},"repository":{"type":"git","url":"git://github.com/idiocc/text-decoding.git"},"versions":{"1.0.0":{"name":"text-decoding","version":"1.0.0","description":"[fork] TextEncoder and TextDecoder (Polyfill for the Encoding Living Standard's API) For Node.JS.","main":"build/index.js","module":"src/index.js","scripts":{"t":"zoroaster -a","test":"yarn t test/spec test/mask","spec":"yarn t test/spec","mask":"yarn t test/mask","test-build":"ALAMODE_ENV=test-build yarn test","lint":"eslint .","doc":"NODE_DEBUG=doc doc -o README.md","b":"alamode src -o build -s","d":"yarn-s d1 externs","d1":"typal types/index.js src -c -t types/index.xml","externs":"typal types/externs.js","build":"yarn-s d b doc","e":"alanode"},"externs":"types/externs.js","repository":{"type":"git","url":"git://github.com/idiocc/text-decoding.git"},"keywords":["text-encoding","encoding","text-decoding","TextEncoder","TextDecoder","decoding","ascii","windows-1252","big5","euc-jp","euc-kr","gb18030","iso-20220jp","shift-jis","single-byte","utf8","utf16","x-user-defined","unicode"],"author":{"name":"Anton","email":"anton@adc.sh"},"license":"MIT","bugs":{"url":"https://github.com/idiocc/text-decoding/issues"},"homepage":"https://github.com/idiocc/text-decoding#readme","devDependencies":{"alamode":"^2.3.4","documentary":"^1.27.4","eslint-config-artdeco":"1.0.1","yarn-s":"1.1.0","zoroaster":"^4.1.1-alpha"},"licenseText":"MIT License\n\nCopyright (c) 2019 Art Deco Code Limited\n\n + ES6 code with ECMA modules\n + Zoroaster spec and mask tests\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\nOriginal Work by Joshua Bell and contributors\nDual License: Unlicense/Apache 2.0 License","_id":"text-decoding@1.0.0","dist":{"shasum":"38a5692d23b5c2b12942d6e245599cb58b1bc52f","size":415678,"noattachment":false,"key":"/text-decoding/-/text-decoding-1.0.0.tgz","tarball":"http://name.csiicloud.com:7001/text-decoding/download/text-decoding-1.0.0.tgz"},"maintainers":[{"name":"zvr","email":""}],"_npmUser":{"name":"zvr","email":"anton@adc.sh"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/text-decoding_1.0.0_1562065211107_0.38723988200493364"},"_hasShrinkwrap":false,"publish_time":1562065211283,"_cnpm_publish_time":1562065211283,"_cnpmcore_publish_time":"2021-12-16T16:19:39.006Z"}},"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<string> }`](#getencodinglabel-string--name-string-labels-arraystring-)\n- [Encodings](#encodings)\n- [Copyright](#copyright)\n\n<p align=\"center\"><a href=\"#table-of-contents\"><img src=\"/.documentary/section-breaks/0.svg?sanitize=true\"></a></p>\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<p align=\"center\"><a href=\"#table-of-contents\"><img src=\"/.documentary/section-breaks/1.svg?sanitize=true\"></a></p>\n\n## `class TextDecoder`\n\nDecodes a Uint8Array into a string.\n\n<table>\n<tr><th>Source</th><th>Output</th></tr>\n<tr><td>\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</td>\n<td>\n\n```\nz¢水????????\n```\n</td></tr>\n</table>\n\n<p align=\"center\"><a href=\"#table-of-contents\"><img src=\"/.documentary/section-breaks/2.svg?sanitize=true\"></a></p>\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<p align=\"center\"><a href=\"#table-of-contents\"><img src=\"/.documentary/section-breaks/3.svg?sanitize=true\"></a></p>\n\n## `const EncodingIndexes`\n\nThis is [a map of indexes](src/encoding-indexes.js) used for encoding.\n\n<p align=\"center\"><a href=\"#table-of-contents\"><img src=\"/.documentary/section-breaks/4.svg?sanitize=true\"></a></p>\n\n## `getEncoding(`<br/>&nbsp;&nbsp;`label: string,`<br/>`): { name: string, labels: Array<string> }`\n\nReturns the normalised name of the encoding and its associated labels.\n\n<table>\n<tr><th>Source</th><th>Output</th></tr>\n<tr><td>\n\n```js\nimport { getEncoding } from 'text-decoding'\n\nconst encoding = getEncoding('ascii')\nconsole.log(encoding)\n```\n</td>\n<td>\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</td></tr>\n</table>\n\n<p align=\"center\"><a href=\"#table-of-contents\"><img src=\"/.documentary/section-breaks/5.svg?sanitize=true\"></a></p>\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<p align=\"center\"><a href=\"#table-of-contents\"><img src=\"/.documentary/section-breaks/6.svg?sanitize=true\"></a></p>\n\n## Copyright\n\nOriginal Work By [Joshua Bell](https://github.com/inexorabletash/text-encoding) under dual Unlicense/Apache-2.0 license.\n\n> The encoding indexes, algorithms, and many comments in the code derive from the Encoding Standard https://encoding.spec.whatwg.org/\n\n---\n\n<table>\n  <tr>\n    <th>\n      <a href=\"https://artd.eco\">\n        <img src=\"https://raw.githubusercontent.com/wrote/wrote/master/images/artdeco.png\" alt=\"Art Deco\">\n      </a>\n    </th>\n    <th>© <a href=\"https://artd.eco\">Art Deco</a> for <a href=\"https://idio.cc\">Idio</a> 2019</th>\n    <th>\n      <a href=\"https://idio.cc\">\n        <img src=\"https://avatars3.githubusercontent.com/u/40834161?s=100\" width=\"100\" alt=\"Idio\">\n      </a>\n    </th>\n    <th>\n      <a href=\"https://www.technation.sucks\" title=\"Tech Nation Visa\">\n        <img src=\"https://raw.githubusercontent.com/artdecoweb/www.technation.sucks/master/anim.gif\"\n          alt=\"Tech Nation Visa\">\n      </a>\n    </th>\n    <th><a href=\"https://www.technation.sucks\">Tech Nation Visa Sucks</a></th>\n  </tr>\n</table>\n\n<p align=\"center\"><a href=\"#table-of-contents\"><img src=\"/.documentary/section-breaks/-1.svg?sanitize=true\"></a></p>","_attachments":{},"homepage":"https://github.com/idiocc/text-decoding#readme","bugs":{"url":"https://github.com/idiocc/text-decoding/issues"},"license":"MIT"}