Fix everything

This commit is contained in:
Mohsen Azimi
2018-05-31 00:28:32 -07:00
parent c0b3b89595
commit f9a3f3c2da
2 changed files with 41 additions and 22 deletions
+20 -3
View File
@@ -13,11 +13,28 @@ declare namespace TextEncoding {
(utfLabel?: string, options?: TextEncoderOptions): TextEncoder;
new (utfLabel?: string, options?: TextEncoderOptions): TextEncoder;
}
export const TextEncoder: TextEncoder;
export const TextDecoder: TextDecoder;
export var TextEncoder: {
new (utfLabel?: string, options?: TextEncoderOptions): TextEncoder;
(utfLabel?: string, options?: TextEncoderOptions): TextEncoder;
encoding: string;
};
export var TextDecoder: {
(label?: string, options?: TextDecoderOptions): TextDecoder;
new (label?: string, options?: TextDecoderOptions): TextDecoder;
encoding: string;
};
}
declare var TextEncoding: TextEncoding.TextEncodingStatic;
interface TextEncodeOptions {
stream?: boolean;
}
interface TextEncoder {
readonly encoding: string;
encode(input?: string, options?: TextEncodeOptions): Uint8Array;
}
declare module "text-encoding" {
export = TextEncoding;
+21 -19
View File
@@ -1,21 +1,24 @@
import { TextEncoder, TextDecoder } from "text-encoding";
function test_encoder() {
var text = "plain text";
var uint8array: Uint8Array;
var uint8array = new Uint8Array([]);
// constructor
uint8array = new TextEncoder().encode(text);
uint8array = new TextEncoder('utf-8').encode(text);
uint8array = new TextEncoder('windows-1252', { NONSTANDARD_allowLegacyEncoding: true }).encode(text);
uint8array = new TextEncoder("utf-8").encode(text);
uint8array = new TextEncoder("windows-1252", {
NONSTANDARD_allowLegacyEncoding: true
}).encode(text);
uint8array = TextEncoder().encode(text);
uint8array = TextEncoder('utf-8').encode(text);
uint8array = TextEncoder('windows-1252', { NONSTANDARD_allowLegacyEncoding: true }).encode(text);
uint8array = TextEncoder("utf-8").encode(text);
uint8array = TextEncoder("windows-1252", {
NONSTANDARD_allowLegacyEncoding: true
}).encode(text);
// attributes
var encoder = new TextEncoder();
encoder.encoding = 'utf-8';
var encoding: string = encoder.encoding;
// methods
@@ -27,31 +30,30 @@ function test_encoder() {
function test_decoder() {
var text = "plain text";
var uint8array: Uint8Array = TextEncoder().encode(text);
var arrayBuffer: ArrayBuffer = uint8array.buffer
var arrayBuffer: ArrayBuffer = uint8array.buffer;
// constructor
text = new TextDecoder().decode(uint8array);
text = new TextDecoder('utf-8').decode(uint8array);
text = new TextDecoder('windows-1252', {}).decode(uint8array);
text = new TextDecoder('windows-1252', { fatal: true }).decode(uint8array);
text = new TextDecoder('windows-1252', { ignoreBOM: true }).decode(uint8array);
text = new TextDecoder("utf-8").decode(uint8array);
text = new TextDecoder("windows-1252", {}).decode(uint8array);
text = new TextDecoder("windows-1252", { fatal: true }).decode(uint8array);
text = new TextDecoder("windows-1252", { ignoreBOM: true }).decode(
uint8array
);
text = TextDecoder().decode(uint8array);
text = TextDecoder('utf-8').decode(uint8array);
text = TextDecoder('windows-1252', {}).decode(uint8array);
text = TextDecoder('windows-1252', { fatal: true }).decode(uint8array);
text = TextDecoder('windows-1252', { ignoreBOM: true }).decode(uint8array);
text = TextDecoder("utf-8").decode(uint8array);
text = TextDecoder("windows-1252", {}).decode(uint8array);
text = TextDecoder("windows-1252", { fatal: true }).decode(uint8array);
text = TextDecoder("windows-1252", { ignoreBOM: true }).decode(uint8array);
// attributes
var decoder = new TextDecoder();
decoder.encoding = 'utf-8';
var encoding: string = decoder.encoding;
decoder.fatal = true;
var fatal: boolean = decoder.fatal;
decoder.ignoreBOM = true;
var ignoreBOM: boolean = decoder.ignoreBOM;
// methods