Add types for random-bytes (#37599)

This commit is contained in:
sripberger 2019-08-13 15:47:01 -04:00 committed by Pranav Senthilnathan
parent c14ed38e51
commit 174e62ee37
4 changed files with 75 additions and 0 deletions

31
types/random-bytes/index.d.ts vendored Normal file
View File

@ -0,0 +1,31 @@
// Type definitions for random-bytes 1.0
// Project: https://github.com/crypto-utils/random-bytes
// Definitions by: Steve Ripberger <https://github.com/me>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
interface RandomBytesStatic {
/**
* Generates strong pseudo-random bytes.
* @param size - Number of bytes to generate.
* @param callback - Asynchronous callback function.
*/
(size: number, callback: (error: Error, bytes: Buffer) => void): void;
/**
* Generates strong pseudo-random bytes.
* @param size - Number of bytes to generate.
*/
(size: number): Promise<Buffer>;
/**
* Synchronously generates strong pseudo-random bytes.
* @param size - Number of bytes to generate.
*/
sync(size: number): Buffer;
}
declare const randomBytes: RandomBytesStatic;
export = randomBytes;

View File

@ -0,0 +1,20 @@
import randomBytes = require('random-bytes');
// Callback-based signature.
randomBytes(16, (err, buff) => {
if (err) {
console.error(err);
} else {
console.log(buff);
}
});
// Promise-based signature.
randomBytes(32)
.then((buff) => {
console.log(buff);
});
// Synchronous signature.
const buff = randomBytes.sync(64);
console.log(buff);

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"random-bytes-tests.ts"
]
}

View File

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