anyid
Version:
A simple and flexible API to generate various kinds of string ID / code.
32 lines • 1.05 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const assert_1 = __importDefault(require("assert"));
const crypto = __importStar(require("crypto"));
const core_1 = require("./core");
class RandomValue extends core_1.Value {
constructor(owner) {
super(owner);
}
value() {
assert_1.default(this.bits, 'Length or bits must be set for random');
return crypto.randomBytes(Math.ceil(this.bits / 8));
}
}
class Random {
random() {
this.addValue(new RandomValue(this));
return this;
}
}
exports.Random = Random;
//# sourceMappingURL=random.js.map