lbry.tech/app/helpers/random-string.js

18 lines
289 B
JavaScript
Raw Normal View History

"use strict";
2018-10-10 19:56:35 +02:00
// N A T I V E
const crypto = require("crypto");
// E X P O R T
module.exports = exports = len => {
if (!Number.isFinite(len)) throw new TypeError("Expected a finite number");
2018-10-06 22:53:01 +02:00
return crypto.randomBytes(Math.ceil(len / 2)).toString("hex")
.slice(0, len);
};