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
253B

  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. };