You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

11 lines
253 B

2 years ago
'use strict';
const crypto = require('crypto');
module.exports = length => {
if (!Number.isFinite(length)) {
throw new TypeError('Expected a finite number');
}
return crypto.randomBytes(Math.ceil(length / 2)).toString('hex').slice(0, length);
};