2018-08-11 00:29:06 +02:00
|
|
|
"use strict";
|
|
|
|
|
2018-08-14 22:15:27 +02:00
|
|
|
|
|
|
|
|
2018-10-10 19:56:35 +02:00
|
|
|
// N A T I V E
|
2018-08-14 22:15:27 +02:00
|
|
|
|
2018-11-30 21:46:22 +01:00
|
|
|
import crypto from "crypto";
|
2018-08-11 00:29:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-08-14 22:15:27 +02:00
|
|
|
// E X P O R T
|
|
|
|
|
2018-11-30 21:46:22 +01:00
|
|
|
export default len => {
|
2018-08-11 00:29:06 +02:00
|
|
|
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);
|
2018-08-11 00:29:06 +02:00
|
|
|
};
|