From 4cb9d21fb8860d3401db5d94d30c309385599a2e Mon Sep 17 00:00:00 2001 From: Eltrac Date: Mon, 15 Sep 2025 10:10:29 +0800 Subject: initial commit --- src/utility.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/utility.js (limited to 'src/utility.js') 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; -- cgit v1.2.3