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/index.js
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
*
|
|
4
|
+
* platformdirs is a library to determine platform-specific system directories. This includes directories where to place cache files, user data, configuration, etc.
|
|
5
|
+
*
|
|
6
|
+
* The source code and issue tracker are both hosted on [GitHub](https://github.com/jcbhmr/platformdirs.js).
|
|
7
|
+
*
|
|
8
|
+
* Utilities for determining application-specific dirs.
|
|
9
|
+
*
|
|
10
|
+
* See https://github.com/platformdirs/platformdirs for details and usage.
|
|
11
|
+
*/
|
|
12
|
+
import process from "node:process";
|
|
13
|
+
let Result;
|
|
14
|
+
if (process.platform === "win32") {
|
|
15
|
+
({ Windows: Result } = await import("./windows.js"));
|
|
16
|
+
}
|
|
17
|
+
else if (process.platform === "darwin") {
|
|
18
|
+
({ MacOS: Result } = await import("./macos.js"));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
({ Unix: Result } = await import("./unix.js"));
|
|
22
|
+
}
|
|
23
|
+
async function setPlatformDirClass() {
|
|
24
|
+
if (process.env.ANDROID_DATA === "/data" &&
|
|
25
|
+
process.env.ANDROID_ROOT === "/system") {
|
|
26
|
+
if (process.env.SHELL || process.env.PREFIX) {
|
|
27
|
+
return Result;
|
|
28
|
+
}
|
|
29
|
+
const { _androidFolder } = await import("./android.js");
|
|
30
|
+
if (_androidFolder() != null) {
|
|
31
|
+
const { Android } = await import("./android.js");
|
|
32
|
+
return Android;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return Result;
|
|
36
|
+
}
|
|
37
|
+
export const PlatformDirs = (await setPlatformDirClass());
|
|
38
|
+
export const AppDirs = PlatformDirs;
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
42
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
43
|
+
* @param version See {@link PlatformDirs.version}
|
|
44
|
+
* @param roaming See {@link PlatformDirs.roaming}
|
|
45
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
46
|
+
* @returns data directory tied to the user
|
|
47
|
+
*/
|
|
48
|
+
export function userDataDir(appname, appauthor, version, roaming = false, ensureExists = false) {
|
|
49
|
+
return new PlatformDirs(appname, appauthor, version, roaming, undefined, undefined, ensureExists).userDataDir;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
54
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
55
|
+
* @param version See {@link PlatformDirs.version}
|
|
56
|
+
* @param multipath See {@link PlatformDirs.multipath}
|
|
57
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
58
|
+
* @returns data directory shared by users
|
|
59
|
+
*/
|
|
60
|
+
export function siteDataDir(appname, appauthor, version, multipath = false, ensureExists = false) {
|
|
61
|
+
return new PlatformDirs(appname, appauthor, version, undefined, multipath, undefined, ensureExists).siteDataDir;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
65
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
66
|
+
* @param version See {@link PlatformDirs.version}
|
|
67
|
+
* @param roaming See {@link PlatformDirs.roaming}
|
|
68
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
69
|
+
* @returns config directory tied to the user
|
|
70
|
+
*/
|
|
71
|
+
export function userConfigDir(appname, appauthor, version, roaming = false, ensureExists = false) {
|
|
72
|
+
return new PlatformDirs(appname, appauthor, version, roaming, undefined, undefined, ensureExists).userConfigDir;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
76
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
77
|
+
* @param version See {@link PlatformDirs.version}
|
|
78
|
+
* @param multipath See {@link PlatformDirs.multipath}
|
|
79
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
80
|
+
* @returns config directory shared by users
|
|
81
|
+
*/
|
|
82
|
+
export function siteConfigDir(appname, appauthor, version, multipath = false, ensureExists = false) {
|
|
83
|
+
return new PlatformDirs(appname, appauthor, version, undefined, multipath, undefined, ensureExists).siteConfigDir;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
87
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
88
|
+
* @param version See {@link PlatformDirs.version}
|
|
89
|
+
* @param opinion See {@link PlatformDirs.opinion}
|
|
90
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
91
|
+
* @returns cache directory tied to the user
|
|
92
|
+
*/
|
|
93
|
+
export function userCacheDir(appname, appauthor, version, opinion = true, ensureExists = false) {
|
|
94
|
+
return new PlatformDirs(appname, appauthor, version, undefined, undefined, opinion, ensureExists).userCacheDir;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
98
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
99
|
+
* @param version See {@link PlatformDirs.version}
|
|
100
|
+
* @param opinion See {@link PlatformDirs.opinion}
|
|
101
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
102
|
+
* @returns cache directory tied to the user
|
|
103
|
+
*/
|
|
104
|
+
export function siteCacheDir(appname, appauthor, version, opinion = true, ensureExists = false) {
|
|
105
|
+
return new PlatformDirs(appname, appauthor, version, undefined, undefined, opinion, ensureExists).siteCacheDir;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
109
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
110
|
+
* @param version See {@link PlatformDirs.version}
|
|
111
|
+
* @param roaming See {@link PlatformDirs.roaming}
|
|
112
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
113
|
+
* @returns state directory tied to the user
|
|
114
|
+
*/
|
|
115
|
+
export function userStateDir(appname, appauthor, version, roaming = false, ensureExists = false) {
|
|
116
|
+
return new PlatformDirs(appname, appauthor, version, roaming, undefined, undefined, ensureExists).userStateDir;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
120
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
121
|
+
* @param version See {@link PlatformDirs.version}
|
|
122
|
+
* @param opinion See {@link PlatformDirs.opinion}
|
|
123
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
124
|
+
* @returns log directory tied to the user
|
|
125
|
+
*/
|
|
126
|
+
export function userLogDir(appname, appauthor, version, opinion = true, ensureExists = false) {
|
|
127
|
+
return new PlatformDirs(appname, appauthor, version, undefined, undefined, opinion, ensureExists).userLogDir;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* @returns documents directory tied to the user
|
|
131
|
+
*/
|
|
132
|
+
export function userDocumentsDir() {
|
|
133
|
+
return new PlatformDirs().userDocumentsDir;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* @returns downloads directory tied to the user
|
|
137
|
+
*/
|
|
138
|
+
export function userDownloadsDir() {
|
|
139
|
+
return new PlatformDirs().userDownloadsDir;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* @returns pictures directory tied to the user
|
|
143
|
+
*/
|
|
144
|
+
export function userPicturesDir() {
|
|
145
|
+
return new PlatformDirs().userPicturesDir;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* @returns videos directory tied to the user
|
|
149
|
+
*/
|
|
150
|
+
export function userVideosDir() {
|
|
151
|
+
return new PlatformDirs().userVideosDir;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* @returns music directory tied to the user
|
|
155
|
+
*/
|
|
156
|
+
export function userMusicDir() {
|
|
157
|
+
return new PlatformDirs().userMusicDir;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* @returns desktop directory tied to the user
|
|
161
|
+
*/
|
|
162
|
+
export function userDesktopDir() {
|
|
163
|
+
return new PlatformDirs().userDesktopDir;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
167
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
168
|
+
* @param version See {@link PlatformDirs.version}
|
|
169
|
+
* @param opinion See {@link PlatformDirs.opinion}
|
|
170
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
171
|
+
* @returns runtime directory tied to the user
|
|
172
|
+
*/
|
|
173
|
+
export function userRuntimeDir(appname, appauthor, version, opinion = true, ensureExists = false) {
|
|
174
|
+
return new PlatformDirs(appname, appauthor, version, undefined, undefined, opinion, ensureExists).userRuntimeDir;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
178
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
179
|
+
* @param version See {@link PlatformDirs.version}
|
|
180
|
+
* @param opinion See {@link PlatformDirs.opinion}
|
|
181
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
182
|
+
* @returns runtime directory shared by users
|
|
183
|
+
*/
|
|
184
|
+
export function siteRuntimeDir(appname, appauthor, version, opinion = true, ensureExists = false) {
|
|
185
|
+
return new PlatformDirs(appname, appauthor, version, undefined, undefined, opinion, ensureExists).siteRuntimeDir;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
189
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
190
|
+
* @param version See {@link PlatformDirs.version}
|
|
191
|
+
* @param roaming See {@link PlatformDirs.roaming}
|
|
192
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
193
|
+
* @returns data path tied to the user
|
|
194
|
+
*/
|
|
195
|
+
export function userDataPath(appname, appauthor, version, roaming = false, ensureExists = false) {
|
|
196
|
+
return new PlatformDirs(appname, appauthor, version, roaming, undefined, undefined, ensureExists).userDataPath;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
200
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
201
|
+
* @param version See {@link PlatformDirs.version}
|
|
202
|
+
* @param multipath See {@link PlatformDirs.multipath}
|
|
203
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
204
|
+
* @returns data path shared by users
|
|
205
|
+
*/
|
|
206
|
+
export function siteDataPath(appname, appauthor, version, multipath = false, ensureExists = false) {
|
|
207
|
+
return new PlatformDirs(appname, appauthor, version, undefined, multipath, undefined, ensureExists).siteDataPath;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
211
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
212
|
+
* @param version See {@link PlatformDirs.version}
|
|
213
|
+
* @param roaming See {@link PlatformDirs.roaming}
|
|
214
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
215
|
+
* @returns config path tied to the user
|
|
216
|
+
*/
|
|
217
|
+
export function userConfigPath(appname, appauthor, version, roaming = false, ensureExists = false) {
|
|
218
|
+
return new PlatformDirs(appname, appauthor, version, roaming, undefined, undefined, ensureExists).userConfigPath;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
222
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
223
|
+
* @param version See {@link PlatformDirs.version}
|
|
224
|
+
* @param multipath See {@link PlatformDirs.multipath}
|
|
225
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
226
|
+
* @returns config path shared by the users
|
|
227
|
+
*/
|
|
228
|
+
export function siteConfigPath(appname, appauthor, version, multipath = false, ensureExists = false) {
|
|
229
|
+
return new PlatformDirs(appname, appauthor, version, undefined, multipath, undefined, ensureExists).siteConfigPath;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
233
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
234
|
+
* @param version See {@link PlatformDirs.version}
|
|
235
|
+
* @param opinion See {@link PlatformDirs.opinion}
|
|
236
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
237
|
+
* @returns cache path shared by users
|
|
238
|
+
*/
|
|
239
|
+
export function siteCachePath(appname, appauthor, version, opinion = true, ensureExists = false) {
|
|
240
|
+
return new PlatformDirs(appname, appauthor, version, undefined, undefined, opinion, ensureExists).siteCachePath;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
244
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
245
|
+
* @param version See {@link PlatformDirs.version}
|
|
246
|
+
* @param opinion See {@link PlatformDirs.opinion}
|
|
247
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
248
|
+
* @returns cache path tied to the user
|
|
249
|
+
*/
|
|
250
|
+
export function userCachePath(appname, appauthor, version, opinion = true, ensureExists = false) {
|
|
251
|
+
return new PlatformDirs(appname, appauthor, version, undefined, undefined, opinion, ensureExists).userCachePath;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
255
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
256
|
+
* @param version See {@link PlatformDirs.version}
|
|
257
|
+
* @param roaming See {@link PlatformDirs.roaming}
|
|
258
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
259
|
+
* @returns state path tied to the user
|
|
260
|
+
*/
|
|
261
|
+
export function userStatePath(appname, appauthor, version, roaming = false, ensureExists = false) {
|
|
262
|
+
return new PlatformDirs(appname, appauthor, version, roaming, undefined, undefined, ensureExists).userStatePath;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
266
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
267
|
+
* @param version See {@link PlatformDirs.version}
|
|
268
|
+
* @param opinion See {@link PlatformDirs.opinion}
|
|
269
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
270
|
+
* @returns log path tied to the user
|
|
271
|
+
*/
|
|
272
|
+
export function userLogPath(appname, appauthor, version, opinion = true, ensureExists = false) {
|
|
273
|
+
return new PlatformDirs(appname, appauthor, version, undefined, undefined, opinion, ensureExists).userLogPath;
|
|
274
|
+
}
|
|
275
|
+
/** @returns documents path tied to the user */
|
|
276
|
+
export function userDocumentsPath() {
|
|
277
|
+
return new PlatformDirs().userDocumentsPath;
|
|
278
|
+
}
|
|
279
|
+
/** @returns downloads path tied to the user */
|
|
280
|
+
export function userDownloadsPath() {
|
|
281
|
+
return new PlatformDirs().userDownloadsPath;
|
|
282
|
+
}
|
|
283
|
+
/** @returns pictures path tied to the user */
|
|
284
|
+
export function userPicturesPath() {
|
|
285
|
+
return new PlatformDirs().userPicturesPath;
|
|
286
|
+
}
|
|
287
|
+
/** @returns videos path tied to the user */
|
|
288
|
+
export function userVideosPath() {
|
|
289
|
+
return new PlatformDirs().userVideosPath;
|
|
290
|
+
}
|
|
291
|
+
/** @returns music path tied to the user */
|
|
292
|
+
export function userMusicPath() {
|
|
293
|
+
return new PlatformDirs().userMusicPath;
|
|
294
|
+
}
|
|
295
|
+
/** @returns desktop path tied to the user */
|
|
296
|
+
export function userDesktopPath() {
|
|
297
|
+
return new PlatformDirs().userDesktopPath;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
301
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
302
|
+
* @param version See {@link PlatformDirs.version}
|
|
303
|
+
* @param opinion See {@link PlatformDirs.opinion}
|
|
304
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
305
|
+
* @returns runtime path tied to the user
|
|
306
|
+
*/
|
|
307
|
+
export function userRuntimePath(appname, appauthor, version, opinion = true, ensureExists = false) {
|
|
308
|
+
return new PlatformDirs(appname, appauthor, version, undefined, undefined, opinion, ensureExists).userRuntimePath;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* @param appname See {@link PlatformDirs.appname}
|
|
312
|
+
* @param appauthor See {@link PlatformDirs.appauthor}
|
|
313
|
+
* @param version See {@link PlatformDirs.version}
|
|
314
|
+
* @param opinion See {@link PlatformDirs.opinion}
|
|
315
|
+
* @param ensureExists See {@link PlatformDirs.ensureExists}
|
|
316
|
+
* @returns runtime path shared by users
|
|
317
|
+
*/
|
|
318
|
+
export function siteRuntimePath(appname, appauthor, version, opinion = true, ensureExists = false) {
|
|
319
|
+
return new PlatformDirs(appname, appauthor, version, undefined, undefined, opinion, ensureExists).siteRuntimePath;
|
|
320
|
+
}
|
|
321
|
+
export { PlatformDirsABC } from "./api.js";
|
|
322
|
+
export { version, versionTuple as versionInfo } from "./version.js";
|
package/dist/macos.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* macOS.
|
|
4
|
+
*/
|
|
5
|
+
import { PlatformDirsABC } from "./api.js";
|
|
6
|
+
/**
|
|
7
|
+
* Platform directories for the macOS operating system.
|
|
8
|
+
*
|
|
9
|
+
* Follows the guidance from [Apple documentation](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/MacOSXDirectories/MacOSXDirectories.html). Makes use of the {@link PlatformDirsABC.appname}, {@link PlatformDirsABC.version}, {@link PlatformDirsABC.ensureExists}.
|
|
10
|
+
*/
|
|
11
|
+
export declare class MacOS extends PlatformDirsABC {
|
|
12
|
+
/**
|
|
13
|
+
* @return data directory tied to the user, e.g. `~/Library/Application Support/$appname/$version`
|
|
14
|
+
*/
|
|
15
|
+
get userDataDir(): string;
|
|
16
|
+
/**
|
|
17
|
+
* @return data directory shared by users, e.g. `/Library/Application
|
|
18
|
+
* Support/$appname/$version`. If we're using a Node.js, Deno, or Bun binary
|
|
19
|
+
* managed by [Homebrew](https://brew.sh), the directory will be under the
|
|
20
|
+
* Homebrew prefix, e.g. `/opt/homebrew/share/$appname/$version`. If
|
|
21
|
+
* {@link PlatformDirsABC.multipath} is enabled, and we're in Homebrew, the
|
|
22
|
+
* response is a multi-path string separated by ":", e.g.
|
|
23
|
+
* `/opt/homebrew/share/$appname/$version:/Library/Application
|
|
24
|
+
* Support/$appname/$version`.
|
|
25
|
+
*/
|
|
26
|
+
get siteDataDir(): string;
|
|
27
|
+
/**
|
|
28
|
+
* @return data path shared by users. Only return the first item, even if
|
|
29
|
+
* `multipath` is enabled is set to `true`.
|
|
30
|
+
*/
|
|
31
|
+
get siteDataPath(): string;
|
|
32
|
+
/**
|
|
33
|
+
* @return config directory tied to the user, same as `userDataDir`
|
|
34
|
+
*/
|
|
35
|
+
get userConfigDir(): string;
|
|
36
|
+
/**
|
|
37
|
+
* @return config directory shared by users, same as `siteDataDir`
|
|
38
|
+
*/
|
|
39
|
+
get siteConfigDir(): string;
|
|
40
|
+
/**
|
|
41
|
+
* @return cache directory tied to the user, e.g. `~/Library/Caches/$appname/$version`
|
|
42
|
+
*/
|
|
43
|
+
get userCacheDir(): string;
|
|
44
|
+
/**
|
|
45
|
+
* @return cache directory shared by users, e.g. `/Library/Caches/$appname/$version`.
|
|
46
|
+
* If we're using a Node.js, Deno, or Bun binary managed by [Homebrew](https://brew.sh),
|
|
47
|
+
* the directory will be under the Homebrew prefix, e.g. `/opt/homebrew/var/cache/$appname/$version`.
|
|
48
|
+
* If {@link PlatformDirsABC.multipath} is enabled, and we're in Homebrew, the response is a multi-path string separated by ":", e.g.
|
|
49
|
+
* `/opt/homebrew/var/cache/$appname/$version:/Library/Caches/$appname/$version`.
|
|
50
|
+
*/
|
|
51
|
+
get siteCacheDir(): string;
|
|
52
|
+
/**
|
|
53
|
+
* @return cache path shared by users. Only return the first item, even if
|
|
54
|
+
* `multipath` is enabled is set to `true`.
|
|
55
|
+
*/
|
|
56
|
+
get siteCachePath(): string;
|
|
57
|
+
/**
|
|
58
|
+
* @return state directory tied to the user, e.g. `~/Library/Application Support/$appname/$version`
|
|
59
|
+
*/
|
|
60
|
+
get userStateDir(): string;
|
|
61
|
+
/**
|
|
62
|
+
* @return log directory tied to the user, e.g. `~/Library/Logs/$appname/$version`
|
|
63
|
+
*/
|
|
64
|
+
get userLogDir(): string;
|
|
65
|
+
/**
|
|
66
|
+
* @return documents directory tied to the user, e.g. `~/Documents`
|
|
67
|
+
*/
|
|
68
|
+
get userDocumentsDir(): string;
|
|
69
|
+
/**
|
|
70
|
+
* @return downloads directory tied to the user, e.g. `~/Downloads`
|
|
71
|
+
*/
|
|
72
|
+
get userDownloadsDir(): string;
|
|
73
|
+
/**
|
|
74
|
+
* @return pictures directory tied to the user, e.g. `~/Pictures`
|
|
75
|
+
*/
|
|
76
|
+
get userPicturesDir(): string;
|
|
77
|
+
/**
|
|
78
|
+
* @return videos directory tied to the user, e.g. `~/Movies`
|
|
79
|
+
*/
|
|
80
|
+
get userVideosDir(): string;
|
|
81
|
+
/**
|
|
82
|
+
* @return music directory tied to the user, e.g. `~/Music`
|
|
83
|
+
*/
|
|
84
|
+
get userMusicDir(): string;
|
|
85
|
+
/**
|
|
86
|
+
* @return desktop directory tied to the user, e.g. `~/Desktop`
|
|
87
|
+
*/
|
|
88
|
+
get userDesktopDir(): string;
|
|
89
|
+
/**
|
|
90
|
+
* @return runtime directory tied to the user, e.g. `~/Library/Caches/TemporaryItems`
|
|
91
|
+
*/
|
|
92
|
+
get userRuntimeDir(): string;
|
|
93
|
+
/**
|
|
94
|
+
* @return runtime directory shared by users, same as `userRuntimeDir`
|
|
95
|
+
*/
|
|
96
|
+
get siteRuntimeDir(): string;
|
|
97
|
+
}
|
package/dist/macos.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* macOS.
|
|
4
|
+
*/
|
|
5
|
+
import * as os from "node:os";
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
import process from "node:process";
|
|
8
|
+
import { PlatformDirsABC } from "./api.js";
|
|
9
|
+
function expanduser(path2) {
|
|
10
|
+
return path2.replace(/^~\//, `${os.homedir()}/`);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Platform directories for the macOS operating system.
|
|
14
|
+
*
|
|
15
|
+
* Follows the guidance from [Apple documentation](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/MacOSXDirectories/MacOSXDirectories.html). Makes use of the {@link PlatformDirsABC.appname}, {@link PlatformDirsABC.version}, {@link PlatformDirsABC.ensureExists}.
|
|
16
|
+
*/
|
|
17
|
+
export class MacOS extends PlatformDirsABC {
|
|
18
|
+
/**
|
|
19
|
+
* @return data directory tied to the user, e.g. `~/Library/Application Support/$appname/$version`
|
|
20
|
+
*/
|
|
21
|
+
get userDataDir() {
|
|
22
|
+
return this._appendAppNameAndVersion(expanduser("~/Library/Application Support"));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @return data directory shared by users, e.g. `/Library/Application
|
|
26
|
+
* Support/$appname/$version`. If we're using a Node.js, Deno, or Bun binary
|
|
27
|
+
* managed by [Homebrew](https://brew.sh), the directory will be under the
|
|
28
|
+
* Homebrew prefix, e.g. `/opt/homebrew/share/$appname/$version`. If
|
|
29
|
+
* {@link PlatformDirsABC.multipath} is enabled, and we're in Homebrew, the
|
|
30
|
+
* response is a multi-path string separated by ":", e.g.
|
|
31
|
+
* `/opt/homebrew/share/$appname/$version:/Library/Application
|
|
32
|
+
* Support/$appname/$version`.
|
|
33
|
+
*/
|
|
34
|
+
get siteDataDir() {
|
|
35
|
+
const isHomebrew = process.execPath.startsWith("/opt/homebrew");
|
|
36
|
+
const pathList = isHomebrew
|
|
37
|
+
? [this._appendAppNameAndVersion("/opt/homebrew/share")]
|
|
38
|
+
: [];
|
|
39
|
+
pathList.push(this._appendAppNameAndVersion("/Library/Application Support"));
|
|
40
|
+
if (this.multipath) {
|
|
41
|
+
return pathList.join(path.delimiter);
|
|
42
|
+
}
|
|
43
|
+
return pathList[0];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @return data path shared by users. Only return the first item, even if
|
|
47
|
+
* `multipath` is enabled is set to `true`.
|
|
48
|
+
*/
|
|
49
|
+
get siteDataPath() {
|
|
50
|
+
return this._firstItemAsPathIfMultipath(this.siteDataDir);
|
|
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, e.g. `~/Library/Caches/$appname/$version`
|
|
66
|
+
*/
|
|
67
|
+
get userCacheDir() {
|
|
68
|
+
return this._appendAppNameAndVersion(expanduser("~/Library/Caches"));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* @return cache directory shared by users, e.g. `/Library/Caches/$appname/$version`.
|
|
72
|
+
* If we're using a Node.js, Deno, or Bun binary managed by [Homebrew](https://brew.sh),
|
|
73
|
+
* the directory will be under the Homebrew prefix, e.g. `/opt/homebrew/var/cache/$appname/$version`.
|
|
74
|
+
* If {@link PlatformDirsABC.multipath} is enabled, and we're in Homebrew, the response is a multi-path string separated by ":", e.g.
|
|
75
|
+
* `/opt/homebrew/var/cache/$appname/$version:/Library/Caches/$appname/$version`.
|
|
76
|
+
*/
|
|
77
|
+
get siteCacheDir() {
|
|
78
|
+
const isHomebrew = process.execPath.startsWith("/opt/homebrew");
|
|
79
|
+
const pathList = isHomebrew
|
|
80
|
+
? [this._appendAppNameAndVersion("/opt/homebrew/var/cache")]
|
|
81
|
+
: [];
|
|
82
|
+
pathList.push(this._appendAppNameAndVersion("/Library/Caches"));
|
|
83
|
+
if (this.multipath) {
|
|
84
|
+
return pathList.join(path.delimiter);
|
|
85
|
+
}
|
|
86
|
+
return pathList[0];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @return cache path shared by users. Only return the first item, even if
|
|
90
|
+
* `multipath` is enabled is set to `true`.
|
|
91
|
+
*/
|
|
92
|
+
get siteCachePath() {
|
|
93
|
+
return this._firstItemAsPathIfMultipath(this.siteCacheDir);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @return state directory tied to the user, e.g. `~/Library/Application Support/$appname/$version`
|
|
97
|
+
*/
|
|
98
|
+
get userStateDir() {
|
|
99
|
+
return this.userDataDir;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @return log directory tied to the user, e.g. `~/Library/Logs/$appname/$version`
|
|
103
|
+
*/
|
|
104
|
+
get userLogDir() {
|
|
105
|
+
return this._appendAppNameAndVersion(expanduser("~/Library/Logs"));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @return documents directory tied to the user, e.g. `~/Documents`
|
|
109
|
+
*/
|
|
110
|
+
get userDocumentsDir() {
|
|
111
|
+
return expanduser("~/Documents");
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* @return downloads directory tied to the user, e.g. `~/Downloads`
|
|
115
|
+
*/
|
|
116
|
+
get userDownloadsDir() {
|
|
117
|
+
return expanduser("~/Downloads");
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* @return pictures directory tied to the user, e.g. `~/Pictures`
|
|
121
|
+
*/
|
|
122
|
+
get userPicturesDir() {
|
|
123
|
+
return expanduser("~/Pictures");
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* @return videos directory tied to the user, e.g. `~/Movies`
|
|
127
|
+
*/
|
|
128
|
+
get userVideosDir() {
|
|
129
|
+
return expanduser("~/Movies");
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* @return music directory tied to the user, e.g. `~/Music`
|
|
133
|
+
*/
|
|
134
|
+
get userMusicDir() {
|
|
135
|
+
return expanduser("~/Music");
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* @return desktop directory tied to the user, e.g. `~/Desktop`
|
|
139
|
+
*/
|
|
140
|
+
get userDesktopDir() {
|
|
141
|
+
return expanduser("~/Desktop");
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* @return runtime directory tied to the user, e.g. `~/Library/Caches/TemporaryItems`
|
|
145
|
+
*/
|
|
146
|
+
get userRuntimeDir() {
|
|
147
|
+
return this._appendAppNameAndVersion(expanduser("~/Library/Caches/TemporaryItems"));
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* @return runtime directory shared by users, same as `userRuntimeDir`
|
|
151
|
+
*/
|
|
152
|
+
get siteRuntimeDir() {
|
|
153
|
+
return this.userRuntimeDir;
|
|
154
|
+
}
|
|
155
|
+
}
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { PlatformDirs, version } from "./index.js";
|
|
2
|
+
const props = {
|
|
3
|
+
user_data_dir: "userDataDir",
|
|
4
|
+
user_config_dir: "userConfigDir",
|
|
5
|
+
user_cache_dir: "userCacheDir",
|
|
6
|
+
user_state_dir: "userStateDir",
|
|
7
|
+
user_log_dir: "userLogDir",
|
|
8
|
+
user_documents_dir: "userDocumentsDir",
|
|
9
|
+
user_downloads_dir: "userDownloadsDir",
|
|
10
|
+
user_pictures_dir: "userPicturesDir",
|
|
11
|
+
user_videos_dir: "userVideosDir",
|
|
12
|
+
user_music_dir: "userMusicDir",
|
|
13
|
+
user_runtime_dir: "userRuntimeDir",
|
|
14
|
+
site_data_dir: "siteDataDir",
|
|
15
|
+
site_config_dir: "siteConfigDir",
|
|
16
|
+
site_cache_dir: "siteCacheDir",
|
|
17
|
+
site_runtime_dir: "siteRuntimeDir",
|
|
18
|
+
};
|
|
19
|
+
const appName = "MyApp";
|
|
20
|
+
const appAuthor = "MyCompany";
|
|
21
|
+
console.log(`-- platformdirs ${version} --`);
|
|
22
|
+
console.log("-- app dirs (with optional 'version')");
|
|
23
|
+
let dirs = new PlatformDirs(appName, appAuthor, "1.0");
|
|
24
|
+
for (const [label, key] of Object.entries(props)) {
|
|
25
|
+
console.log(`${label}: ${dirs[key]}`);
|
|
26
|
+
}
|
|
27
|
+
console.log("\n-- app dirs (without optional 'version')");
|
|
28
|
+
dirs = new PlatformDirs(appName, appAuthor);
|
|
29
|
+
for (const [label, key] of Object.entries(props)) {
|
|
30
|
+
console.log(`${label}: ${dirs[key]}`);
|
|
31
|
+
}
|
|
32
|
+
console.log("\n-- app dirs (without optional 'appauthor')");
|
|
33
|
+
dirs = new PlatformDirs(appName);
|
|
34
|
+
for (const [label, key] of Object.entries(props)) {
|
|
35
|
+
console.log(`${label}: ${dirs[key]}`);
|
|
36
|
+
}
|
|
37
|
+
console.log("\n-- app dirs (with disabled 'appauthor')");
|
|
38
|
+
dirs = new PlatformDirs(appName, false);
|
|
39
|
+
for (const [label, key] of Object.entries(props)) {
|
|
40
|
+
console.log(`${label}: ${dirs[key]}`);
|
|
41
|
+
}
|