mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 15:57:13 +00:00
Merge pull request #22041 from trxcllnt/text-encoding-utf-8
Add text-encoding-utf-8 typings
This commit is contained in:
Vendored
+56
@@ -0,0 +1,56 @@
|
||||
// Type definitions for text-encoding-utf-8 1.0
|
||||
// Project: https://github.com/arv/text-encoding-utf-8
|
||||
// Definitions by: Paul Taylor <https://github.com/trxcllnt>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace TextEncoding {
|
||||
interface TextDecoderOptions {
|
||||
fatal?: boolean;
|
||||
ignoreBOM?: boolean;
|
||||
}
|
||||
|
||||
interface TextDecodeOptions {
|
||||
stream?: boolean;
|
||||
}
|
||||
|
||||
interface TextEncoderOptions {
|
||||
NONSTANDARD_allowLegacyEncoding?: boolean;
|
||||
}
|
||||
|
||||
interface TextDecoder {
|
||||
encoding: string;
|
||||
fatal: boolean;
|
||||
ignoreBOM: boolean;
|
||||
decode(input?: ArrayBuffer | ArrayBufferView, options?: TextDecodeOptions): string;
|
||||
}
|
||||
|
||||
interface TextEncoder {
|
||||
encoding: string;
|
||||
encode(input?: string, options?: TextEncodeOptions): Uint8Array;
|
||||
}
|
||||
|
||||
interface TextEncodeOptions {
|
||||
stream?: boolean;
|
||||
}
|
||||
|
||||
interface TextEncoderStatic {
|
||||
(utfLabel?: string, options?: TextEncoderOptions): TextEncoder;
|
||||
new (utfLabel?: string, options?: TextEncoderOptions): TextEncoder;
|
||||
}
|
||||
|
||||
interface TextDecoderStatic {
|
||||
(label?: string, options?: TextDecoderOptions): TextDecoder;
|
||||
new (label?: string, options?: TextDecoderOptions): TextDecoder;
|
||||
}
|
||||
|
||||
interface TextEncodingStatic {
|
||||
TextEncoder: TextEncoderStatic;
|
||||
TextDecoder: TextDecoderStatic;
|
||||
}
|
||||
}
|
||||
|
||||
declare var TextDecoder: TextEncoding.TextDecoderStatic;
|
||||
|
||||
declare var TextEncoder: TextEncoding.TextEncoderStatic;
|
||||
|
||||
declare var TextEncoding: TextEncoding.TextEncodingStatic;
|
||||
@@ -0,0 +1,50 @@
|
||||
function test_encoder() {
|
||||
const text = "plain text";
|
||||
let uint8array: Uint8Array;
|
||||
|
||||
// constructor
|
||||
uint8array = new TextEncoder().encode(text);
|
||||
uint8array = new TextEncoder('utf-8').encode(text);
|
||||
|
||||
uint8array = TextEncoder().encode(text);
|
||||
uint8array = TextEncoder('utf-8').encode(text);
|
||||
|
||||
// attributes
|
||||
const encoder = new TextEncoder();
|
||||
encoder.encoding = 'utf-8';
|
||||
const encoding: string = encoder.encoding;
|
||||
|
||||
// methods
|
||||
encoder.encode();
|
||||
encoder.encode(text);
|
||||
}
|
||||
|
||||
function test_decoder() {
|
||||
let text = "plain text";
|
||||
const uint8array: Uint8Array = TextEncoder().encode(text);
|
||||
const arrayBuffer: ArrayBuffer = uint8array.buffer;
|
||||
|
||||
// constructor
|
||||
text = new TextDecoder().decode(uint8array);
|
||||
text = new TextDecoder('utf-8').decode(uint8array);
|
||||
|
||||
text = TextDecoder().decode(uint8array);
|
||||
text = TextDecoder('utf-8').decode(uint8array);
|
||||
|
||||
// attributes
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
decoder.encoding = 'utf-8';
|
||||
const encoding: string = decoder.encoding;
|
||||
|
||||
decoder.fatal = true;
|
||||
const fatal: boolean = decoder.fatal;
|
||||
|
||||
decoder.ignoreBOM = true;
|
||||
const ignoreBOM: boolean = decoder.ignoreBOM;
|
||||
|
||||
// methods
|
||||
decoder.decode();
|
||||
decoder.decode(uint8array);
|
||||
decoder.decode(arrayBuffer);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"text-encoding-utf-8-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user