generated from justjavac/deno_starter
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mod.ts
34 lines (30 loc) · 1.13 KB
/
mod.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
/** Returns the path to the user's cache directory.
*
* The returned value depends on the operating system and is either a string,
* containing a value from the following table, or `null`.
*
* |Platform | Value | Example |
* | ------- | ----------------------------------- | -------------------------------- |
* | Linux | `$XDG_CACHE_HOME` or `$HOME`/.cache | /home/justjavac/.cache |
* | macOS | `$HOME`/Library/Caches | /Users/justjavac/Library/Caches |
* | Windows | `{FOLDERID_LocalAppData}` | C:\Users\justjavac\AppData\Local |
*/
export default function cache_dir(): string | null {
switch (Deno.build.os) {
case "linux": {
const xdg = Deno.env.get("XDG_CACHE_HOME");
if (xdg) return xdg;
const home = Deno.env.get("HOME");
if (home) return `${home}/.cache`;
break;
}
case "darwin": {
const home = Deno.env.get("HOME");
if (home) return `${home}/Library/Caches`;
break;
}
case "windows":
return Deno.env.get("FOLDERID_LocalAppData") ?? null;
}
return null;
}