index.js 241 B

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