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

This commit is contained in:
Jordi Oliveras Rovira 2019-02-23 01:45:32 +01:00
parent a9b3a2b5a8
commit 3a08ee731e
3 changed files with 12 additions and 1 deletions

View File

@ -2,6 +2,11 @@ declare module "buffer" {
export const INSPECT_MAX_BYTES: number;
const BuffType: typeof Buffer;
export function transcode(
source: Buffer | Uint8Array,
fromEnc: "ascii" | "utf8" | "utf16le" | "ucs2" | "latin1" | "binary",
toEnc: "ascii" | "utf8" | "utf16le" | "ucs2" | "latin1" | "binary"): Buffer;
export const SlowBuffer: {
/** @deprecated since v6.0.0, use Buffer.allocUnsafeSlow() */
new(size: number): Buffer;

View File

@ -33,6 +33,7 @@
// Jeremie Rodriguez <https://github.com/jeremiergz>
// Samuel Ainsworth <https://github.com/samuela>
// Kyle Uehlein <https://github.com/kuehlein>
// Jordi Oliveras Rovira <https://github.com/j-oliveras>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// NOTE: These definitions support NodeJS and TypeScript 3.1.

View File

@ -35,7 +35,7 @@ import * as trace_events from "trace_events";
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 ///
@ -632,6 +632,11 @@ function bufferTests() {
const buffer = new Buffer('123');
const octets = new Uint8Array(buffer.buffer);
}
// Buffer module, transcode function
{
transcode(Buffer.from('€'), 'utf8', 'ascii'); // $ExpectType Buffer
}
}
////////////////////////////////////////////////////