Files
async-programming-promises/node_modules/nanoid/random.js
2019-10-23 07:41:03 -05:00

16 lines
359 B
JavaScript

var crypto = require('crypto')
if (crypto.randomFillSync) {
var buffers = { }
module.exports = function (bytes) {
var buffer = buffers[bytes]
if (!buffer) {
buffer = Buffer.allocUnsafe(bytes)
if (bytes <= 255) buffers[bytes] = buffer
}
return crypto.randomFillSync(buffer)
}
} else {
module.exports = crypto.randomBytes
}