From 1d784eb72b4fcda4abde5927cb2913dab1c1809f Mon Sep 17 00:00:00 2001 From: Paul Taylor Date: Thu, 7 Dec 2017 15:16:21 -0800 Subject: [PATCH 1/3] add text-encoding-utf-8 --- types/text-encoding-utf-8/index.d.ts | 60 ++++++++++++++ .../text-encoding-utf-8-tests.ts | 52 ++++++++++++ types/text-encoding-utf-8/tsconfig.json | 23 ++++++ types/text-encoding-utf-8/tslint.json | 79 +++++++++++++++++++ 4 files changed, 214 insertions(+) create mode 100644 types/text-encoding-utf-8/index.d.ts create mode 100644 types/text-encoding-utf-8/text-encoding-utf-8-tests.ts create mode 100644 types/text-encoding-utf-8/tsconfig.json create mode 100644 types/text-encoding-utf-8/tslint.json diff --git a/types/text-encoding-utf-8/index.d.ts b/types/text-encoding-utf-8/index.d.ts new file mode 100644 index 0000000000..73aed16d6f --- /dev/null +++ b/types/text-encoding-utf-8/index.d.ts @@ -0,0 +1,60 @@ +// Type definitions for text-encoding-utf-8 +// Project: https://github.com/arv/text-encoding-utf-8 +// Definitions by: Paul Taylor +// 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; +} diff --git a/types/text-encoding-utf-8/text-encoding-utf-8-tests.ts b/types/text-encoding-utf-8/text-encoding-utf-8-tests.ts new file mode 100644 index 0000000000..afa837c65d --- /dev/null +++ b/types/text-encoding-utf-8/text-encoding-utf-8-tests.ts @@ -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); +} diff --git a/types/text-encoding-utf-8/tsconfig.json b/types/text-encoding-utf-8/tsconfig.json new file mode 100644 index 0000000000..f9d410c8c5 --- /dev/null +++ b/types/text-encoding-utf-8/tsconfig.json @@ -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" + ] +} \ No newline at end of file diff --git a/types/text-encoding-utf-8/tslint.json b/types/text-encoding-utf-8/tslint.json new file mode 100644 index 0000000000..a41bf5d19a --- /dev/null +++ b/types/text-encoding-utf-8/tslint.json @@ -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 + } +} From b5a4bb1fb61b5081d48ca99d92969c4b18edffdc Mon Sep 17 00:00:00 2001 From: Paul Taylor Date: Sat, 9 Dec 2017 19:36:51 -0800 Subject: [PATCH 2/3] Update tslint.json --- types/text-encoding-utf-8/tslint.json | 78 +-------------------------- 1 file changed, 1 insertion(+), 77 deletions(-) diff --git a/types/text-encoding-utf-8/tslint.json b/types/text-encoding-utf-8/tslint.json index a41bf5d19a..f93cf8562a 100644 --- a/types/text-encoding-utf-8/tslint.json +++ b/types/text-encoding-utf-8/tslint.json @@ -1,79 +1,3 @@ { - "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 - } + "extends": "dtslint/dt.json" } From 2cad227300f19c2f333a67c5ed6a10cf9d22fc51 Mon Sep 17 00:00:00 2001 From: Paul Taylor Date: Wed, 13 Dec 2017 20:35:40 -0800 Subject: [PATCH 3/3] fix lint --- types/text-encoding-utf-8/index.d.ts | 6 +---- .../text-encoding-utf-8-tests.ts | 24 +++++++++---------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/types/text-encoding-utf-8/index.d.ts b/types/text-encoding-utf-8/index.d.ts index 73aed16d6f..30f3728250 100644 --- a/types/text-encoding-utf-8/index.d.ts +++ b/types/text-encoding-utf-8/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for text-encoding-utf-8 +// Type definitions for text-encoding-utf-8 1.0 // Project: https://github.com/arv/text-encoding-utf-8 // Definitions by: Paul Taylor // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -54,7 +54,3 @@ declare var TextDecoder: TextEncoding.TextDecoderStatic; declare var TextEncoder: TextEncoding.TextEncoderStatic; declare var TextEncoding: TextEncoding.TextEncodingStatic; - -declare module "text-encoding-utf-8" { - export = TextEncoding; -} diff --git a/types/text-encoding-utf-8/text-encoding-utf-8-tests.ts b/types/text-encoding-utf-8/text-encoding-utf-8-tests.ts index afa837c65d..7ebfb04055 100644 --- a/types/text-encoding-utf-8/text-encoding-utf-8-tests.ts +++ b/types/text-encoding-utf-8/text-encoding-utf-8-tests.ts @@ -1,8 +1,6 @@ - - function test_encoder() { - var text = "plain text"; - var uint8array: Uint8Array; + const text = "plain text"; + let uint8array: Uint8Array; // constructor uint8array = new TextEncoder().encode(text); @@ -12,9 +10,9 @@ function test_encoder() { uint8array = TextEncoder('utf-8').encode(text); // attributes - var encoder = new TextEncoder(); + const encoder = new TextEncoder(); encoder.encoding = 'utf-8'; - var encoding: string = encoder.encoding; + const encoding: string = encoder.encoding; // methods encoder.encode(); @@ -22,9 +20,9 @@ function test_encoder() { } function test_decoder() { - var text = "plain text"; - var uint8array: Uint8Array = TextEncoder().encode(text); - var arrayBuffer: ArrayBuffer = uint8array.buffer + let text = "plain text"; + const uint8array: Uint8Array = TextEncoder().encode(text); + const arrayBuffer: ArrayBuffer = uint8array.buffer; // constructor text = new TextDecoder().decode(uint8array); @@ -34,16 +32,16 @@ function test_decoder() { text = TextDecoder('utf-8').decode(uint8array); // attributes - var decoder = new TextDecoder(); + const decoder = new TextDecoder(); decoder.encoding = 'utf-8'; - var encoding: string = decoder.encoding; + const encoding: string = decoder.encoding; decoder.fatal = true; - var fatal: boolean = decoder.fatal; + const fatal: boolean = decoder.fatal; decoder.ignoreBOM = true; - var ignoreBOM: boolean = decoder.ignoreBOM; + const ignoreBOM: boolean = decoder.ignoreBOM; // methods decoder.decode();