A note-taking app inspired by nb
1import { join } from "@std/path";
2
3function getHomeDir(): string {
4 if (Deno.build.os === "windows") {
5 const home = Deno.env.get("USERPROFILE");
6 if (home == null) throw new Error("%USERPROFILE% missing");
7 return home;
8 } else {
9 const home = Deno.env.get("HOME");
10 if (home == null) throw new Error("$HOME missing");
11 return home;
12 }
13}
14
15export function getDataDir(): string {
16 let base = Deno.env.get("HSH_DATA_DIR");
17 if (base == null) {
18 switch (Deno.build.os) {
19 case "windows":
20 base = Deno.env.get("APPDATA")!;
21 break;
22 case "darwin":
23 // As far as I can tell, unlike Linux and Windows, this is just fixed
24 base = join(getHomeDir(), "Library", "Application Support");
25 break;
26 default:
27 base = Deno.env.get("XDG_DATA_HOME") ??
28 join(getHomeDir(), ".local", "share");
29 }
30 }
31
32 return join(base, "hsh");
33}
34
35export function getConfigDir(): string {
36 let base: string;
37 switch (Deno.build.os) {
38 case "windows":
39 base = Deno.env.get("APPDATA")!;
40 break;
41 default:
42 base = Deno.env.get("XDG_CONFIG_HOME") ??
43 join(getHomeDir(), ".config");
44 }
45
46 return join(base, "hsh");
47}
48
49export function likelyPath(path: string): boolean {
50 return !path.includes(" ") && (path.includes("/") || path.includes(":"));
51}