From 476c0ed672381a9cb414f85bf44185e4dc8b990e Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Thu, 12 Dec 2024 22:18:09 +0000 Subject: [PATCH] Add hash --- plugin/src/utils.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 plugin/src/utils.ts diff --git a/plugin/src/utils.ts b/plugin/src/utils.ts new file mode 100644 index 0000000..a9a44cb --- /dev/null +++ b/plugin/src/utils.ts @@ -0,0 +1,9 @@ +// https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript +export function hash(content: Uint8Array): string { + let hash = 0; + for (let i = 0; i < content.length; i++) { + hash = (hash << 5) - hash + content[i]; + hash |= 0; // convert to 32bit integer + } + return hash.toString(64); +}