forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/// <reference path="text-encoding.d.ts" /> | ||
|
||
function test_encoder() { | ||
var text = "plain text"; | ||
var uint8array: 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 = TextEncoder().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 | ||
encoder.encode(); | ||
encoder.encode(text); | ||
encoder.encode(text, { stream: true }); | ||
} | ||
|
||
function test_decoder() { | ||
var text = "plain text"; | ||
var uint8array: Uint8Array = TextEncoder().encode(text); | ||
|
||
// 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 = 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); | ||
|
||
// 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 | ||
decoder.decode(); | ||
decoder.decode(uint8array); | ||
decoder.decode(uint8array, { stream: true }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Type definitions for text-encoding | ||
// Project: https://github.com/inexorabletash/text-encoding | ||
// Definitions by: MIZUNE Pine <https://github.com/pine613/> | ||
// Definitions: https://github.com/borisyankov/DefinitelyTyped | ||
|
||
declare module TextEncodingStatic { | ||
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?: ArrayBufferView, options?: TextDecodeOptions): string; | ||
} | ||
|
||
interface TextEncoder { | ||
encoding: string; | ||
encode(input?: string, options?: TextEncodeOptions): Uint8Array; | ||
} | ||
|
||
interface TextEncodeOptions { | ||
stream?: boolean; | ||
} | ||
} | ||
|
||
declare var TextDecoder: { | ||
(label?: string, options?: TextEncodingStatic.TextDecoderOptions): TextEncodingStatic.TextDecoder; | ||
new (label?: string, options?: TextEncodingStatic.TextDecoderOptions): TextEncodingStatic.TextDecoder; | ||
}; | ||
|
||
declare var TextEncoder: { | ||
(utfLabel?: string, options?: TextEncodingStatic.TextEncoderOptions): TextEncodingStatic.TextEncoder; | ||
new (utfLabel?: string, options?: TextEncodingStatic.TextEncoderOptions): TextEncodingStatic.TextEncoder; | ||
}; |