platformdirs 4.3.6-rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +170 -0
- package/dist/android.d.ts +81 -0
- package/dist/android.js +142 -0
- package/dist/api.d.ts +232 -0
- package/dist/api.js +250 -0
- package/dist/index.d.ts +238 -0
- package/dist/index.js +322 -0
- package/dist/macos.d.ts +97 -0
- package/dist/macos.js +155 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +41 -0
- package/dist/unix.d.ts +121 -0
- package/dist/unix.js +277 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +24 -0
- package/dist/windows.d.ts +83 -0
- package/dist/windows.js +226 -0
- package/package.json +53 -0
package/dist/windows.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Windows.
|
|
4
|
+
*/
|
|
5
|
+
import * as path from "node:path";
|
|
6
|
+
import process from "node:process";
|
|
7
|
+
import { PlatformDirsABC } from "./api.js";
|
|
8
|
+
/**
|
|
9
|
+
* [MSDN on where to store app data
|
|
10
|
+
* files](https://learn.microsoft.com/en-us/windows/win32/shell/knownfolderid)
|
|
11
|
+
*
|
|
12
|
+
* Makes use of the {@link PlatformDirsABC.appname},
|
|
13
|
+
* {@link PlatformDirsABC.appauthor}, {@link PlatformDirsABC.version},
|
|
14
|
+
* {@link PlatformDirsABC.roaming}, {@link PlatformDirsABC.opinion},
|
|
15
|
+
* {@link PlatformDirsABC.ensureExists}.
|
|
16
|
+
*/
|
|
17
|
+
export class Windows extends PlatformDirsABC {
|
|
18
|
+
/**
|
|
19
|
+
* @return data directory tied to the user, e.g. `%USERPROFILE%\AppData\Local\$appauthor\$appname` (not roaming) or `%USERPROFILE%\AppData\Roaming\$appauthor\$appname` (roaming)
|
|
20
|
+
*/
|
|
21
|
+
get userDataDir() {
|
|
22
|
+
const const2 = this.roaming ? "CSIDL_APPDATA" : "CSIDL_LOCAL_APPDATA";
|
|
23
|
+
const path2 = path.normalize(getWinFolder(const2));
|
|
24
|
+
return this._appendParts(path2);
|
|
25
|
+
}
|
|
26
|
+
_appendParts(path2, { opinionValue } = {}) {
|
|
27
|
+
const params = [];
|
|
28
|
+
if (this.appname) {
|
|
29
|
+
if (this.appauthor !== false) {
|
|
30
|
+
const author = this.appauthor || this.appname;
|
|
31
|
+
params.push(author);
|
|
32
|
+
}
|
|
33
|
+
params.push(this.appname);
|
|
34
|
+
if (opinionValue !== undefined && this.opinion) {
|
|
35
|
+
params.push(opinionValue);
|
|
36
|
+
}
|
|
37
|
+
if (this.version) {
|
|
38
|
+
params.push(this.version);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const path3 = path.join(path2, ...params);
|
|
42
|
+
this._optionallyCreateDirectory(path3);
|
|
43
|
+
return path3;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @return data directory shared by users, e.g. `C:\ProgramData\$appauthor\$appname`
|
|
47
|
+
*/
|
|
48
|
+
get siteDataDir() {
|
|
49
|
+
const path2 = path.normalize(getWinFolder("CSIDL_COMMON_APPDATA"));
|
|
50
|
+
return this._appendParts(path2);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @return config directory tied to the user, same as `userDataDir`
|
|
54
|
+
*/
|
|
55
|
+
get userConfigDir() {
|
|
56
|
+
return this.userDataDir;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @return config directory shared by users, same as `siteDataDir`
|
|
60
|
+
*/
|
|
61
|
+
get siteConfigDir() {
|
|
62
|
+
return this.siteDataDir;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @return cache directory tied to the user (if opinionated with `Cache` folder within `$appname`) e.g. `%USERPROFILE%\AppData\Local\$appauthor\$appname\Cache\$version`
|
|
66
|
+
*/
|
|
67
|
+
get userCacheDir() {
|
|
68
|
+
const path2 = path.normalize(getWinFolder("CSIDL_LOCAL_APPDATA"));
|
|
69
|
+
return this._appendParts(path2, { opinionValue: "Cache" });
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @return cache directory shared by users, e.g. `C:\ProgramData\$appauthor\$appname\Cache\$version`
|
|
73
|
+
*/
|
|
74
|
+
get siteCacheDir() {
|
|
75
|
+
const path2 = path.normalize(getWinFolder("CSIDL_COMMON_APPDATA"));
|
|
76
|
+
return this._appendParts(path2, { opinionValue: "Cache" });
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @return state directory tied to the user, same as `userDataDir`
|
|
80
|
+
*/
|
|
81
|
+
get userStateDir() {
|
|
82
|
+
return this.userDataDir;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @return log directory tied to the user, same as `userCacheDir` if not opinionated else `log` in it
|
|
86
|
+
*/
|
|
87
|
+
get userLogDir() {
|
|
88
|
+
let path2 = this.userDataDir;
|
|
89
|
+
if (this.opinion) {
|
|
90
|
+
path2 = path.join(path2, "Logs");
|
|
91
|
+
this._optionallyCreateDirectory(path2);
|
|
92
|
+
}
|
|
93
|
+
return path2;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @return documents directory tied to the user, e.g. `%USERPROFILE%\Documents`
|
|
97
|
+
*/
|
|
98
|
+
get userDocumentsDir() {
|
|
99
|
+
return path.normalize(getWinFolder("CSIDL_PERSONAL"));
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @return downloads directory tied to the user, e.g. `%USERPROFILE%\Downloads`
|
|
103
|
+
*/
|
|
104
|
+
get userDownloadsDir() {
|
|
105
|
+
return path.normalize(getWinFolder("CSIDL_DOWNLOADS"));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @return pictures directory tied to the user, e.g. `%USERPROFILE%\Pictures`
|
|
109
|
+
*/
|
|
110
|
+
get userPicturesDir() {
|
|
111
|
+
return path.normalize(getWinFolder("CSIDL_MYPICTURES"));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* @return videos directory tied to the user, e.g. `%USERPROFILE%\Videos`
|
|
115
|
+
*/
|
|
116
|
+
get userVideosDir() {
|
|
117
|
+
return path.normalize(getWinFolder("CSIDL_MYVIDEO"));
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* @return music directory tied to the user, e.g. `%USERPROFILE%\Music`
|
|
121
|
+
*/
|
|
122
|
+
get userMusicDir() {
|
|
123
|
+
return path.normalize(getWinFolder("CSIDL_MYMUSIC"));
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* @return desktop directory tied to the user, e.g. `%USERPROFILE%\Desktop`
|
|
127
|
+
*/
|
|
128
|
+
get userDesktopDir() {
|
|
129
|
+
return path.normalize(getWinFolder("CSIDL_DESKTOPDIRECTORY"));
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* @return runtime directory tied to the user, e.g. `%USERPROFILE%\AppData\Local\Temp\$appauthor\$appname`
|
|
133
|
+
*/
|
|
134
|
+
get userRuntimeDir() {
|
|
135
|
+
const path2 = path.normalize(path.join(getWinFolder("CSIDL_LOCAL_APPDATA"), "Temp"));
|
|
136
|
+
return this._appendParts(path2);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* @return runtime directory shared by users, same as `userRuntimeDir`
|
|
140
|
+
*/
|
|
141
|
+
get siteRuntimeDir() {
|
|
142
|
+
return this.userRuntimeDir;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get folder from environment variable
|
|
147
|
+
*/
|
|
148
|
+
function getWinFolderFromEnvVars(csidlName) {
|
|
149
|
+
let result = getWinFolderIfCSIDLNameNotEnvVar(csidlName);
|
|
150
|
+
if (result !== undefined) {
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
if (csidlName === "CSIDL_APPDATA") {
|
|
154
|
+
result = process.env.APPDATA;
|
|
155
|
+
if (result === undefined) {
|
|
156
|
+
throw new Error("Unset environment variable: APPDATA");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else if (csidlName === "CSIDL_COMMON_APPDATA") {
|
|
160
|
+
result = process.env.ALLUSERSPROFILE;
|
|
161
|
+
if (result === undefined) {
|
|
162
|
+
throw new Error("Unset environment variable: ALLUSERSPROFILE");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else if (csidlName === "CSIDL_LOCAL_APPDATA") {
|
|
166
|
+
result = process.env.LOCALAPPDATA;
|
|
167
|
+
if (result === undefined) {
|
|
168
|
+
throw new Error("Unset environment variable: LOCALAPPDATA");
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
throw new Error(`Unknown CSIDL name: ${csidlName}`);
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Get a folder for a CSIDL name that does not exist as an environment variable.
|
|
178
|
+
*/
|
|
179
|
+
function getWinFolderIfCSIDLNameNotEnvVar(csidlName) {
|
|
180
|
+
if (csidlName === "CSIDL_PERSONAL") {
|
|
181
|
+
const p = process.env.USERPROFILE;
|
|
182
|
+
if (p === undefined) {
|
|
183
|
+
throw new Error("Unset environment variable: USERPROFILE");
|
|
184
|
+
}
|
|
185
|
+
return path.join(path.normalize(p), "Documents");
|
|
186
|
+
}
|
|
187
|
+
if (csidlName === "CSIDL_DOWNLOADS") {
|
|
188
|
+
const p = process.env.USERPROFILE;
|
|
189
|
+
if (p === undefined) {
|
|
190
|
+
throw new Error("Unset environment variable: USERPROFILE");
|
|
191
|
+
}
|
|
192
|
+
return path.join(path.normalize(p), "Downloads");
|
|
193
|
+
}
|
|
194
|
+
if (csidlName === "CSIDL_MYPICTURES") {
|
|
195
|
+
const p = process.env.USERPROFILE;
|
|
196
|
+
if (p === undefined) {
|
|
197
|
+
throw new Error("Unset environment variable: USERPROFILE");
|
|
198
|
+
}
|
|
199
|
+
return path.join(path.normalize(p), "Pictures");
|
|
200
|
+
}
|
|
201
|
+
if (csidlName === "CSIDL_MYVIDEO") {
|
|
202
|
+
const p = process.env.USERPROFILE;
|
|
203
|
+
if (p === undefined) {
|
|
204
|
+
throw new Error("Unset environment variable: USERPROFILE");
|
|
205
|
+
}
|
|
206
|
+
return path.join(path.normalize(p), "Videos");
|
|
207
|
+
}
|
|
208
|
+
if (csidlName === "CSIDL_MYMUSIC") {
|
|
209
|
+
const p = process.env.USERPROFILE;
|
|
210
|
+
if (p === undefined) {
|
|
211
|
+
throw new Error("Unset environment variable: USERPROFILE");
|
|
212
|
+
}
|
|
213
|
+
return path.join(path.normalize(p), "Music");
|
|
214
|
+
}
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
// function getWinFolderFromRegistry(csidlName: string): string {
|
|
218
|
+
// throw new Error("Not implemented");
|
|
219
|
+
// }
|
|
220
|
+
// function getWinFolderViaCTypes(csidlName: string): string {
|
|
221
|
+
// throw new Error("Not implemented");
|
|
222
|
+
// }
|
|
223
|
+
function pickGetWinFolder() {
|
|
224
|
+
return getWinFolderFromEnvVars;
|
|
225
|
+
}
|
|
226
|
+
const getWinFolder = pickGetWinFolder();
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "platformdirs",
|
|
3
|
+
"version": "4.3.6-rc1",
|
|
4
|
+
"description": "📂 Unified interface to get platform-specific directories",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nodejs",
|
|
7
|
+
"port",
|
|
8
|
+
"xdg",
|
|
9
|
+
"xdg-basedir",
|
|
10
|
+
"bun",
|
|
11
|
+
"deno",
|
|
12
|
+
"appdirs",
|
|
13
|
+
"known-folders",
|
|
14
|
+
"platformdirs"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://www.jsdocs.io/package/platformdirs",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/jcbhmr/platformdirs.js.git"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "Jacob Hummer <jcbhmr@outlook.com> (https://jcbhmr.me)",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": "./dist/index.js",
|
|
26
|
+
"./android": "./dist/android.js",
|
|
27
|
+
"./api": "./dist/api.js",
|
|
28
|
+
"./macos": "./dist/macos.js",
|
|
29
|
+
"./unix": "./dist/unix.js",
|
|
30
|
+
"./version": "./dist/version.js"
|
|
31
|
+
},
|
|
32
|
+
"bin": {
|
|
33
|
+
"platformdirs": "dist/main.js"
|
|
34
|
+
},
|
|
35
|
+
"files": ["dist"],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc --noCheck",
|
|
38
|
+
"format": "biome format --write .",
|
|
39
|
+
"lint": "biome check --write . && tsc --noEmit",
|
|
40
|
+
"run": "tsx src/main.ts",
|
|
41
|
+
"test": "tsx --test"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@biomejs/biome": "1.9.4",
|
|
45
|
+
"@types/node": "^22.9.0",
|
|
46
|
+
"execa": "^9.5.1",
|
|
47
|
+
"tsx": "^4.19.2",
|
|
48
|
+
"typescript": "^5.6.3"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=18"
|
|
52
|
+
}
|
|
53
|
+
}
|