summaryrefslogtreecommitdiff
path: root/src/utility.js
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-09-15 10:10:29 +0800
committerEltrac <hi@guhub.cn>2025-09-15 10:10:29 +0800
commit4cb9d21fb8860d3401db5d94d30c309385599a2e (patch)
tree08bd2cb39bc2602fec302c78f3990edfd11a93b1 /src/utility.js
initial commit
Diffstat (limited to 'src/utility.js')
-rw-r--r--src/utility.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/utility.js b/src/utility.js
new file mode 100644
index 0000000..790443d
--- /dev/null
+++ b/src/utility.js
@@ -0,0 +1,12 @@
+const utility = {
+ generateUniqueId: (str) => {
+ const encoder = new TextEncoder();
+ const data = encoder.encode(str);
+ const hashBuffer = crypto.subtle.digest('SHA-256', data); // SHA-256 hash
+ const hashArray = Array.from(new Uint8Array(hashBuffer)); // Convert buffer to array
+ const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
+ return hashHex; // Return the hex string
+ }
+}
+
+export default utility;