mirror of
https://github.com/Warky-Devs/artemis-kit.git
synced 2025-07-03 22:07:32 +00:00
Added newUUID, getUUID
This commit is contained in:
parent
f0be5d3028
commit
04fb164c8d
@ -39,7 +39,8 @@
|
|||||||
"author": "Hein (Warkanum) Puth",
|
"author": "Hein (Warkanum) Puth",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"semver": "^7.6.3"
|
"semver": "^7.6.3",
|
||||||
|
"uuid": "^11.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@changesets/cli": "^2.27.10",
|
"@changesets/cli": "^2.27.10",
|
||||||
|
@ -11,6 +11,9 @@ importers:
|
|||||||
semver:
|
semver:
|
||||||
specifier: ^7.6.3
|
specifier: ^7.6.3
|
||||||
version: 7.6.3
|
version: 7.6.3
|
||||||
|
uuid:
|
||||||
|
specifier: ^11.0.3
|
||||||
|
version: 11.0.3
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@changesets/cli':
|
'@changesets/cli':
|
||||||
specifier: ^2.27.10
|
specifier: ^2.27.10
|
||||||
@ -1637,6 +1640,10 @@ packages:
|
|||||||
uri-js@4.4.1:
|
uri-js@4.4.1:
|
||||||
resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==}
|
resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==}
|
||||||
|
|
||||||
|
uuid@11.0.3:
|
||||||
|
resolution: {integrity: sha512-d0z310fCWv5dJwnX1Y/MncBAqGMKEzlBb1AOf7z9K8ALnd0utBX/msg/fA0+sbyN1ihbMsLhrBlnl1ak7Wa0rg==}
|
||||||
|
hasBin: true
|
||||||
|
|
||||||
vite-node@2.1.8:
|
vite-node@2.1.8:
|
||||||
resolution: {integrity: sha512-uPAwSr57kYjAUux+8E2j0q0Fxpn8M9VoyfGiRI8Kfktz9NcYMCenwY5RnZxnF1WTu3TGiYipirIzacLL3VVGFg==}
|
resolution: {integrity: sha512-uPAwSr57kYjAUux+8E2j0q0Fxpn8M9VoyfGiRI8Kfktz9NcYMCenwY5RnZxnF1WTu3TGiYipirIzacLL3VVGFg==}
|
||||||
engines: {node: ^18.0.0 || >=20.0.0}
|
engines: {node: ^18.0.0 || >=20.0.0}
|
||||||
@ -3368,6 +3375,8 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
punycode: 2.3.1
|
punycode: 2.3.1
|
||||||
|
|
||||||
|
uuid@11.0.3: {}
|
||||||
|
|
||||||
vite-node@2.1.8:
|
vite-node@2.1.8:
|
||||||
dependencies:
|
dependencies:
|
||||||
cac: 6.7.14
|
cac: 6.7.14
|
||||||
|
15
src/index.ts
15
src/index.ts
@ -1,8 +1,7 @@
|
|||||||
|
export * from "./base64";
|
||||||
export * from './base64'
|
export * from "./strings";
|
||||||
export * from './strings'
|
export * from "./mime";
|
||||||
export * from './mime'
|
export * from "./promise";
|
||||||
export * from './promise'
|
export * from "./i18n";
|
||||||
export * from './i18n'
|
export * from "./dataqueue";
|
||||||
export * from './dataqueue'
|
//export * from './logger'
|
||||||
//export * from './logger'
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
export * from './trim'
|
export * from "./trim";
|
||||||
export * from './replace'
|
export * from "./replace";
|
||||||
export * from './caseConversion'
|
export * from "./caseConversion";
|
||||||
export * from './locale'
|
export * from "./locale";
|
||||||
export * from './fileSize'
|
export * from "./fileSize";
|
||||||
export * from './legacy'
|
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();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user