const hexList: string[] = []; for (let i = 0; i <= 15; i++) { hexList[i] = i.toString(16); } export function buildUUID() { // return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) { // const r = (Math.random() * 16) | 0, // v = c == 'x' ? r : (r & 0x3) | 0x8; // return v.toString(16); // }); let guid = ''; for (let i = 1; i <= 32; i++) { const n = Math.floor(Math.random() * 16.0).toString(16); guid += n; if (i == 8 || i == 12 || i == 16 || i == 20) guid += '-'; } return guid; } // export function buildUUID(): string { // let uuid = ''; // for (let i = 1; i <= 36; i++) { // if (i === 9 || i === 14 || i === 19 || i === 24) { // uuid += '-'; // } else if (i === 15) { // uuid += 4; // } else if (i === 20) { // uuid += hexList[(Math.random() * 4) | 8]; // } else { // uuid += hexList[(Math.random() * 16) | 0]; // } // } // return uuid.replace(/-/g, ''); // } let unique = 0; export function buildShortUUID(prefix = ''): string { const time = Date.now(); const random = Math.floor(Math.random() * 1000000000); unique++; return prefix + '_' + random + unique + String(time); }