@types/node (v8): add transcode function to buffer module.

This commit is contained in:
Jordi Oliveras Rovira
2019-02-23 01:44:50 +01:00
parent 83ab12ea97
commit c1875f5bce
2 changed files with 13 additions and 1 deletions
+7
View File
@@ -22,6 +22,7 @@
// Hoàng Văn Khải <https://github.com/KSXGitHub>
// Lishude <https://github.com/islishude>
// Andrew Makarov <https://github.com/r3nya>
// Jordi Oliveras Rovira <https://github.com/j-oliveras>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
@@ -909,6 +910,12 @@ declare module "buffer" {
export var INSPECT_MAX_BYTES: number;
var BuffType: typeof Buffer;
var SlowBuffType: typeof SlowBuffer;
export function transcode(
source: Buffer | Uint8Array,
fromEnc: "ascii" | "utf8" | "utf16le" | "ucs2" | "latin1" | "binary",
toEnc: "ascii" | "utf8" | "utf16le" | "ucs2" | "latin1" | "binary"): Buffer;
export { BuffType as Buffer, SlowBuffType as SlowBuffer };
}
+6 -1
View File
@@ -33,7 +33,7 @@ import * as perf_hooks from "perf_hooks";
import Module = require("module");
// Specifically test buffer module regression.
import { Buffer as ImportedBuffer, SlowBuffer as ImportedSlowBuffer } from "buffer";
import { Buffer as ImportedBuffer, SlowBuffer as ImportedSlowBuffer, transcode } from "buffer";
//////////////////////////////////////////////////////////
/// Global Tests : https://nodejs.org/api/global.html ///
@@ -568,6 +568,11 @@ function bufferTests() {
let buffer = new Buffer('123');
let octets = new Uint8Array(buffer.buffer);
}
// Buffer module, transcode function
{
transcode(Buffer.from('€'), 'utf8', 'ascii'); // $ExpectType Buffer
}
}
////////////////////////////////////////////////////