Add type definitions for buffer-from

This commit is contained in:
Nat Burns
2018-06-16 12:58:41 +00:00
parent 10fe633823
commit 7e57337c6e
4 changed files with 42 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
import bufferFrom = require('buffer-from');
bufferFrom([1, 2, 3, 4]); // $ExpectType Buffer
bufferFrom(new Uint8Array([1, 2, 3, 4]).buffer, 1, 2); // $ExpectType Buffer
bufferFrom('test', 'utf8'); // $ExpectType Buffer
bufferFrom(bufferFrom('test')); // $ExpectType Buffer

12
types/buffer-from/index.d.ts vendored Normal file
View File

@@ -0,0 +1,12 @@
// Type definitions for buffer-from 1.1
// Project: https://github.com/LinusU/buffer-from#readme
// Definitions by: Nat Burns <https://github.com/burnnat>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
declare function bufferFrom(arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number): Buffer;
declare function bufferFrom(str: string, encoding?: string): Buffer;
declare function bufferFrom(data: ReadonlyArray<any> | Buffer): Buffer;
export = bufferFrom;

View File

@@ -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",
"buffer-from-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }