summaryrefslogtreecommitdiff
path: root/src/utility.js
diff options
context:
space:
mode:
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;