mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add types for random-bytes (#37599)
This commit is contained in:
parent
c14ed38e51
commit
174e62ee37
31
types/random-bytes/index.d.ts
vendored
Normal file
31
types/random-bytes/index.d.ts
vendored
Normal 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;
|
||||
20
types/random-bytes/random-bytes-tests.ts
Normal file
20
types/random-bytes/random-bytes-tests.ts
Normal 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);
|
||||
23
types/random-bytes/tsconfig.json
Normal file
23
types/random-bytes/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/random-bytes/tslint.json
Normal file
1
types/random-bytes/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user