diff --git a/types/random-bytes/index.d.ts b/types/random-bytes/index.d.ts new file mode 100644 index 0000000000..f17893f8b5 --- /dev/null +++ b/types/random-bytes/index.d.ts @@ -0,0 +1,31 @@ +// Type definitions for random-bytes 1.0 +// Project: https://github.com/crypto-utils/random-bytes +// Definitions by: Steve Ripberger +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +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; + + /** + * Synchronously generates strong pseudo-random bytes. + * @param size - Number of bytes to generate. + */ + sync(size: number): Buffer; +} + +declare const randomBytes: RandomBytesStatic; + +export = randomBytes; diff --git a/types/random-bytes/random-bytes-tests.ts b/types/random-bytes/random-bytes-tests.ts new file mode 100644 index 0000000000..ed48f5d853 --- /dev/null +++ b/types/random-bytes/random-bytes-tests.ts @@ -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); diff --git a/types/random-bytes/tsconfig.json b/types/random-bytes/tsconfig.json new file mode 100644 index 0000000000..da7b0df9c2 --- /dev/null +++ b/types/random-bytes/tsconfig.json @@ -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" + ] +} diff --git a/types/random-bytes/tslint.json b/types/random-bytes/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/random-bytes/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }