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

18 lines
272 B
JavaScript
Raw Normal View History

"use strict";
2018-10-10 12:56:35 -05:00
// N A T I V E
2018-11-30 14:46:22 -06:00
import crypto from "crypto";
// E X P O R T
2018-11-30 14:46:22 -06:00
export default len => {
if (!Number.isFinite(len)) throw new TypeError("Expected a finite number");
2018-10-06 15:53:01 -05:00
return crypto.randomBytes(Math.ceil(len / 2)).toString("hex")
.slice(0, len);
};