backend v4 half
This commit is contained in:
+55
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GuidGenerator = void 0;
|
||||
const crypto_1 = require("crypto");
|
||||
class GuidGenerator {
|
||||
static generateGuid() {
|
||||
const bytes = (0, crypto_1.randomBytes)(12);
|
||||
const hexString = bytes.toString('hex').toUpperCase();
|
||||
return `${hexString.slice(0, 8)}-${hexString.slice(8, 16)}-${hexString.slice(16, 24)}`;
|
||||
}
|
||||
static generateUuid() {
|
||||
const bytes = (0, crypto_1.randomBytes)(16);
|
||||
const hex = bytes.toString('hex');
|
||||
return [
|
||||
hex.slice(0, 8),
|
||||
hex.slice(8, 12),
|
||||
'4' + hex.slice(13, 16),
|
||||
((parseInt(hex.slice(16, 17), 16) & 0x3) | 0x8).toString(16) + hex.slice(17, 20),
|
||||
hex.slice(20, 32)
|
||||
].join('-');
|
||||
}
|
||||
static isValidGuid(guid) {
|
||||
const guidRegex = /^[A-F0-9]{8}-[A-F0-9]{8}-[A-F0-9]{8}$/;
|
||||
return guidRegex.test(guid);
|
||||
}
|
||||
static isValidUuid(uuid) {
|
||||
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
||||
return uuidRegex.test(uuid);
|
||||
}
|
||||
static generateMultipleGuids(count) {
|
||||
const guids = [];
|
||||
const guidSet = new Set();
|
||||
while (guidSet.size < count) {
|
||||
const guid = this.generateGuid();
|
||||
if (!guidSet.has(guid)) {
|
||||
guidSet.add(guid);
|
||||
guids.push(guid);
|
||||
}
|
||||
}
|
||||
return guids;
|
||||
}
|
||||
static generateMultipleUuids(count) {
|
||||
const uuids = [];
|
||||
const uuidSet = new Set();
|
||||
while (uuidSet.size < count) {
|
||||
const uuid = this.generateUuid();
|
||||
if (!uuidSet.has(uuid)) {
|
||||
uuidSet.add(uuid);
|
||||
uuids.push(uuid);
|
||||
}
|
||||
}
|
||||
return uuids;
|
||||
}
|
||||
}
|
||||
exports.GuidGenerator = GuidGenerator;
|
||||
Reference in New Issue
Block a user