From 9e7f7e584d8cd3cb2c390e3943398f092910df9c Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Mon, 6 Mar 2023 09:59:17 +0000 Subject: [PATCH] hash string --- static/js/utils.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/static/js/utils.js b/static/js/utils.js index 83e886b..3e3a14e 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -25,3 +25,13 @@ function imgSizeFit(img, maxWidth = 1024, maxHeight = 768) { ) return {width: img.naturalWidth * ratio, height: img.naturalHeight * ratio} } + +async function hash(string) { + const utf8 = new TextEncoder().encode(string) + const hashBuffer = await crypto.subtle.digest('SHA-256', utf8) + const hashArray = Array.from(new Uint8Array(hashBuffer)) + const hashHex = hashArray + .map(bytes => bytes.toString(16).padStart(2, '0')) + .join('') + return hashHex +}