toastflow-core 1.1.2 → 1.1.3

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/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "url": "https://github.com/adrianjanocko/toastflow.git",
9
9
  "directory": "packages/core"
10
10
  },
11
- "version": "1.1.2",
11
+ "version": "1.1.3",
12
12
  "main": "src/index.ts",
13
13
  "module": "src/index.ts",
14
14
  "types": "src/index.ts",
@@ -21,8 +21,5 @@
21
21
  "tsup": "^8.5.1",
22
22
  "typescript": "^5.9.3",
23
23
  "vitest": "^4.0.13"
24
- },
25
- "dependencies": {
26
- "uuid": "^13.0.0"
27
24
  }
28
25
  }
package/src/store.ts CHANGED
@@ -15,8 +15,7 @@ import type {
15
15
  ToastType,
16
16
  ToastUpdateInput,
17
17
  } from "./types";
18
- import { isNumberFinite } from "./util";
19
- import { v4 as uuidv4 } from "uuid";
18
+ import { generateUuid, isNumberFinite } from "./util";
20
19
 
21
20
  type Listener = (state: ToastState) => void;
22
21
  type EventListener = (event: ToastEvent) => void;
@@ -156,7 +155,7 @@ export function createToastStore(
156
155
  }
157
156
  }
158
157
 
159
- const id = uuidv4();
158
+ const id = generateUuid();
160
159
  const createdAt = Date.now();
161
160
 
162
161
  const toastInstance: ToastInstance = {
package/src/util.ts CHANGED
@@ -1,3 +1,28 @@
1
+ /**
2
+ * Generate a UUID v4 using `crypto.randomUUID` when available; otherwise fall back
3
+ * to the classic template with random nibbles (uses `crypto.getRandomValues` when possible).
4
+ */
5
+ export function generateUuid(): string {
6
+ const cryptoSource: Crypto | undefined =
7
+ typeof crypto !== "undefined" ? (crypto as Crypto) : undefined;
8
+
9
+ if (typeof cryptoSource?.randomUUID === "function") {
10
+ try {
11
+ return cryptoSource.randomUUID();
12
+ } catch {
13
+ // ignore and use fallback
14
+ }
15
+ }
16
+
17
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
18
+ const rand = cryptoSource?.getRandomValues
19
+ ? cryptoSource.getRandomValues(new Uint8Array(1))[0] & 0xf
20
+ : Math.floor(Math.random() * 16);
21
+ const value = c === "x" ? rand : (rand & 0x3) | 0x8;
22
+ return value.toString(16);
23
+ });
24
+ }
25
+
1
26
  /**
2
27
  * Check if a value is a finite number greater than zero.
3
28
  */