@willphan1712000/frontend 1.7.2 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -540,9 +540,20 @@ declare function handleAsync<DataType>(data: Promise<DataType>): Promise<HandleA
540
540
  */
541
541
  declare function textProcessing(text: string): string;
542
542
 
543
+ /**
544
+ * Function creates and returns a unique UUID and store it in local storage
545
+ * @params key name
546
+ * @returns UUID
547
+ *
548
+ * @example
549
+ * const deviceId = getOrCreateUUID("deviceId")
550
+ */
551
+ declare function getOrCreateUUID(key: string): string;
552
+
543
553
  declare const tools: {
544
554
  handleAsync: typeof handleAsync;
545
555
  textProcessing: typeof textProcessing;
556
+ getOrCreateUUID: typeof getOrCreateUUID;
546
557
  };
547
558
 
548
559
  /**
package/dist/index.d.ts CHANGED
@@ -540,9 +540,20 @@ declare function handleAsync<DataType>(data: Promise<DataType>): Promise<HandleA
540
540
  */
541
541
  declare function textProcessing(text: string): string;
542
542
 
543
+ /**
544
+ * Function creates and returns a unique UUID and store it in local storage
545
+ * @params key name
546
+ * @returns UUID
547
+ *
548
+ * @example
549
+ * const deviceId = getOrCreateUUID("deviceId")
550
+ */
551
+ declare function getOrCreateUUID(key: string): string;
552
+
543
553
  declare const tools: {
544
554
  handleAsync: typeof handleAsync;
545
555
  textProcessing: typeof textProcessing;
556
+ getOrCreateUUID: typeof getOrCreateUUID;
546
557
  };
547
558
 
548
559
  /**
package/dist/index.js CHANGED
@@ -3531,10 +3531,26 @@ function textProcessing(text) {
3531
3531
  return newWords.join(" ");
3532
3532
  }
3533
3533
 
3534
+ // src/utilities/tools/UUID.ts
3535
+ function getOrCreateUUID(key) {
3536
+ const STORAGE_KEY = key;
3537
+ let deviceId = localStorage.getItem(STORAGE_KEY);
3538
+ if (!deviceId) {
3539
+ if (window.crypto && window.crypto.randomUUID) {
3540
+ deviceId = window.crypto.randomUUID();
3541
+ } else {
3542
+ deviceId = "id-" + Math.random().toString(36).substring(2, 15) + Date.now().toString(36);
3543
+ }
3544
+ localStorage.setItem(STORAGE_KEY, deviceId);
3545
+ }
3546
+ return deviceId;
3547
+ }
3548
+
3534
3549
  // src/utilities/tools/tools.ts
3535
3550
  var tools = {
3536
3551
  handleAsync: handleAsync_default,
3537
- textProcessing
3552
+ textProcessing,
3553
+ getOrCreateUUID
3538
3554
  };
3539
3555
  var tools_default = tools;
3540
3556
 
package/dist/index.mjs CHANGED
@@ -3492,10 +3492,26 @@ function textProcessing(text) {
3492
3492
  return newWords.join(" ");
3493
3493
  }
3494
3494
 
3495
+ // src/utilities/tools/UUID.ts
3496
+ function getOrCreateUUID(key) {
3497
+ const STORAGE_KEY = key;
3498
+ let deviceId = localStorage.getItem(STORAGE_KEY);
3499
+ if (!deviceId) {
3500
+ if (window.crypto && window.crypto.randomUUID) {
3501
+ deviceId = window.crypto.randomUUID();
3502
+ } else {
3503
+ deviceId = "id-" + Math.random().toString(36).substring(2, 15) + Date.now().toString(36);
3504
+ }
3505
+ localStorage.setItem(STORAGE_KEY, deviceId);
3506
+ }
3507
+ return deviceId;
3508
+ }
3509
+
3495
3510
  // src/utilities/tools/tools.ts
3496
3511
  var tools = {
3497
3512
  handleAsync: handleAsync_default,
3498
- textProcessing
3513
+ textProcessing,
3514
+ getOrCreateUUID
3499
3515
  };
3500
3516
  var tools_default = tools;
3501
3517
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willphan1712000/frontend",
3
- "version": "1.7.2",
3
+ "version": "1.8.0",
4
4
  "description": "Frontend Library",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",