-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
32 lines (27 loc) · 1.06 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const getBase64 = (file: File): Promise<string> => {
return new Promise((resolve) => {
let reader = new FileReader();
// Convert the file to base64 text
reader.readAsDataURL(file);
reader.onload = () => {
const baseURL = reader.result as string;
resolve(baseURL);
};
});
};
const isValidTaprootAddress = (address: string): boolean => {
// Regular expression for Taproot addresses (testnet)
const taprootAddressRegex: RegExp = /^(tb)(0([a-zA-HJ-NP-Z0-9]{39}|[a-zA-HJ-NP-Z0-9]{59})|1[a-zA-HJ-NP-Z0-9]{8,89})$/;
return taprootAddressRegex.test(address);
};
const getFromLocalStorage = (value: string): string | null => {
const item = localStorage.getItem(value);
return item;
}
const addToLocalStorage = (name: string, value: string): void => {
localStorage.setItem(name, value);
}
const removeFromLocalStorage = (value: string): void => {
localStorage.removeItem(value);
}
export { getBase64, isValidTaprootAddress, getFromLocalStorage, addToLocalStorage, removeFromLocalStorage };