Skip to content

Commit

Permalink
Import destructuring
Browse files Browse the repository at this point in the history
Signed-off-by: Richie Bendall <[email protected]>
  • Loading branch information
Richienb committed Apr 21, 2022
1 parent 4f69e0b commit 2db06d0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// TODO: When targeting Node.js 16, use `crypto.webcrypto.getRandomValues` to interop with the browser code and when targeting Node.js 18, only use the browser code
// TODO: When targeting Node.js 16, use `crypto.webcrypto.getRandomValues` to interop with the browser code and when targeting Node.js 18, only use the browser code. Either way,
import {promisify} from 'node:util';
import crypto from 'node:crypto';
import {randomBytes} from 'node:crypto';
import {createStringGenerator, createAsyncStringGenerator} from './core.js';

const randomBytesAsync = promisify(crypto.randomBytes);
const randomBytesAsync = promisify(randomBytes);

export default createStringGenerator((byteLength, type, length) => crypto.randomBytes(byteLength).toString(type).slice(0, length), size => new Uint8Array(crypto.randomBytes(size)));
export default createStringGenerator((byteLength, type, length) => randomBytes(byteLength).toString(type).slice(0, length), size => new Uint8Array(randomBytes(size)));
export const cryptoRandomStringAsync = createAsyncStringGenerator(async (byteLength, type, length) => {
const buffer = await randomBytesAsync(byteLength);
return buffer.toString(type).slice(0, length);
Expand Down

0 comments on commit 2db06d0

Please sign in to comment.