v0.1.0
This commit is contained in:
38
src/utils.ts
Normal file
38
src/utils.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import * as hashes from 'jshashes';
|
||||
|
||||
const hasher = new hashes.MD5();
|
||||
|
||||
const hashCache = new Map<string, string>();
|
||||
|
||||
export async function md5(data: string): Promise<string> {
|
||||
if (!hashCache.has(data)) {
|
||||
const hashHex = hasher.hex(data);
|
||||
hashCache.set(data, hashHex);
|
||||
}
|
||||
return hashCache.get(data)!;
|
||||
}
|
||||
|
||||
export function sleep(ms: number) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
export async function share(text: string) {
|
||||
if (navigator.share) {
|
||||
await navigator.share({
|
||||
text,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function ellipsize(text: string, maxLength: number) {
|
||||
if (text.length > maxLength) {
|
||||
return text.substring(0, maxLength) + '...';
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
export function cloneArrayBuffer(buffer) {
|
||||
const newBuffer = new ArrayBuffer(buffer.byteLength);
|
||||
new Uint8Array(newBuffer).set(new Uint8Array(buffer));
|
||||
return newBuffer;
|
||||
}
|
Reference in New Issue
Block a user