index.js 253 B

12345678910
  1. 'use strict';
  2. const crypto = require('crypto');
  3. module.exports = length => {
  4. if (!Number.isFinite(length)) {
  5. throw new TypeError('Expected a finite number');
  6. }
  7. return crypto.randomBytes(Math.ceil(length / 2)).toString('hex').slice(0, length);
  8. };