platformdirs 4.3.6 → 4.3.7

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.
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @module
3
+ * Android.
4
+ *
5
+ * TODO: Implement this module.
6
+ */
7
+ import { PlatformDirsABC } from "./api.js";
8
+ /**
9
+ * Follows the guidance [from here](https://android.stackexchange.com/a/216132).
10
+ *
11
+ * Makes use of the {@link PlatformDirsABC.appname},
12
+ * {@link PlatformDirsABC.version}, {@link PlatformDirsABC.ensureExists}.
13
+ */
14
+ export declare class Android extends PlatformDirsABC {
15
+ /**
16
+ * @return data directory tied to the user, e.g. `/data/user/<userid>/<packagename>/files/<AppName>`
17
+ */
18
+ get userDataDir(): string;
19
+ /**
20
+ * @return data directory shared by users, same as `userDataDir`
21
+ */
22
+ get siteDataDir(): string;
23
+ /**
24
+ * @return config directory tied to the user, e.g. `/data/user/<userid>/<packagename>/shared_prefs/<AppName>`
25
+ */
26
+ get userConfigDir(): string;
27
+ /**
28
+ * @return config directory shared by users, same as `userConfigDir`
29
+ */
30
+ get siteConfigDir(): string;
31
+ /**
32
+ * @return cache directory tied to the user, e.g. `/data/user/<userid>/<packagename>/cache/<AppName>`
33
+ */
34
+ get userCacheDir(): string;
35
+ /**
36
+ * @return cache directory shared by users, same as `userCacheDir`
37
+ */
38
+ get siteCacheDir(): string;
39
+ /**
40
+ * @return state directory tied to the user, same as `userDataDir`
41
+ */
42
+ get userStateDir(): string;
43
+ /**
44
+ * @return log directory tied to the user, same as `userCacheDir` if not opinionated else `log` in it, e.g. `/data/user/<userid>/<packagename>/cache/<AppName>/log`
45
+ */
46
+ get userLogDir(): string;
47
+ /**
48
+ * @return documents directory tied to the user, e.g. `/storage/emulated/0/Documents`
49
+ */
50
+ get userDocumentsDir(): string;
51
+ /**
52
+ * @return downloads directory tied to the user, e.g. `/storage/emulated/0/Downloads`
53
+ */
54
+ get userDownloadsDir(): string;
55
+ /**
56
+ * @return pictures directory tied to the user, e.g. `/storage/emulated/0/Pictures`
57
+ */
58
+ get userPicturesDir(): string;
59
+ /**
60
+ * @return videos directory tied to the user, e.g. `/storage/emulated/0/Movies`
61
+ */
62
+ get userVideosDir(): string;
63
+ /**
64
+ * @return music directory tied to the user, e.g. `/storage/emulated/0/Music`
65
+ */
66
+ get userMusicDir(): string;
67
+ /**
68
+ * @return desktop directory tied to the user, e.g. `/storage/emulated/0/Desktop`
69
+ */
70
+ get userDesktopDir(): string;
71
+ /**
72
+ * @return runtime directory tied to the user, same as `userCacheDir` if not opinionated else `tmp` in it, e.g. `/data/user/<userid>/<packagename>/cache/<AppName>/tmp`
73
+ */
74
+ get userRuntimeDir(): string;
75
+ /**
76
+ * @return runtime directory shared by users, same as `userRuntimeDir`
77
+ */
78
+ get siteRuntimeDir(): string;
79
+ }
80
+ /** @ignore @internal */
81
+ export declare function _androidFolder(): string | undefined;
@@ -0,0 +1,142 @@
1
+ /**
2
+ * @module
3
+ * Android.
4
+ *
5
+ * TODO: Implement this module.
6
+ */
7
+ import * as path from "node:path";
8
+ import { PlatformDirsABC } from "./api.js";
9
+ function throw2(error) {
10
+ throw error;
11
+ }
12
+ /**
13
+ * Follows the guidance [from here](https://android.stackexchange.com/a/216132).
14
+ *
15
+ * Makes use of the {@link PlatformDirsABC.appname},
16
+ * {@link PlatformDirsABC.version}, {@link PlatformDirsABC.ensureExists}.
17
+ */
18
+ export class Android extends PlatformDirsABC {
19
+ /**
20
+ * @return data directory tied to the user, e.g. `/data/user/<userid>/<packagename>/files/<AppName>`
21
+ */
22
+ get userDataDir() {
23
+ return this._appendAppNameAndVersion(_androidFolder() ?? throw2(new Error("unreachable")), "files");
24
+ }
25
+ /**
26
+ * @return data directory shared by users, same as `userDataDir`
27
+ */
28
+ get siteDataDir() {
29
+ return this.userDataDir;
30
+ }
31
+ /**
32
+ * @return config directory tied to the user, e.g. `/data/user/<userid>/<packagename>/shared_prefs/<AppName>`
33
+ */
34
+ get userConfigDir() {
35
+ return this._appendAppNameAndVersion(_androidFolder() ?? throw2(new Error("unreachable")), "shared_prefs");
36
+ }
37
+ /**
38
+ * @return config directory shared by users, same as `userConfigDir`
39
+ */
40
+ get siteConfigDir() {
41
+ return this.userConfigDir;
42
+ }
43
+ /**
44
+ * @return cache directory tied to the user, e.g. `/data/user/<userid>/<packagename>/cache/<AppName>`
45
+ */
46
+ get userCacheDir() {
47
+ return this._appendAppNameAndVersion(_androidFolder() ?? throw2(new Error("unreachable")), "cache");
48
+ }
49
+ /**
50
+ * @return cache directory shared by users, same as `userCacheDir`
51
+ */
52
+ get siteCacheDir() {
53
+ return this.userCacheDir;
54
+ }
55
+ /**
56
+ * @return state directory tied to the user, same as `userDataDir`
57
+ */
58
+ get userStateDir() {
59
+ return this.userDataDir;
60
+ }
61
+ /**
62
+ * @return log directory tied to the user, same as `userCacheDir` if not opinionated else `log` in it, e.g. `/data/user/<userid>/<packagename>/cache/<AppName>/log`
63
+ */
64
+ get userLogDir() {
65
+ let path2 = this.userCacheDir;
66
+ if (this.opinion) {
67
+ path2 = path.join(path2, "log");
68
+ }
69
+ return path2;
70
+ }
71
+ /**
72
+ * @return documents directory tied to the user, e.g. `/storage/emulated/0/Documents`
73
+ */
74
+ get userDocumentsDir() {
75
+ return androidDocumentsFolder();
76
+ }
77
+ /**
78
+ * @return downloads directory tied to the user, e.g. `/storage/emulated/0/Downloads`
79
+ */
80
+ get userDownloadsDir() {
81
+ return androidDownloadsFolder();
82
+ }
83
+ /**
84
+ * @return pictures directory tied to the user, e.g. `/storage/emulated/0/Pictures`
85
+ */
86
+ get userPicturesDir() {
87
+ return androidPicturesFolder();
88
+ }
89
+ /**
90
+ * @return videos directory tied to the user, e.g. `/storage/emulated/0/Movies`
91
+ */
92
+ get userVideosDir() {
93
+ return androidVideosFolder();
94
+ }
95
+ /**
96
+ * @return music directory tied to the user, e.g. `/storage/emulated/0/Music`
97
+ */
98
+ get userMusicDir() {
99
+ return androidMusicFolder();
100
+ }
101
+ /**
102
+ * @return desktop directory tied to the user, e.g. `/storage/emulated/0/Desktop`
103
+ */
104
+ get userDesktopDir() {
105
+ return "/storage/emulated/0/Desktop";
106
+ }
107
+ /**
108
+ * @return runtime directory tied to the user, same as `userCacheDir` if not opinionated else `tmp` in it, e.g. `/data/user/<userid>/<packagename>/cache/<AppName>/tmp`
109
+ */
110
+ get userRuntimeDir() {
111
+ let path2 = this.userCacheDir;
112
+ if (this.opinion) {
113
+ path2 = path.join(path2, "tmp");
114
+ }
115
+ return path2;
116
+ }
117
+ /**
118
+ * @return runtime directory shared by users, same as `userRuntimeDir`
119
+ */
120
+ get siteRuntimeDir() {
121
+ return this.userRuntimeDir;
122
+ }
123
+ }
124
+ /** @ignore @internal */
125
+ export function _androidFolder() {
126
+ throw new Error("Not implemented");
127
+ }
128
+ function androidDocumentsFolder() {
129
+ throw new Error("Not implemented");
130
+ }
131
+ function androidDownloadsFolder() {
132
+ throw new Error("Not implemented");
133
+ }
134
+ function androidPicturesFolder() {
135
+ throw new Error("Not implemented");
136
+ }
137
+ function androidVideosFolder() {
138
+ throw new Error("Not implemented");
139
+ }
140
+ function androidMusicFolder() {
141
+ throw new Error("Not implemented");
142
+ }
package/dist/api.d.ts ADDED
@@ -0,0 +1,232 @@
1
+ /**
2
+ * Base API.
3
+ * @module
4
+ */
5
+ /**
6
+ * Abstract base class for platform directories.
7
+ */
8
+ export declare abstract class PlatformDirsABC {
9
+ /**
10
+ * The name of the application.
11
+ */
12
+ appname: string | undefined;
13
+ /**
14
+ * The name of the app author or distributing body for this application.
15
+ *
16
+ * Typically it is the owning company name. Defaults to `appname`. You may pass `false` to disable it.
17
+ */
18
+ appauthor: string | false | undefined;
19
+ /**
20
+ * An optional version path element to append to the path.
21
+ *
22
+ * You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be `<major>.<minor>`.
23
+ */
24
+ version: string | undefined;
25
+ /**
26
+ * Whether to use the roaming appdata directory on Windows.
27
+ *
28
+ * That means that for users on a Windows network setup for roaming profiles, this user data will be synced on login (see [here](https://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx)).
29
+ */
30
+ roaming: boolean;
31
+ /**
32
+ * An optional parameter which indicates that the entire list of data dirs should be returned.
33
+ *
34
+ * By default, the first item would only be returned.
35
+ */
36
+ multipath: boolean;
37
+ /**
38
+ * A flag to indicating to use opinionated values.
39
+ */
40
+ opinion: boolean;
41
+ /**
42
+ * Optionally create the directory (and any missing parents) upon access if
43
+ * it does not exist.
44
+ *
45
+ * By default, no directories are created.
46
+ *
47
+ * ⚠️ Since the getters (`dirs.userDataDir`, etc.) are synchronous, the
48
+ * directory creation will use `fs.mkdirSync()` which **is a blocking
49
+ * synchronous operation** to ensure that the returned path does indeed
50
+ * exist before returning the path to the caller. This is for convenience.
51
+ * If you require non-blocking async operation you should set this to
52
+ * `false` and use `fs.mkdir()` or `fsPromises.mkdir()` yourself.
53
+ */
54
+ ensureExists: boolean;
55
+ /**
56
+ * Create a new platform directory.
57
+ * @param appname See `appname`
58
+ * @param appauthor See `appauthor`
59
+ * @param version See `version`
60
+ * @param roaming See `roaming`
61
+ * @param multipath See `multipath`
62
+ * @param opinion See `opinion`
63
+ * @param ensureExists See `ensureExists`
64
+ */
65
+ constructor(appname?: string, appauthor?: string | false, version?: string, roaming?: boolean, multipath?: boolean, opinion?: boolean, ensureExists?: boolean);
66
+ /** @ignore @internal */
67
+ protected _appendAppNameAndVersion(...base: string[]): string;
68
+ /** @ignore @internal */
69
+ protected _optionallyCreateDirectory(dir: string): void;
70
+ /** @ignore @internal */
71
+ protected _firstItemAsPathIfMultipath(directory: string): string;
72
+ /**
73
+ * @return data directory tied to the user
74
+ */
75
+ abstract get userDataDir(): string;
76
+ /**
77
+ * @return data directory shared by users
78
+ */
79
+ abstract get siteDataDir(): string;
80
+ /**
81
+ * @return config directory tied to the user
82
+ */
83
+ abstract get userConfigDir(): string;
84
+ /**
85
+ * @return config directory shared by users
86
+ */
87
+ abstract get siteConfigDir(): string;
88
+ /**
89
+ * @return cache directory tied to the user
90
+ */
91
+ abstract get userCacheDir(): string;
92
+ /**
93
+ * @return cache directory shared by users
94
+ */
95
+ abstract get siteCacheDir(): string;
96
+ /**
97
+ * @return state directory tied to the user
98
+ */
99
+ abstract get userStateDir(): string;
100
+ /**
101
+ * @return log directory tied to the user
102
+ */
103
+ abstract get userLogDir(): string;
104
+ /**
105
+ * @return documents directory tied to the user
106
+ */
107
+ abstract get userDocumentsDir(): string;
108
+ /**
109
+ * @return downloads directory tied to the user
110
+ */
111
+ abstract get userDownloadsDir(): string;
112
+ /**
113
+ * @return pictures directory tied to the user
114
+ */
115
+ abstract get userPicturesDir(): string;
116
+ /**
117
+ * @return videos directory tied to the user
118
+ */
119
+ abstract get userVideosDir(): string;
120
+ /**
121
+ * @return music directory tied to the user
122
+ */
123
+ abstract get userMusicDir(): string;
124
+ /**
125
+ * @return desktop directory tied to the user
126
+ */
127
+ abstract get userDesktopDir(): string;
128
+ /**
129
+ * @return runtime directory tied to the user
130
+ */
131
+ abstract get userRuntimeDir(): string;
132
+ /**
133
+ * @return runtime directory shared by users
134
+ */
135
+ abstract get siteRuntimeDir(): string;
136
+ /**
137
+ * @return data path tied to the user
138
+ */
139
+ get userDataPath(): string;
140
+ /**
141
+ * @return data path shared by users
142
+ */
143
+ get siteDataPath(): string;
144
+ /**
145
+ * @return config path tied to the user
146
+ */
147
+ get userConfigPath(): string;
148
+ /**
149
+ * @return config path shared by users
150
+ */
151
+ get siteConfigPath(): string;
152
+ /**
153
+ * @return cache path tied to the user
154
+ */
155
+ get userCachePath(): string;
156
+ /**
157
+ * @return cache path shared by users
158
+ */
159
+ get siteCachePath(): string;
160
+ /**
161
+ * @return state path tied to the user
162
+ */
163
+ get userStatePath(): string;
164
+ /**
165
+ * @return log path tied to the user
166
+ */
167
+ get userLogPath(): string;
168
+ /**
169
+ * @return documents path tied to the user
170
+ */
171
+ get userDocumentsPath(): string;
172
+ /**
173
+ * @return downloads path tied to the user
174
+ */
175
+ get userDownloadsPath(): string;
176
+ /**
177
+ * @return pictures path tied to the user
178
+ */
179
+ get userPicturesPath(): string;
180
+ /**
181
+ * @return videos path tied to the user
182
+ */
183
+ get userVideosPath(): string;
184
+ /**
185
+ * @return music path tied to the user
186
+ */
187
+ get userMusicPath(): string;
188
+ /**
189
+ * @return desktop path tied to the user
190
+ */
191
+ get userDesktopPath(): string;
192
+ /**
193
+ * @return runtime path tied to the user
194
+ */
195
+ get userRuntimePath(): string;
196
+ /**
197
+ * @return runtime path shared by users
198
+ */
199
+ get siteRuntimePath(): string;
200
+ /**
201
+ * @yields all user and site configuration directories
202
+ */
203
+ iterConfigDirs(): Generator<string>;
204
+ /**
205
+ * @yields all user and site data directories
206
+ */
207
+ iterDataDirs(): Generator<string>;
208
+ /**
209
+ * @yields all user and site cache directories
210
+ */
211
+ iterCacheDirs(): Generator<string>;
212
+ /**
213
+ * @yields all user and site runtime directories
214
+ */
215
+ iterRuntimeDirs(): Generator<string>;
216
+ /**
217
+ * @yields all user and site state directories
218
+ */
219
+ iterConfigPaths(): Generator<string>;
220
+ /**
221
+ * @yields all user and site data directories
222
+ */
223
+ iterDataPaths(): Generator<string>;
224
+ /**
225
+ * @yields all user and site cache directories
226
+ */
227
+ iterCachePaths(): Generator<string>;
228
+ /**
229
+ * @yields all user and site runtime directories
230
+ */
231
+ iterRuntimePaths(): Generator<string>;
232
+ }
package/dist/api.js ADDED
@@ -0,0 +1,250 @@
1
+ /**
2
+ * Base API.
3
+ * @module
4
+ */
5
+ import * as fs from "node:fs";
6
+ import * as path from "node:path";
7
+ /**
8
+ * Abstract base class for platform directories.
9
+ */
10
+ export class PlatformDirsABC {
11
+ /**
12
+ * The name of the application.
13
+ */
14
+ appname;
15
+ /**
16
+ * The name of the app author or distributing body for this application.
17
+ *
18
+ * Typically it is the owning company name. Defaults to `appname`. You may pass `false` to disable it.
19
+ */
20
+ appauthor;
21
+ /**
22
+ * An optional version path element to append to the path.
23
+ *
24
+ * You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be `<major>.<minor>`.
25
+ */
26
+ version;
27
+ /**
28
+ * Whether to use the roaming appdata directory on Windows.
29
+ *
30
+ * That means that for users on a Windows network setup for roaming profiles, this user data will be synced on login (see [here](https://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx)).
31
+ */
32
+ roaming;
33
+ /**
34
+ * An optional parameter which indicates that the entire list of data dirs should be returned.
35
+ *
36
+ * By default, the first item would only be returned.
37
+ */
38
+ multipath;
39
+ /**
40
+ * A flag to indicating to use opinionated values.
41
+ */
42
+ opinion;
43
+ /**
44
+ * Optionally create the directory (and any missing parents) upon access if
45
+ * it does not exist.
46
+ *
47
+ * By default, no directories are created.
48
+ *
49
+ * ⚠️ Since the getters (`dirs.userDataDir`, etc.) are synchronous, the
50
+ * directory creation will use `fs.mkdirSync()` which **is a blocking
51
+ * synchronous operation** to ensure that the returned path does indeed
52
+ * exist before returning the path to the caller. This is for convenience.
53
+ * If you require non-blocking async operation you should set this to
54
+ * `false` and use `fs.mkdir()` or `fsPromises.mkdir()` yourself.
55
+ */
56
+ ensureExists;
57
+ /**
58
+ * Create a new platform directory.
59
+ * @param appname See `appname`
60
+ * @param appauthor See `appauthor`
61
+ * @param version See `version`
62
+ * @param roaming See `roaming`
63
+ * @param multipath See `multipath`
64
+ * @param opinion See `opinion`
65
+ * @param ensureExists See `ensureExists`
66
+ */
67
+ constructor(appname, appauthor, version, roaming = false, multipath = false, opinion = true, ensureExists = false) {
68
+ this.appname = appname;
69
+ this.appauthor = appauthor;
70
+ this.version = version;
71
+ this.roaming = roaming;
72
+ this.multipath = multipath;
73
+ this.opinion = opinion;
74
+ this.ensureExists = ensureExists;
75
+ }
76
+ /** @ignore @internal */
77
+ _appendAppNameAndVersion(...base) {
78
+ const params = base.slice(1);
79
+ if (this.appname) {
80
+ params.push(this.appname);
81
+ if (this.version) {
82
+ params.push(this.version);
83
+ }
84
+ }
85
+ const path2 = path.join(base[0], ...params);
86
+ this._optionallyCreateDirectory(path2);
87
+ return path2;
88
+ }
89
+ /** @ignore @internal */
90
+ _optionallyCreateDirectory(dir) {
91
+ if (this.ensureExists) {
92
+ fs.mkdirSync(dir, { recursive: true });
93
+ }
94
+ }
95
+ /** @ignore @internal */
96
+ _firstItemAsPathIfMultipath(directory) {
97
+ if (this.multipath) {
98
+ return directory.split(path.delimiter)[0];
99
+ }
100
+ return directory;
101
+ }
102
+ /**
103
+ * @return data path tied to the user
104
+ */
105
+ get userDataPath() {
106
+ return this.userDataDir;
107
+ }
108
+ /**
109
+ * @return data path shared by users
110
+ */
111
+ get siteDataPath() {
112
+ return this.siteDataDir;
113
+ }
114
+ /**
115
+ * @return config path tied to the user
116
+ */
117
+ get userConfigPath() {
118
+ return this.userConfigDir;
119
+ }
120
+ /**
121
+ * @return config path shared by users
122
+ */
123
+ get siteConfigPath() {
124
+ return this.siteConfigDir;
125
+ }
126
+ /**
127
+ * @return cache path tied to the user
128
+ */
129
+ get userCachePath() {
130
+ return this.userCacheDir;
131
+ }
132
+ /**
133
+ * @return cache path shared by users
134
+ */
135
+ get siteCachePath() {
136
+ return this.siteCacheDir;
137
+ }
138
+ /**
139
+ * @return state path tied to the user
140
+ */
141
+ get userStatePath() {
142
+ return this.userStateDir;
143
+ }
144
+ /**
145
+ * @return log path tied to the user
146
+ */
147
+ get userLogPath() {
148
+ return this.userLogDir;
149
+ }
150
+ /**
151
+ * @return documents path tied to the user
152
+ */
153
+ get userDocumentsPath() {
154
+ return this.userDocumentsDir;
155
+ }
156
+ /**
157
+ * @return downloads path tied to the user
158
+ */
159
+ get userDownloadsPath() {
160
+ return this.userDownloadsDir;
161
+ }
162
+ /**
163
+ * @return pictures path tied to the user
164
+ */
165
+ get userPicturesPath() {
166
+ return this.userPicturesDir;
167
+ }
168
+ /**
169
+ * @return videos path tied to the user
170
+ */
171
+ get userVideosPath() {
172
+ return this.userVideosDir;
173
+ }
174
+ /**
175
+ * @return music path tied to the user
176
+ */
177
+ get userMusicPath() {
178
+ return this.userMusicDir;
179
+ }
180
+ /**
181
+ * @return desktop path tied to the user
182
+ */
183
+ get userDesktopPath() {
184
+ return this.userDesktopDir;
185
+ }
186
+ /**
187
+ * @return runtime path tied to the user
188
+ */
189
+ get userRuntimePath() {
190
+ return this.userRuntimeDir;
191
+ }
192
+ /**
193
+ * @return runtime path shared by users
194
+ */
195
+ get siteRuntimePath() {
196
+ return this.siteRuntimeDir;
197
+ }
198
+ /**
199
+ * @yields all user and site configuration directories
200
+ */
201
+ *iterConfigDirs() {
202
+ yield this.userConfigDir;
203
+ yield this.siteConfigDir;
204
+ }
205
+ /**
206
+ * @yields all user and site data directories
207
+ */
208
+ *iterDataDirs() {
209
+ yield this.userDataDir;
210
+ yield this.siteDataDir;
211
+ }
212
+ /**
213
+ * @yields all user and site cache directories
214
+ */
215
+ *iterCacheDirs() {
216
+ yield this.userCacheDir;
217
+ yield this.siteCacheDir;
218
+ }
219
+ /**
220
+ * @yields all user and site runtime directories
221
+ */
222
+ *iterRuntimeDirs() {
223
+ yield this.userRuntimeDir;
224
+ yield this.siteRuntimeDir;
225
+ }
226
+ /**
227
+ * @yields all user and site state directories
228
+ */
229
+ *iterConfigPaths() {
230
+ yield* this.iterConfigDirs();
231
+ }
232
+ /**
233
+ * @yields all user and site data directories
234
+ */
235
+ *iterDataPaths() {
236
+ yield* this.iterDataDirs();
237
+ }
238
+ /**
239
+ * @yields all user and site cache directories
240
+ */
241
+ *iterCachePaths() {
242
+ yield* this.iterCacheDirs();
243
+ }
244
+ /**
245
+ * @yields all user and site runtime directories
246
+ */
247
+ *iterRuntimePaths() {
248
+ yield* this.iterRuntimeDirs();
249
+ }
250
+ }