@types/whatwg-encoding
- Version 2.0.3
- Published
- 6.96 kB
- No dependencies
- MIT license
Install
npm i @types/whatwg-encoding
yarn add @types/whatwg-encoding
pnpm add @types/whatwg-encoding
Overview
TypeScript definitions for whatwg-encoding
Index
Functions
Type Aliases
Functions
function decode
decode: (uint8Array: Uint8Array, fallbackEncodingName: string) => string;
Performs the [decode](https://encoding.spec.whatwg.org/#decode) algorithm (in which any BOM will override the passed fallback encoding).
Returns
The resulting string.
Throws
RangeError
if an unsupported encoding is provided forfallbackEncodingName
.Example 1
import { decode } from "whatwg-encoding";
console.assert(decode(new Uint8Array([0x48, 0x69]), "UTF-8") === "Hi");
function getBOMEncoding
getBOMEncoding: (uint8Array: Uint8Array) => BOMEncoding | null;
Sniffs the first 2–3 bytes of the supplied
Uint8Array
.Returns
One of the encoding names if the appropriate BOM is present, or
null
if no BOM is present.Example 1
import { getBOMEncoding } from "whatwg-encoding";
console.assert(getBOMEncoding(new Uint8Array([0xFE, 0xFF])) === "UTF-16BE"); console.assert(getBOMEncoding(new Uint8Array([0x48, 0x69])) === null);
function isSupported
isSupported: (name: string) => boolean;
Checks 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
).Example 1
import { isSupported } from "whatwg-encoding";
console.assert(isSupported("IBM866") === true);
// Not supported by the Encoding Standard console.assert(isSupported("UTF-32") === false);
// In the Encoding Standard, but this package can't decode it console.assert(isSupported("x-mac-cyrillic") === false);
function labelToName
labelToName: (label: string) => string | null;
Performs the [get an encoding](https://encoding.spec.whatwg.org/#concept-encoding-get) algorithm.
Returns
The resulting encoding's name, or
null
for failure.Example 1
import { labelToName } from "whatwg-encoding";
console.assert(labelToName("latin1") === "windows-1252"); console.assert(labelToName(" CYRILLic ") === "ISO-8859-5");
Type Aliases
type BOMEncoding
type BOMEncoding = 'UTF-16BE' | 'UTF-16LE' | 'UTF-8';
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/whatwg-encoding
.
- Markdown[](https://www.jsdocs.io/package/@types/whatwg-encoding)
- HTML<a href="https://www.jsdocs.io/package/@types/whatwg-encoding"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3061 ms. - Missing or incorrect documentation? Open an issue for this package.