streaming, markdown, model selecting, and lots more
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
export const hash = async (text: string) => {
|
||||
const msgBuffer = new TextEncoder().encode(text);
|
||||
|
||||
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
|
||||
|
||||
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
||||
|
||||
return hashHex;
|
||||
}
|
||||
|
||||
export const hashSync = (text: string) => {
|
||||
let hash = 5381;
|
||||
let i = 0;
|
||||
for (const char of text) {
|
||||
hash = ((hash << 5) - hash) + char.charCodeAt(0);
|
||||
hash |= 0;
|
||||
}
|
||||
return hash.toString(16);
|
||||
}
|
||||
Reference in New Issue
Block a user