mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
Merge pull request #25742 from isLishude/node-util-feat
feat(node9&10): add `TextDecoder` and `TextEncoder` for `util` module
This commit is contained in:
33
types/node/index.d.ts
vendored
33
types/node/index.d.ts
vendored
@@ -23,6 +23,7 @@
|
||||
// Mohsen Azimi <https://github.com/mohsen1>
|
||||
// Hoàng Văn Khải <https://github.com/KSXGitHub>
|
||||
// Alexander T. <https://github.com/a-tarasyuk>
|
||||
// Lishude <https://github.com/islishude>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/** inspector module types */
|
||||
@@ -6225,6 +6226,38 @@ declare module "util" {
|
||||
export function isWeakSet(object: any): object is WeakSet<any>;
|
||||
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" {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
types/node/v8/index.d.ts
vendored
2
types/node/v8/index.d.ts
vendored
@@ -5588,7 +5588,7 @@ declare module "util" {
|
||||
);
|
||||
decode(
|
||||
input?:
|
||||
| Int8Array
|
||||
Int8Array
|
||||
| Int16Array
|
||||
| Int32Array
|
||||
| Uint8Array
|
||||
|
||||
33
types/node/v9/index.d.ts
vendored
33
types/node/v9/index.d.ts
vendored
@@ -24,6 +24,7 @@
|
||||
// Mohsen Azimi <https://github.com/mohsen1>
|
||||
// Hoàng Văn Khải <https://github.com/KSXGitHub>
|
||||
// Alexander T. <https://github.com/a-tarasyuk>
|
||||
// Lishude <https://github.com/islishude>
|
||||
// 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" {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user