add text-encoding-utf-8

This commit is contained in:
Paul Taylor
2017-12-07 15:24:25 -08:00
parent 85c17c4f49
commit 1d784eb72b
4 changed files with 214 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
// Type definitions for text-encoding-utf-8
// 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;
declare module "text-encoding-utf-8" {
export = TextEncoding;
}
@@ -0,0 +1,52 @@
function test_encoder() {
var text = "plain text";
var 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
var encoder = new TextEncoder();
encoder.encoding = 'utf-8';
var encoding: string = encoder.encoding;
// methods
encoder.encode();
encoder.encode(text);
}
function test_decoder() {
var text = "plain text";
var uint8array: Uint8Array = TextEncoder().encode(text);
var 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
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(arrayBuffer);
}
+23
View File
@@ -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"
]
}
+79
View File
@@ -0,0 +1,79 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": false,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": false,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
}
}