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/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
+ }
@@ -0,0 +1,238 @@
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 type { Android } from "./android.js";
13
+ import type { MacOS } from "./macos.js";
14
+ import type { Unix } from "./unix.js";
15
+ import type { Windows } from "./windows.js";
16
+ export type PlatformDirs = Windows | MacOS | Unix | Android;
17
+ export declare const PlatformDirs: typeof Windows | typeof MacOS | typeof Unix | typeof Android;
18
+ export declare const AppDirs: typeof Windows | typeof MacOS | typeof Unix | typeof Android;
19
+ /**
20
+ *
21
+ * @param appname See {@link PlatformDirs.appname}
22
+ * @param appauthor See {@link PlatformDirs.appauthor}
23
+ * @param version See {@link PlatformDirs.version}
24
+ * @param roaming See {@link PlatformDirs.roaming}
25
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
26
+ * @returns data directory tied to the user
27
+ */
28
+ export declare function userDataDir(appname?: string, appauthor?: string | false, version?: string, roaming?: boolean, ensureExists?: boolean): string;
29
+ /**
30
+ *
31
+ * @param appname See {@link PlatformDirs.appname}
32
+ * @param appauthor See {@link PlatformDirs.appauthor}
33
+ * @param version See {@link PlatformDirs.version}
34
+ * @param multipath See {@link PlatformDirs.multipath}
35
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
36
+ * @returns data directory shared by users
37
+ */
38
+ export declare function siteDataDir(appname?: string, appauthor?: string | false, version?: string, multipath?: boolean, ensureExists?: boolean): string;
39
+ /**
40
+ * @param appname See {@link PlatformDirs.appname}
41
+ * @param appauthor See {@link PlatformDirs.appauthor}
42
+ * @param version See {@link PlatformDirs.version}
43
+ * @param roaming See {@link PlatformDirs.roaming}
44
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
45
+ * @returns config directory tied to the user
46
+ */
47
+ export declare function userConfigDir(appname?: string, appauthor?: string | false, version?: string, roaming?: boolean, ensureExists?: boolean): string;
48
+ /**
49
+ * @param appname See {@link PlatformDirs.appname}
50
+ * @param appauthor See {@link PlatformDirs.appauthor}
51
+ * @param version See {@link PlatformDirs.version}
52
+ * @param multipath See {@link PlatformDirs.multipath}
53
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
54
+ * @returns config directory shared by users
55
+ */
56
+ export declare function siteConfigDir(appname?: string, appauthor?: string | false, version?: string, multipath?: boolean, ensureExists?: boolean): string;
57
+ /**
58
+ * @param appname See {@link PlatformDirs.appname}
59
+ * @param appauthor See {@link PlatformDirs.appauthor}
60
+ * @param version See {@link PlatformDirs.version}
61
+ * @param opinion See {@link PlatformDirs.opinion}
62
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
63
+ * @returns cache directory tied to the user
64
+ */
65
+ export declare function userCacheDir(appname?: string, appauthor?: string | false, version?: string, opinion?: boolean, ensureExists?: boolean): string;
66
+ /**
67
+ * @param appname See {@link PlatformDirs.appname}
68
+ * @param appauthor See {@link PlatformDirs.appauthor}
69
+ * @param version See {@link PlatformDirs.version}
70
+ * @param opinion See {@link PlatformDirs.opinion}
71
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
72
+ * @returns cache directory tied to the user
73
+ */
74
+ export declare function siteCacheDir(appname?: string, appauthor?: string | false, version?: string, opinion?: boolean, ensureExists?: boolean): string;
75
+ /**
76
+ * @param appname See {@link PlatformDirs.appname}
77
+ * @param appauthor See {@link PlatformDirs.appauthor}
78
+ * @param version See {@link PlatformDirs.version}
79
+ * @param roaming See {@link PlatformDirs.roaming}
80
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
81
+ * @returns state directory tied to the user
82
+ */
83
+ export declare function userStateDir(appname?: string, appauthor?: string | false, version?: string, roaming?: boolean, ensureExists?: boolean): string;
84
+ /**
85
+ * @param appname See {@link PlatformDirs.appname}
86
+ * @param appauthor See {@link PlatformDirs.appauthor}
87
+ * @param version See {@link PlatformDirs.version}
88
+ * @param opinion See {@link PlatformDirs.opinion}
89
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
90
+ * @returns log directory tied to the user
91
+ */
92
+ export declare function userLogDir(appname?: string, appauthor?: string | false, version?: string, opinion?: boolean, ensureExists?: boolean): string;
93
+ /**
94
+ * @returns documents directory tied to the user
95
+ */
96
+ export declare function userDocumentsDir(): string;
97
+ /**
98
+ * @returns downloads directory tied to the user
99
+ */
100
+ export declare function userDownloadsDir(): string;
101
+ /**
102
+ * @returns pictures directory tied to the user
103
+ */
104
+ export declare function userPicturesDir(): string;
105
+ /**
106
+ * @returns videos directory tied to the user
107
+ */
108
+ export declare function userVideosDir(): string;
109
+ /**
110
+ * @returns music directory tied to the user
111
+ */
112
+ export declare function userMusicDir(): string;
113
+ /**
114
+ * @returns desktop directory tied to the user
115
+ */
116
+ export declare function userDesktopDir(): string;
117
+ /**
118
+ * @param appname See {@link PlatformDirs.appname}
119
+ * @param appauthor See {@link PlatformDirs.appauthor}
120
+ * @param version See {@link PlatformDirs.version}
121
+ * @param opinion See {@link PlatformDirs.opinion}
122
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
123
+ * @returns runtime directory tied to the user
124
+ */
125
+ export declare function userRuntimeDir(appname?: string, appauthor?: string | false, version?: string, opinion?: boolean, ensureExists?: boolean): string;
126
+ /**
127
+ * @param appname See {@link PlatformDirs.appname}
128
+ * @param appauthor See {@link PlatformDirs.appauthor}
129
+ * @param version See {@link PlatformDirs.version}
130
+ * @param opinion See {@link PlatformDirs.opinion}
131
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
132
+ * @returns runtime directory shared by users
133
+ */
134
+ export declare function siteRuntimeDir(appname?: string, appauthor?: string | false, version?: string, opinion?: boolean, ensureExists?: boolean): string;
135
+ /**
136
+ * @param appname See {@link PlatformDirs.appname}
137
+ * @param appauthor See {@link PlatformDirs.appauthor}
138
+ * @param version See {@link PlatformDirs.version}
139
+ * @param roaming See {@link PlatformDirs.roaming}
140
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
141
+ * @returns data path tied to the user
142
+ */
143
+ export declare function userDataPath(appname?: string, appauthor?: string | false, version?: string, roaming?: boolean, ensureExists?: boolean): string;
144
+ /**
145
+ * @param appname See {@link PlatformDirs.appname}
146
+ * @param appauthor See {@link PlatformDirs.appauthor}
147
+ * @param version See {@link PlatformDirs.version}
148
+ * @param multipath See {@link PlatformDirs.multipath}
149
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
150
+ * @returns data path shared by users
151
+ */
152
+ export declare function siteDataPath(appname?: string, appauthor?: string | false, version?: string, multipath?: boolean, ensureExists?: boolean): string;
153
+ /**
154
+ * @param appname See {@link PlatformDirs.appname}
155
+ * @param appauthor See {@link PlatformDirs.appauthor}
156
+ * @param version See {@link PlatformDirs.version}
157
+ * @param roaming See {@link PlatformDirs.roaming}
158
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
159
+ * @returns config path tied to the user
160
+ */
161
+ export declare function userConfigPath(appname?: string, appauthor?: string | false, version?: string, roaming?: boolean, ensureExists?: boolean): string;
162
+ /**
163
+ * @param appname See {@link PlatformDirs.appname}
164
+ * @param appauthor See {@link PlatformDirs.appauthor}
165
+ * @param version See {@link PlatformDirs.version}
166
+ * @param multipath See {@link PlatformDirs.multipath}
167
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
168
+ * @returns config path shared by the users
169
+ */
170
+ export declare function siteConfigPath(appname?: string, appauthor?: string | false, version?: string, multipath?: boolean, ensureExists?: boolean): string;
171
+ /**
172
+ * @param appname See {@link PlatformDirs.appname}
173
+ * @param appauthor See {@link PlatformDirs.appauthor}
174
+ * @param version See {@link PlatformDirs.version}
175
+ * @param opinion See {@link PlatformDirs.opinion}
176
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
177
+ * @returns cache path shared by users
178
+ */
179
+ export declare function siteCachePath(appname?: string, appauthor?: string | false, version?: string, opinion?: boolean, ensureExists?: boolean): string;
180
+ /**
181
+ * @param appname See {@link PlatformDirs.appname}
182
+ * @param appauthor See {@link PlatformDirs.appauthor}
183
+ * @param version See {@link PlatformDirs.version}
184
+ * @param opinion See {@link PlatformDirs.opinion}
185
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
186
+ * @returns cache path tied to the user
187
+ */
188
+ export declare function userCachePath(appname?: string, appauthor?: string | false, version?: string, opinion?: boolean, ensureExists?: boolean): string;
189
+ /**
190
+ * @param appname See {@link PlatformDirs.appname}
191
+ * @param appauthor See {@link PlatformDirs.appauthor}
192
+ * @param version See {@link PlatformDirs.version}
193
+ * @param roaming See {@link PlatformDirs.roaming}
194
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
195
+ * @returns state path tied to the user
196
+ */
197
+ export declare function userStatePath(appname?: string, appauthor?: string | false, version?: string, roaming?: boolean, ensureExists?: boolean): string;
198
+ /**
199
+ * @param appname See {@link PlatformDirs.appname}
200
+ * @param appauthor See {@link PlatformDirs.appauthor}
201
+ * @param version See {@link PlatformDirs.version}
202
+ * @param opinion See {@link PlatformDirs.opinion}
203
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
204
+ * @returns log path tied to the user
205
+ */
206
+ export declare function userLogPath(appname?: string, appauthor?: string | false, version?: string, opinion?: boolean, ensureExists?: boolean): string;
207
+ /** @returns documents path tied to the user */
208
+ export declare function userDocumentsPath(): string;
209
+ /** @returns downloads path tied to the user */
210
+ export declare function userDownloadsPath(): string;
211
+ /** @returns pictures path tied to the user */
212
+ export declare function userPicturesPath(): string;
213
+ /** @returns videos path tied to the user */
214
+ export declare function userVideosPath(): string;
215
+ /** @returns music path tied to the user */
216
+ export declare function userMusicPath(): string;
217
+ /** @returns desktop path tied to the user */
218
+ export declare function userDesktopPath(): string;
219
+ /**
220
+ * @param appname See {@link PlatformDirs.appname}
221
+ * @param appauthor See {@link PlatformDirs.appauthor}
222
+ * @param version See {@link PlatformDirs.version}
223
+ * @param opinion See {@link PlatformDirs.opinion}
224
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
225
+ * @returns runtime path tied to the user
226
+ */
227
+ export declare function userRuntimePath(appname?: string, appauthor?: string | false, version?: string, opinion?: boolean, ensureExists?: boolean): string;
228
+ /**
229
+ * @param appname See {@link PlatformDirs.appname}
230
+ * @param appauthor See {@link PlatformDirs.appauthor}
231
+ * @param version See {@link PlatformDirs.version}
232
+ * @param opinion See {@link PlatformDirs.opinion}
233
+ * @param ensureExists See {@link PlatformDirs.ensureExists}
234
+ * @returns runtime path shared by users
235
+ */
236
+ export declare function siteRuntimePath(appname?: string, appauthor?: string | false, version?: string, opinion?: boolean, ensureExists?: boolean): string;
237
+ export { PlatformDirsABC } from "./api.js";
238
+ export { version, versionTuple as versionInfo } from "./version.js";