forked from SamSamskies/nostrstuff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurls.ts
42 lines (36 loc) · 848 Bytes
/
urls.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
33
34
35
36
37
38
39
40
41
42
import { encodeNpub } from "@/utils/nostr";
export const makeSnortUrl = (prefix: "npub" | "note", hexId: string) => {
const baseUrl = "https://snort.social";
try {
switch (prefix) {
case "npub":
return `${baseUrl}/p/${encodeNpub(hexId)}`;
case "note":
return `${baseUrl}/e/${encodeNpub(hexId)}`;
default:
return null;
}
} catch {
return null;
}
};
export const isValidUrl = (url: string = "") => {
try {
new URL(url);
return true;
} catch (error) {
return false;
}
};
export const makeUrlWithParams = (
url: string,
params: Record<string, string>
) => {
const urlObj = new URL(url);
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined) {
urlObj.searchParams.append(key, value);
}
});
return urlObj.toString();
};