mirror of
https://github.com/Warky-Devs/artemis-kit.git
synced 2026-02-01 23:44:27 +00:00
Added newUUID, getUUID
This commit is contained in:
15
src/index.ts
15
src/index.ts
@@ -1,8 +1,7 @@
|
||||
|
||||
export * from './base64'
|
||||
export * from './strings'
|
||||
export * from './mime'
|
||||
export * from './promise'
|
||||
export * from './i18n'
|
||||
export * from './dataqueue'
|
||||
//export * from './logger'
|
||||
export * from "./base64";
|
||||
export * from "./strings";
|
||||
export * from "./mime";
|
||||
export * from "./promise";
|
||||
export * from "./i18n";
|
||||
export * from "./dataqueue";
|
||||
//export * from './logger'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export * from './trim'
|
||||
export * from './replace'
|
||||
export * from './caseConversion'
|
||||
export * from './locale'
|
||||
export * from './fileSize'
|
||||
export * from './legacy'
|
||||
export * from "./trim";
|
||||
export * from "./replace";
|
||||
export * from "./caseConversion";
|
||||
export * from "./locale";
|
||||
export * from "./fileSize";
|
||||
export * from "./legacy";
|
||||
export * from "./uuid";
|
||||
|
||||
28
src/strings/uuid.ts
Normal file
28
src/strings/uuid.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
/**
|
||||
* Generates a UUID (Universally Unique Identifier) using the crypto.randomUUID() method if available,
|
||||
* or creates a fallback UUID using the current timestamp and random numbers.
|
||||
*
|
||||
* @returns {string} Returns a UUID string.
|
||||
*/
|
||||
export function getUUID(): string {
|
||||
let uuid = "";
|
||||
try {
|
||||
uuid = crypto.randomUUID();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
} catch (e) {
|
||||
const d = new Date();
|
||||
const rnd = Math.random() * 100 * (Math.random() * 10);
|
||||
uuid = `${d.getTime()}${rnd}`;
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random UUID using the uuidv4 library.
|
||||
*
|
||||
* @returns {string} Returns a UUID string.
|
||||
*/
|
||||
export function newUUID(): string {
|
||||
return uuidv4();
|
||||
}
|
||||
Reference in New Issue
Block a user