diff --git a/types/node/index.d.ts b/types/node/index.d.ts index 62e0f4c3ee..91801f4fc0 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -23,6 +23,7 @@ // Mohsen Azimi // Hoàng Văn Khải // Alexander T. +// Lishude // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /** inspector module types */ @@ -6225,6 +6226,38 @@ declare module "util" { export function isWeakSet(object: any): object is WeakSet; export function isWebAssemblyCompiledModule(object: any): boolean; } + + export class TextDecoder { + readonly encoding: string; + readonly fatal: boolean; + readonly ignoreBOM: boolean; + constructor( + encoding?: string, + options?: { fatal?: boolean; ignoreBOM?: boolean } + ); + decode( + input?: + Int8Array + | Int16Array + | Int32Array + | Uint8Array + | Uint16Array + | Uint32Array + | Uint8ClampedArray + | Float32Array + | Float64Array + | DataView + | ArrayBuffer + | null, + options?: { stream?: boolean } + ): string; + } + + export class TextEncoder { + readonly encoding: string; + constructor(); + encode(input?: string): Uint8Array; + } } declare module "assert" { diff --git a/types/node/node-tests.ts b/types/node/node-tests.ts index 7c059e23e2..8651d361b7 100644 --- a/types/node/node-tests.ts +++ b/types/node/node-tests.ts @@ -858,6 +858,35 @@ namespace util_tests { // util.isDeepStrictEqual util.isDeepStrictEqual({foo: 'bar'}, {foo: 'bar'}); + + // util.TextDecoder() + var td = new util.TextDecoder(); + new util.TextDecoder("utf-8"); + new util.TextDecoder("utf-8", { fatal: true }); + new util.TextDecoder("utf-8", { fatal: true, ignoreBOM: true }); + var ignoreBom: boolean = td.ignoreBOM; + var fatal: boolean = td.fatal; + var encoding: string = td.encoding; + td.decode(new Int8Array(1)); + td.decode(new Int16Array(1)); + td.decode(new Int32Array(1)); + td.decode(new Uint8Array(1)); + td.decode(new Uint16Array(1)); + td.decode(new Uint32Array(1)); + td.decode(new Uint8ClampedArray(1)); + td.decode(new Float32Array(1)); + td.decode(new Float64Array(1)); + td.decode(new DataView(new Int8Array(1).buffer)); + td.decode(new ArrayBuffer(1)); + td.decode(null); + td.decode(null, { stream: true }); + td.decode(new Int8Array(1), { stream: true }); + var decode: string = td.decode(new Int8Array(1)); + + // util.TextEncoder() + var te = new util.TextEncoder(); + var teEncoding: string = te.encoding; + var teEncodeRes: Uint8Array = te.encode("TextEncoder"); } } diff --git a/types/node/v8/index.d.ts b/types/node/v8/index.d.ts index 45f1c85b64..32530306c2 100644 --- a/types/node/v8/index.d.ts +++ b/types/node/v8/index.d.ts @@ -5588,7 +5588,7 @@ declare module "util" { ); decode( input?: - | Int8Array + Int8Array | Int16Array | Int32Array | Uint8Array diff --git a/types/node/v9/index.d.ts b/types/node/v9/index.d.ts index 5a76e4cc45..e7112daa25 100644 --- a/types/node/v9/index.d.ts +++ b/types/node/v9/index.d.ts @@ -24,6 +24,7 @@ // Mohsen Azimi // Hoàng Văn Khải // Alexander T. +// Lishude // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /** inspector module types */ @@ -5659,6 +5660,38 @@ declare module "util" { export namespace promisify { const custom: symbol; } + + export class TextDecoder { + readonly encoding: string; + readonly fatal: boolean; + readonly ignoreBOM: boolean; + constructor( + encoding?: string, + options?: { fatal?: boolean; ignoreBOM?: boolean } + ); + decode( + input?: + Int8Array + | Int16Array + | Int32Array + | Uint8Array + | Uint16Array + | Uint32Array + | Uint8ClampedArray + | Float32Array + | Float64Array + | DataView + | ArrayBuffer + | null, + options?: { stream?: boolean } + ): string; + } + + export class TextEncoder { + readonly encoding: string; + constructor(); + encode(input?: string): Uint8Array; + } } declare module "assert" { diff --git a/types/node/v9/node-tests.ts b/types/node/v9/node-tests.ts index d6751541b9..b7c7471fe1 100644 --- a/types/node/v9/node-tests.ts +++ b/types/node/v9/node-tests.ts @@ -854,6 +854,35 @@ namespace util_tests { // util.isDeepStrictEqual util.isDeepStrictEqual({foo: 'bar'}, {foo: 'bar'}); + + // util.TextDecoder() + var td = new util.TextDecoder(); + new util.TextDecoder("utf-8"); + new util.TextDecoder("utf-8", { fatal: true }); + new util.TextDecoder("utf-8", { fatal: true, ignoreBOM: true }); + var ignoreBom: boolean = td.ignoreBOM; + var fatal: boolean = td.fatal; + var encoding: string = td.encoding; + td.decode(new Int8Array(1)); + td.decode(new Int16Array(1)); + td.decode(new Int32Array(1)); + td.decode(new Uint8Array(1)); + td.decode(new Uint16Array(1)); + td.decode(new Uint32Array(1)); + td.decode(new Uint8ClampedArray(1)); + td.decode(new Float32Array(1)); + td.decode(new Float64Array(1)); + td.decode(new DataView(new Int8Array(1).buffer)); + td.decode(new ArrayBuffer(1)); + td.decode(null); + td.decode(null, { stream: true }); + td.decode(new Int8Array(1), { stream: true }); + var decode: string = td.decode(new Int8Array(1)); + + // util.TextEncoder() + var te = new util.TextEncoder(); + var teEncoding: string = te.encoding; + var teEncodeRes: Uint8Array = te.encode("TextEncoder"); } }