os-user-dirs 3.0.1 → 3.1.0
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/README.md +20 -1
- package/index.d.ts +125 -118
- package/package.json +17 -7
package/README.md
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/os-user-dirs)
|
|
4
4
|
[](https://www.npmjs.com/package/os-user-dirs)
|
|
5
5
|
[](https://github.com/velocitylabo/os-user-dirs/actions/workflows/ci.yml)
|
|
6
|
+
[](https://codecov.io/gh/velocitylabo/os-user-dirs)
|
|
7
|
+
[](https://bundlephobia.com/package/os-user-dirs)
|
|
6
8
|
[](https://nodejs.org)
|
|
7
9
|
[](https://github.com/velocitylabo/os-user-dirs/blob/master/LICENSE)
|
|
8
10
|
|
|
@@ -153,6 +155,24 @@ Returns the path to the user fonts directory (`~/.local/share/fonts` on Linux, `
|
|
|
153
155
|
|
|
154
156
|
#### `getBasePath(name)`
|
|
155
157
|
Returns the path to the specified base directory. Valid names: `config`, `data`, `cache`, `state`, `log`, `runtime`.
|
|
158
|
+
|
|
159
|
+
## Which function should I use?
|
|
160
|
+
|
|
161
|
+
| Use case | Function |
|
|
162
|
+
|---|---|
|
|
163
|
+
| Store app config files | `configDir()` or `projectDirs("my-app").config` |
|
|
164
|
+
| Store app data / databases | `dataDir()` or `projectDirs("my-app").data` |
|
|
165
|
+
| Store app cache | `cacheDir()` or `projectDirs("my-app").cache` |
|
|
166
|
+
| Store app logs | `logDir()` or `projectDirs("my-app").log` |
|
|
167
|
+
| Get user's Downloads folder | `downloads()` |
|
|
168
|
+
| Get user's Documents folder | `documents()` |
|
|
169
|
+
| Get all app-scoped dirs at once | `projectDirs("my-app")` |
|
|
170
|
+
| Find system-wide config locations | `configDirs()` |
|
|
171
|
+
| Ensure a directory exists | `ensureDir(path)` / `ensureDirSync(path)` |
|
|
172
|
+
| Get user's home directory | `homeDir()` |
|
|
173
|
+
|
|
174
|
+
> For the full API with platform-specific details, see the **[API Reference](docs/api.md)**.
|
|
175
|
+
|
|
156
176
|
## API Overview
|
|
157
177
|
|
|
158
178
|
### User Directories
|
|
@@ -253,7 +273,6 @@ getBasePath("unknown"); // Type error
|
|
|
253
273
|
- **[Electron Guide](docs/guide-electron.md)** — Using os-user-dirs in Electron apps: `app.getPath()` mapping, main/renderer process patterns, vendor-scoped directories
|
|
254
274
|
- **[CLI Tools Guide](docs/guide-cli-tools.md)** — Using `projectDirs()` with commander, yargs, and oclif for config, cache, and log management
|
|
255
275
|
|
|
256
|
-
## Migration from xdg-basedir
|
|
257
276
|
## Migration Guides
|
|
258
277
|
|
|
259
278
|
Switching from another library? We have you covered:
|
package/index.d.ts
CHANGED
|
@@ -3,12 +3,12 @@ type DirName = "desktop" | "downloads" | "documents" | "music" | "pictures" | "v
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns the path to the Desktop directory.
|
|
5
5
|
* @example
|
|
6
|
-
* ```
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { desktop } from 'os-user-dirs';
|
|
8
|
+
* const dir = desktop();
|
|
9
9
|
* // Linux: '/home/user/Desktop'
|
|
10
10
|
* // macOS: '/Users/user/Desktop'
|
|
11
|
-
* // Windows: 'C
|
|
11
|
+
* // Windows: 'C:\\Users\\user\\Desktop'
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
export function desktop(): string;
|
|
@@ -16,12 +16,12 @@ export function desktop(): string;
|
|
|
16
16
|
/**
|
|
17
17
|
* Returns the path to the Downloads directory.
|
|
18
18
|
* @example
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { downloads } from 'os-user-dirs';
|
|
21
|
+
* const dir = downloads();
|
|
22
22
|
* // Linux: '/home/user/Downloads'
|
|
23
23
|
* // macOS: '/Users/user/Downloads'
|
|
24
|
-
* // Windows: 'C
|
|
24
|
+
* // Windows: 'C:\\Users\\user\\Downloads'
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
27
|
export function downloads(): string;
|
|
@@ -29,12 +29,12 @@ export function downloads(): string;
|
|
|
29
29
|
/**
|
|
30
30
|
* Returns the path to the Documents directory.
|
|
31
31
|
* @example
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { documents } from 'os-user-dirs';
|
|
34
|
+
* const dir = documents();
|
|
35
35
|
* // Linux: '/home/user/Documents'
|
|
36
36
|
* // macOS: '/Users/user/Documents'
|
|
37
|
-
* // Windows: 'C
|
|
37
|
+
* // Windows: 'C:\\Users\\user\\Documents'
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
40
|
export function documents(): string;
|
|
@@ -42,12 +42,12 @@ export function documents(): string;
|
|
|
42
42
|
/**
|
|
43
43
|
* Returns the path to the Music directory.
|
|
44
44
|
* @example
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { music } from 'os-user-dirs';
|
|
47
|
+
* const dir = music();
|
|
48
48
|
* // Linux: '/home/user/Music'
|
|
49
49
|
* // macOS: '/Users/user/Music'
|
|
50
|
-
* // Windows: 'C
|
|
50
|
+
* // Windows: 'C:\\Users\\user\\Music'
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
53
|
export function music(): string;
|
|
@@ -55,12 +55,12 @@ export function music(): string;
|
|
|
55
55
|
/**
|
|
56
56
|
* Returns the path to the Pictures directory.
|
|
57
57
|
* @example
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { pictures } from 'os-user-dirs';
|
|
60
|
+
* const dir = pictures();
|
|
61
61
|
* // Linux: '/home/user/Pictures'
|
|
62
62
|
* // macOS: '/Users/user/Pictures'
|
|
63
|
-
* // Windows: 'C
|
|
63
|
+
* // Windows: 'C:\\Users\\user\\Pictures'
|
|
64
64
|
* ```
|
|
65
65
|
*/
|
|
66
66
|
export function pictures(): string;
|
|
@@ -68,12 +68,12 @@ export function pictures(): string;
|
|
|
68
68
|
/**
|
|
69
69
|
* Returns the path to the Videos directory (Movies on macOS).
|
|
70
70
|
* @example
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
*
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { videos } from 'os-user-dirs';
|
|
73
|
+
* const dir = videos();
|
|
74
74
|
* // Linux: '/home/user/Videos'
|
|
75
75
|
* // macOS: '/Users/user/Movies'
|
|
76
|
-
* // Windows: 'C
|
|
76
|
+
* // Windows: 'C:\\Users\\user\\Videos'
|
|
77
77
|
* ```
|
|
78
78
|
*/
|
|
79
79
|
export function videos(): string;
|
|
@@ -81,12 +81,12 @@ export function videos(): string;
|
|
|
81
81
|
/**
|
|
82
82
|
* Returns the path to the Templates directory.
|
|
83
83
|
* @example
|
|
84
|
-
* ```
|
|
85
|
-
*
|
|
86
|
-
*
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { templates } from 'os-user-dirs';
|
|
86
|
+
* const dir = templates();
|
|
87
87
|
* // Linux: '/home/user/Templates'
|
|
88
88
|
* // macOS: '/Users/user/Templates'
|
|
89
|
-
* // Windows: 'C
|
|
89
|
+
* // Windows: 'C:\\Users\\user\\Templates'
|
|
90
90
|
* ```
|
|
91
91
|
*/
|
|
92
92
|
export function templates(): string;
|
|
@@ -94,23 +94,24 @@ export function templates(): string;
|
|
|
94
94
|
/**
|
|
95
95
|
* Returns the path to the Public Share directory.
|
|
96
96
|
* @example
|
|
97
|
-
* ```
|
|
98
|
-
*
|
|
99
|
-
*
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { publicshare } from 'os-user-dirs';
|
|
99
|
+
* const dir = publicshare();
|
|
100
100
|
* // Linux: '/home/user/Public'
|
|
101
101
|
* // macOS: '/Users/user/Public'
|
|
102
|
-
* // Windows: 'C
|
|
102
|
+
* // Windows: 'C:\\Users\\user\\Public'
|
|
103
103
|
* ```
|
|
104
104
|
*/
|
|
105
105
|
export function publicshare(): string;
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
108
|
* Returns the path to the specified user directory.
|
|
109
|
+
* @param name - Directory name to resolve
|
|
109
110
|
* @example
|
|
110
|
-
* ```
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
111
|
+
* ```ts
|
|
112
|
+
* import { getPath } from 'os-user-dirs';
|
|
113
|
+
* const dir = getPath('downloads'); // '/home/user/Downloads'
|
|
114
|
+
* const dir2 = getPath('desktop'); // '/home/user/Desktop'
|
|
114
115
|
* ```
|
|
115
116
|
*/
|
|
116
117
|
export function getPath(name: DirName): string;
|
|
@@ -118,12 +119,12 @@ export function getPath(name: DirName): string;
|
|
|
118
119
|
/**
|
|
119
120
|
* Returns the path to the user's home directory.
|
|
120
121
|
* @example
|
|
121
|
-
* ```
|
|
122
|
-
*
|
|
123
|
-
*
|
|
122
|
+
* ```ts
|
|
123
|
+
* import { homeDir } from 'os-user-dirs';
|
|
124
|
+
* const dir = homeDir();
|
|
124
125
|
* // Linux: '/home/user'
|
|
125
126
|
* // macOS: '/Users/user'
|
|
126
|
-
* // Windows: 'C
|
|
127
|
+
* // Windows: 'C:\\Users\\user'
|
|
127
128
|
* ```
|
|
128
129
|
*/
|
|
129
130
|
export function homeDir(): string;
|
|
@@ -131,9 +132,9 @@ export function homeDir(): string;
|
|
|
131
132
|
/**
|
|
132
133
|
* Returns the path to the user local bin directory (~/.local/bin), or null on Windows.
|
|
133
134
|
* @example
|
|
134
|
-
* ```
|
|
135
|
-
*
|
|
136
|
-
*
|
|
135
|
+
* ```ts
|
|
136
|
+
* import { binDir } from 'os-user-dirs';
|
|
137
|
+
* const dir = binDir();
|
|
137
138
|
* // Linux/macOS: '/home/user/.local/bin'
|
|
138
139
|
* // Windows: null
|
|
139
140
|
* ```
|
|
@@ -145,12 +146,12 @@ type BaseDirName = "config" | "data" | "cache" | "state" | "log" | "runtime";
|
|
|
145
146
|
/**
|
|
146
147
|
* Returns the path to the XDG config directory.
|
|
147
148
|
* @example
|
|
148
|
-
* ```
|
|
149
|
-
*
|
|
150
|
-
*
|
|
149
|
+
* ```ts
|
|
150
|
+
* import { configDir } from 'os-user-dirs';
|
|
151
|
+
* const dir = configDir();
|
|
151
152
|
* // Linux: '/home/user/.config'
|
|
152
153
|
* // macOS: '/Users/user/Library/Application Support'
|
|
153
|
-
* // Windows: 'C
|
|
154
|
+
* // Windows: 'C:\\Users\\user\\AppData\\Roaming'
|
|
154
155
|
* ```
|
|
155
156
|
*/
|
|
156
157
|
export function configDir(): string;
|
|
@@ -158,12 +159,12 @@ export function configDir(): string;
|
|
|
158
159
|
/**
|
|
159
160
|
* Returns the path to the XDG data directory.
|
|
160
161
|
* @example
|
|
161
|
-
* ```
|
|
162
|
-
*
|
|
163
|
-
*
|
|
162
|
+
* ```ts
|
|
163
|
+
* import { dataDir } from 'os-user-dirs';
|
|
164
|
+
* const dir = dataDir();
|
|
164
165
|
* // Linux: '/home/user/.local/share'
|
|
165
166
|
* // macOS: '/Users/user/Library/Application Support'
|
|
166
|
-
* // Windows: 'C
|
|
167
|
+
* // Windows: 'C:\\Users\\user\\AppData\\Local'
|
|
167
168
|
* ```
|
|
168
169
|
*/
|
|
169
170
|
export function dataDir(): string;
|
|
@@ -171,12 +172,12 @@ export function dataDir(): string;
|
|
|
171
172
|
/**
|
|
172
173
|
* Returns the path to the XDG cache directory.
|
|
173
174
|
* @example
|
|
174
|
-
* ```
|
|
175
|
-
*
|
|
176
|
-
*
|
|
175
|
+
* ```ts
|
|
176
|
+
* import { cacheDir } from 'os-user-dirs';
|
|
177
|
+
* const dir = cacheDir();
|
|
177
178
|
* // Linux: '/home/user/.cache'
|
|
178
179
|
* // macOS: '/Users/user/Library/Caches'
|
|
179
|
-
* // Windows: 'C
|
|
180
|
+
* // Windows: 'C:\\Users\\user\\AppData\\Local'
|
|
180
181
|
* ```
|
|
181
182
|
*/
|
|
182
183
|
export function cacheDir(): string;
|
|
@@ -184,12 +185,12 @@ export function cacheDir(): string;
|
|
|
184
185
|
/**
|
|
185
186
|
* Returns the path to the XDG state directory.
|
|
186
187
|
* @example
|
|
187
|
-
* ```
|
|
188
|
-
*
|
|
189
|
-
*
|
|
188
|
+
* ```ts
|
|
189
|
+
* import { stateDir } from 'os-user-dirs';
|
|
190
|
+
* const dir = stateDir();
|
|
190
191
|
* // Linux: '/home/user/.local/state'
|
|
191
192
|
* // macOS: '/Users/user/Library/Application Support'
|
|
192
|
-
* // Windows: 'C
|
|
193
|
+
* // Windows: 'C:\\Users\\user\\AppData\\Local'
|
|
193
194
|
* ```
|
|
194
195
|
*/
|
|
195
196
|
export function stateDir(): string;
|
|
@@ -197,12 +198,12 @@ export function stateDir(): string;
|
|
|
197
198
|
/**
|
|
198
199
|
* Returns the path to the log directory.
|
|
199
200
|
* @example
|
|
200
|
-
* ```
|
|
201
|
-
*
|
|
202
|
-
*
|
|
201
|
+
* ```ts
|
|
202
|
+
* import { logDir } from 'os-user-dirs';
|
|
203
|
+
* const dir = logDir();
|
|
203
204
|
* // Linux: '/home/user/.local/state'
|
|
204
205
|
* // macOS: '/Users/user/Library/Logs'
|
|
205
|
-
* // Windows: 'C
|
|
206
|
+
* // Windows: 'C:\\Users\\user\\AppData\\Local'
|
|
206
207
|
* ```
|
|
207
208
|
*/
|
|
208
209
|
export function logDir(): string;
|
|
@@ -210,9 +211,9 @@ export function logDir(): string;
|
|
|
210
211
|
/**
|
|
211
212
|
* Returns the path to the XDG runtime directory, or null if unavailable.
|
|
212
213
|
* @example
|
|
213
|
-
* ```
|
|
214
|
-
*
|
|
215
|
-
*
|
|
214
|
+
* ```ts
|
|
215
|
+
* import { runtimeDir } from 'os-user-dirs';
|
|
216
|
+
* const dir = runtimeDir();
|
|
216
217
|
* // Linux: '/run/user/1000' (if $XDG_RUNTIME_DIR is set)
|
|
217
218
|
* // macOS: null
|
|
218
219
|
* // Windows: null
|
|
@@ -223,12 +224,12 @@ export function runtimeDir(): string | null;
|
|
|
223
224
|
/**
|
|
224
225
|
* Returns the path to the user fonts directory.
|
|
225
226
|
* @example
|
|
226
|
-
* ```
|
|
227
|
-
*
|
|
228
|
-
*
|
|
227
|
+
* ```ts
|
|
228
|
+
* import { fontsDir } from 'os-user-dirs';
|
|
229
|
+
* const dir = fontsDir();
|
|
229
230
|
* // Linux: '/home/user/.local/share/fonts'
|
|
230
231
|
* // macOS: '/Users/user/Library/Fonts'
|
|
231
|
-
* // Windows: 'C
|
|
232
|
+
* // Windows: 'C:\\Users\\user\\AppData\\Local\\Microsoft\\Windows\\Fonts'
|
|
232
233
|
* ```
|
|
233
234
|
*/
|
|
234
235
|
export function fontsDir(): string;
|
|
@@ -239,12 +240,12 @@ export function fontsDir(): string;
|
|
|
239
240
|
* On macOS: `["/Library/Application Support", "/Library/Preferences"]`.
|
|
240
241
|
* On Windows: `[%PROGRAMDATA%]`.
|
|
241
242
|
* @example
|
|
242
|
-
* ```
|
|
243
|
-
*
|
|
244
|
-
*
|
|
243
|
+
* ```ts
|
|
244
|
+
* import { configDirs } from 'os-user-dirs';
|
|
245
|
+
* const dirs = configDirs();
|
|
245
246
|
* // Linux: ['/etc/xdg']
|
|
246
247
|
* // macOS: ['/Library/Application Support', '/Library/Preferences']
|
|
247
|
-
* // Windows: ['C
|
|
248
|
+
* // Windows: ['C:\\ProgramData']
|
|
248
249
|
* ```
|
|
249
250
|
*/
|
|
250
251
|
export function configDirs(): string[];
|
|
@@ -255,24 +256,25 @@ export function configDirs(): string[];
|
|
|
255
256
|
* On macOS: `["/Library/Application Support"]`.
|
|
256
257
|
* On Windows: `[%PROGRAMDATA%]`.
|
|
257
258
|
* @example
|
|
258
|
-
* ```
|
|
259
|
-
*
|
|
260
|
-
*
|
|
259
|
+
* ```ts
|
|
260
|
+
* import { dataDirs } from 'os-user-dirs';
|
|
261
|
+
* const dirs = dataDirs();
|
|
261
262
|
* // Linux: ['/usr/local/share', '/usr/share']
|
|
262
263
|
* // macOS: ['/Library/Application Support']
|
|
263
|
-
* // Windows: ['C
|
|
264
|
+
* // Windows: ['C:\\ProgramData']
|
|
264
265
|
* ```
|
|
265
266
|
*/
|
|
266
267
|
export function dataDirs(): string[];
|
|
267
268
|
|
|
268
269
|
/**
|
|
269
270
|
* Returns the path to the specified base directory.
|
|
271
|
+
* @param name - Base directory name to resolve
|
|
270
272
|
* @example
|
|
271
|
-
* ```
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
273
|
+
* ```ts
|
|
274
|
+
* import { getBasePath } from 'os-user-dirs';
|
|
275
|
+
* const config = getBasePath('config'); // '/home/user/.config'
|
|
276
|
+
* const data = getBasePath('data'); // '/home/user/.local/share'
|
|
277
|
+
* const runtime = getBasePath('runtime'); // '/run/user/1000' or null
|
|
276
278
|
* ```
|
|
277
279
|
*/
|
|
278
280
|
export function getBasePath(name: "config"): string;
|
|
@@ -303,23 +305,28 @@ interface ProjectDirsResult {
|
|
|
303
305
|
/**
|
|
304
306
|
* Returns application-scoped directories for the given app name.
|
|
305
307
|
* @param name - Application name used to derive directory paths
|
|
306
|
-
* @param options - Optional settings (e.g. suffix)
|
|
308
|
+
* @param options - Optional settings (e.g. vendor, suffix)
|
|
307
309
|
* @example
|
|
308
|
-
* ```
|
|
309
|
-
*
|
|
310
|
+
* ```ts
|
|
311
|
+
* import { projectDirs } from 'os-user-dirs';
|
|
310
312
|
* const dirs = projectDirs('my-app');
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
313
|
+
* // Linux: dirs.config => '/home/user/.config/my-app'
|
|
314
|
+
* // macOS: dirs.config => '/Users/user/Library/Application Support/my-app'
|
|
315
|
+
* // Windows: dirs.config => 'C:\\Users\\user\\AppData\\Local\\my-app\\Config'
|
|
314
316
|
* ```
|
|
315
317
|
* @example
|
|
316
|
-
* ```
|
|
318
|
+
* ```ts
|
|
317
319
|
* // With vendor option
|
|
318
320
|
* const dirs = projectDirs('my-app', { vendor: 'My Org' });
|
|
319
|
-
*
|
|
320
|
-
* //
|
|
321
|
-
* //
|
|
322
|
-
*
|
|
321
|
+
* // Linux: dirs.config => '/home/user/.config/my-org/my-app'
|
|
322
|
+
* // macOS: dirs.config => '/Users/user/Library/Application Support/My Org/my-app'
|
|
323
|
+
* // Windows: dirs.config => 'C:\\Users\\user\\AppData\\Local\\My Org\\my-app\\Config'
|
|
324
|
+
* ```
|
|
325
|
+
* @example
|
|
326
|
+
* ```ts
|
|
327
|
+
* // With suffix option
|
|
328
|
+
* const dirs = projectDirs('my-app', { suffix: '-beta' });
|
|
329
|
+
* // Linux: dirs.config => '/home/user/.config/my-app-beta'
|
|
323
330
|
* ```
|
|
324
331
|
*/
|
|
325
332
|
export function projectDirs(name: string, options?: ProjectDirsOptions): ProjectDirsResult;
|
|
@@ -340,12 +347,12 @@ interface ProjectUserDirsResult {
|
|
|
340
347
|
* Each value is the user directory path with the app name appended as a subdirectory.
|
|
341
348
|
* @param name - Application name used to derive directory paths
|
|
342
349
|
* @example
|
|
343
|
-
* ```
|
|
344
|
-
*
|
|
350
|
+
* ```ts
|
|
351
|
+
* import { projectUserDirs } from 'os-user-dirs';
|
|
345
352
|
* const dirs = projectUserDirs('my-app');
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
353
|
+
* // dirs.downloads => '/home/user/Downloads/my-app'
|
|
354
|
+
* // dirs.documents => '/home/user/Documents/my-app'
|
|
355
|
+
* // dirs.desktop => '/home/user/Desktop/my-app'
|
|
349
356
|
* ```
|
|
350
357
|
*/
|
|
351
358
|
export function projectUserDirs(name: string): ProjectUserDirsResult;
|
|
@@ -356,9 +363,9 @@ export function projectUserDirs(name: string): ProjectUserDirsResult;
|
|
|
356
363
|
* macOS: `~/.Trash`
|
|
357
364
|
* Windows: `null` (Recycle Bin requires Shell API)
|
|
358
365
|
* @example
|
|
359
|
-
* ```
|
|
360
|
-
*
|
|
361
|
-
*
|
|
366
|
+
* ```ts
|
|
367
|
+
* import { trashDir } from 'os-user-dirs';
|
|
368
|
+
* const dir = trashDir();
|
|
362
369
|
* // Linux: '/home/user/.local/share/Trash'
|
|
363
370
|
* // macOS: '/Users/user/.Trash'
|
|
364
371
|
* // Windows: null
|
|
@@ -372,12 +379,12 @@ export function trashDir(): string | null;
|
|
|
372
379
|
* macOS: `~/Applications`
|
|
373
380
|
* Windows: `%APPDATA%/Microsoft/Windows/Start Menu/Programs`
|
|
374
381
|
* @example
|
|
375
|
-
* ```
|
|
376
|
-
*
|
|
377
|
-
*
|
|
382
|
+
* ```ts
|
|
383
|
+
* import { applicationsDir } from 'os-user-dirs';
|
|
384
|
+
* const dir = applicationsDir();
|
|
378
385
|
* // Linux: '/home/user/.local/share/applications'
|
|
379
386
|
* // macOS: '/Users/user/Applications'
|
|
380
|
-
* // Windows: 'C
|
|
387
|
+
* // Windows: 'C:\\Users\\user\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs'
|
|
381
388
|
* ```
|
|
382
389
|
*/
|
|
383
390
|
export function applicationsDir(): string;
|
|
@@ -388,10 +395,10 @@ export function applicationsDir(): string;
|
|
|
388
395
|
* @param configPath - Optional path to user-dirs.dirs config file
|
|
389
396
|
* @returns The resolved directory path, or null if not found
|
|
390
397
|
* @example
|
|
391
|
-
* ```
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
398
|
+
* ```ts
|
|
399
|
+
* import { getXDGUserDir } from 'os-user-dirs';
|
|
400
|
+
* const dir = getXDGUserDir('XDG_DOWNLOAD_DIR'); // '/home/user/Downloads'
|
|
401
|
+
* const dir2 = getXDGUserDir('XDG_DESKTOP_DIR'); // '/home/user/Desktop'
|
|
395
402
|
* ```
|
|
396
403
|
*/
|
|
397
404
|
export function getXDGUserDir(key: string, configPath?: string): string | null;
|
|
@@ -401,10 +408,10 @@ export function getXDGUserDir(key: string, configPath?: string): string | null;
|
|
|
401
408
|
* @param dirPath - The directory path to ensure exists
|
|
402
409
|
* @returns The directory path
|
|
403
410
|
* @example
|
|
404
|
-
* ```
|
|
405
|
-
*
|
|
406
|
-
* const dir = ensureDirSync('/
|
|
407
|
-
*
|
|
411
|
+
* ```ts
|
|
412
|
+
* import { ensureDirSync, configDir } from 'os-user-dirs';
|
|
413
|
+
* const dir = ensureDirSync(configDir() + '/my-app');
|
|
414
|
+
* // Creates the directory if it doesn't exist and returns the path
|
|
408
415
|
* ```
|
|
409
416
|
*/
|
|
410
417
|
export function ensureDirSync(dirPath: string): string;
|
|
@@ -414,10 +421,10 @@ export function ensureDirSync(dirPath: string): string;
|
|
|
414
421
|
* @param dirPath - The directory path to ensure exists
|
|
415
422
|
* @returns A promise that resolves with the directory path
|
|
416
423
|
* @example
|
|
417
|
-
* ```
|
|
418
|
-
*
|
|
419
|
-
* const dir = await ensureDir('/
|
|
420
|
-
*
|
|
424
|
+
* ```ts
|
|
425
|
+
* import { ensureDir, cacheDir } from 'os-user-dirs';
|
|
426
|
+
* const dir = await ensureDir(cacheDir() + '/my-app');
|
|
427
|
+
* // Creates the directory if it doesn't exist and returns the path
|
|
421
428
|
* ```
|
|
422
429
|
*/
|
|
423
430
|
export function ensureDir(dirPath: string): Promise<string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "os-user-dirs",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Get OS-specific user directories and XDG base directories (config, data, cache, runtime) with zero dependencies.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
"keywords": [
|
|
28
28
|
"os",
|
|
29
29
|
"directories",
|
|
30
|
+
"user-dirs",
|
|
31
|
+
"user-directories",
|
|
30
32
|
"downloads",
|
|
31
33
|
"desktop",
|
|
32
34
|
"documents",
|
|
@@ -35,23 +37,31 @@
|
|
|
35
37
|
"videos",
|
|
36
38
|
"templates",
|
|
37
39
|
"public",
|
|
40
|
+
"home-dir",
|
|
38
41
|
"config",
|
|
39
42
|
"data",
|
|
40
43
|
"cache",
|
|
44
|
+
"state",
|
|
45
|
+
"runtime",
|
|
41
46
|
"xdg",
|
|
42
|
-
"user-dirs",
|
|
43
|
-
"platform-folders",
|
|
44
|
-
"env-paths",
|
|
45
47
|
"xdg-basedir",
|
|
46
|
-
"appdata-path",
|
|
47
48
|
"xdg-base-directory",
|
|
48
|
-
"
|
|
49
|
-
"app-paths",
|
|
49
|
+
"freedesktop",
|
|
50
50
|
"config-dir",
|
|
51
51
|
"data-dir",
|
|
52
52
|
"cache-dir",
|
|
53
|
+
"state-dir",
|
|
54
|
+
"runtime-dir",
|
|
55
|
+
"log-dir",
|
|
53
56
|
"downloads-dir",
|
|
54
57
|
"desktop-dir",
|
|
58
|
+
"fonts-dir",
|
|
59
|
+
"trash-dir",
|
|
60
|
+
"project-dirs",
|
|
61
|
+
"app-paths",
|
|
62
|
+
"env-paths",
|
|
63
|
+
"platform-folders",
|
|
64
|
+
"appdata-path",
|
|
55
65
|
"cross-platform",
|
|
56
66
|
"linux",
|
|
57
67
|
"macos",
|