os-user-dirs 3.0.1 → 3.2.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 +87 -3
- package/index.d.ts +233 -118
- package/index.js +61 -0
- package/index.mjs +4 -0
- package/package.json +18 -7
package/README.md
CHANGED
|
@@ -3,12 +3,14 @@
|
|
|
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
|
|
|
9
11
|
> All-in-one OS directory paths — user directories, XDG base directories, and app-scoped project directories — with zero dependencies.
|
|
10
12
|
|
|
11
|
-
- Node.js 20
|
|
13
|
+
- Node.js 20+, Deno 2+, Bun 1+
|
|
12
14
|
|
|
13
15
|
Replaces [`env-paths`](https://github.com/sindresorhus/env-paths), [`xdg-basedir`](https://github.com/sindresorhus/xdg-basedir), and [`platform-folders`](https://github.com/nicbarker/platform-folders) in a single package. CJS + ESM dual support, TypeScript included.
|
|
14
16
|
|
|
@@ -27,6 +29,7 @@ Replaces [`env-paths`](https://github.com/sindresorhus/env-paths), [`xdg-basedir
|
|
|
27
29
|
| XDG search paths | **Yes** | - | **Yes** | - |
|
|
28
30
|
| Project directories | **Yes** | **Yes** | - | - |
|
|
29
31
|
| CJS + ESM | **Both** | ESM only (v3) | ESM only (v5) | CJS |
|
|
32
|
+
| Deno / Bun | **Yes** | - | - | - |
|
|
30
33
|
| TypeScript | **Included** | Included | Included | - |
|
|
31
34
|
|
|
32
35
|
## Install
|
|
@@ -35,7 +38,7 @@ Replaces [`env-paths`](https://github.com/sindresorhus/env-paths), [`xdg-basedir
|
|
|
35
38
|
$ npm install os-user-dirs
|
|
36
39
|
```
|
|
37
40
|
|
|
38
|
-
Requires Node.js 20 or later. Works on Windows, macOS, and Linux.
|
|
41
|
+
Requires Node.js 20 or later. Works on Windows, macOS, and Linux. Also compatible with [Deno](https://deno.land/) and [Bun](https://bun.sh/).
|
|
39
42
|
|
|
40
43
|
## Quick Start
|
|
41
44
|
|
|
@@ -66,6 +69,25 @@ CommonJS is also supported:
|
|
|
66
69
|
const { downloads, configDir, projectDirs } = require("os-user-dirs");
|
|
67
70
|
```
|
|
68
71
|
|
|
72
|
+
### Deno
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { downloads, configDir } from "npm:os-user-dirs";
|
|
76
|
+
|
|
77
|
+
downloads(); //=> '/home/user/Downloads'
|
|
78
|
+
configDir(); //=> '/home/user/.config'
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Bun
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
import { downloads, configDir } from "os-user-dirs";
|
|
85
|
+
// or: const { downloads, configDir } = require("os-user-dirs");
|
|
86
|
+
|
|
87
|
+
downloads(); //=> '/home/user/Downloads'
|
|
88
|
+
configDir(); //=> '/home/user/.config'
|
|
89
|
+
```
|
|
90
|
+
|
|
69
91
|
### TypeScript
|
|
70
92
|
|
|
71
93
|
Full type definitions are included. `getPath()` accepts a union type for auto-completion:
|
|
@@ -153,6 +175,25 @@ Returns the path to the user fonts directory (`~/.local/share/fonts` on Linux, `
|
|
|
153
175
|
|
|
154
176
|
#### `getBasePath(name)`
|
|
155
177
|
Returns the path to the specified base directory. Valid names: `config`, `data`, `cache`, `state`, `log`, `runtime`.
|
|
178
|
+
|
|
179
|
+
## Which function should I use?
|
|
180
|
+
|
|
181
|
+
| Use case | Function |
|
|
182
|
+
|---|---|
|
|
183
|
+
| Store app config files | `configDir()` or `projectDirs("my-app").config` |
|
|
184
|
+
| Store app data / databases | `dataDir()` or `projectDirs("my-app").data` |
|
|
185
|
+
| Store app cache | `cacheDir()` or `projectDirs("my-app").cache` |
|
|
186
|
+
| Store app logs | `logDir()` or `projectDirs("my-app").log` |
|
|
187
|
+
| Get user's Downloads folder | `downloads()` |
|
|
188
|
+
| Get user's Documents folder | `documents()` |
|
|
189
|
+
| Get all app-scoped dirs at once | `projectDirs("my-app")` |
|
|
190
|
+
| Dump all directory paths | `getAllDirs()` |
|
|
191
|
+
| Find system-wide config locations | `configDirs()` |
|
|
192
|
+
| Ensure a directory exists | `ensureDir(path)` / `ensureDirSync(path)` |
|
|
193
|
+
| Get user's home directory | `homeDir()` |
|
|
194
|
+
|
|
195
|
+
> For the full API with platform-specific details, see the **[API Reference](docs/api.md)**.
|
|
196
|
+
|
|
156
197
|
## API Overview
|
|
157
198
|
|
|
158
199
|
### User Directories
|
|
@@ -226,10 +267,44 @@ const dirs = projectUserDirs("my-app");
|
|
|
226
267
|
dirs.downloads //=> '/home/user/Downloads/my-app'
|
|
227
268
|
```
|
|
228
269
|
|
|
270
|
+
### Namespace Exports
|
|
271
|
+
|
|
272
|
+
For better organization, functions are also available via namespace objects:
|
|
273
|
+
|
|
274
|
+
```javascript
|
|
275
|
+
import { user, base, project } from "os-user-dirs";
|
|
276
|
+
|
|
277
|
+
// User directories
|
|
278
|
+
user.downloads() //=> '/home/user/Downloads'
|
|
279
|
+
user.desktop() //=> '/home/user/Desktop'
|
|
280
|
+
user.homeDir() //=> '/home/user'
|
|
281
|
+
|
|
282
|
+
// XDG base directories
|
|
283
|
+
base.configDir() //=> '/home/user/.config'
|
|
284
|
+
base.dataDir() //=> '/home/user/.local/share'
|
|
285
|
+
base.configDirs() //=> ['/etc/xdg']
|
|
286
|
+
|
|
287
|
+
// Project directories
|
|
288
|
+
const dirs = project.dirs("my-app");
|
|
289
|
+
dirs.config //=> '/home/user/.config/my-app'
|
|
290
|
+
|
|
291
|
+
const userDirs = project.userDirs("my-app");
|
|
292
|
+
userDirs.downloads //=> '/home/user/Downloads/my-app'
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
| Namespace | Functions |
|
|
296
|
+
|---|---|
|
|
297
|
+
| `user` | `desktop`, `downloads`, `documents`, `music`, `pictures`, `videos`, `templates`, `publicshare`, `homeDir`, `binDir`, `fontsDir`, `trashDir`, `applicationsDir` |
|
|
298
|
+
| `base` | `configDir`, `dataDir`, `cacheDir`, `stateDir`, `logDir`, `runtimeDir`, `configDirs`, `dataDirs` |
|
|
299
|
+
| `project` | `dirs` (= `projectDirs`), `userDirs` (= `projectUserDirs`) |
|
|
300
|
+
|
|
301
|
+
All flat exports remain available for backward compatibility.
|
|
302
|
+
|
|
229
303
|
### Utilities
|
|
230
304
|
|
|
231
305
|
| Function | Description |
|
|
232
306
|
|---|---|
|
|
307
|
+
| `getAllDirs()` | Returns all directory paths as a single object |
|
|
233
308
|
| `ensureDirSync(dirPath)` | Creates directory recursively if needed (sync) |
|
|
234
309
|
| `ensureDir(dirPath)` | Creates directory recursively if needed (async) |
|
|
235
310
|
| `getXDGUserDir(key)` | Parse XDG user-dirs.dirs config |
|
|
@@ -251,9 +326,10 @@ getBasePath("unknown"); // Type error
|
|
|
251
326
|
## Integration guides
|
|
252
327
|
|
|
253
328
|
- **[Electron Guide](docs/guide-electron.md)** — Using os-user-dirs in Electron apps: `app.getPath()` mapping, main/renderer process patterns, vendor-scoped directories
|
|
329
|
+
- **[Tauri Guide](docs/guide-tauri.md)** — Using os-user-dirs in Tauri apps: path API mapping, sidecar patterns, shared config with CLI companions
|
|
330
|
+
- **[VS Code Extension Guide](docs/guide-vscode-extension.md)** — Using os-user-dirs in VS Code extensions: `globalStorageUri` comparison, file export patterns, shared config with CLI tools
|
|
254
331
|
- **[CLI Tools Guide](docs/guide-cli-tools.md)** — Using `projectDirs()` with commander, yargs, and oclif for config, cache, and log management
|
|
255
332
|
|
|
256
|
-
## Migration from xdg-basedir
|
|
257
333
|
## Migration Guides
|
|
258
334
|
|
|
259
335
|
Switching from another library? We have you covered:
|
|
@@ -286,6 +362,14 @@ downloads(); // recommended: cross-platform Downloa
|
|
|
286
362
|
getXDGUserDir("XDG_DOWNLOAD_DIR"); // direct replacement if you need XDG config parsing
|
|
287
363
|
```
|
|
288
364
|
|
|
365
|
+
## Contributing
|
|
366
|
+
|
|
367
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, coding conventions, and pull request guidelines.
|
|
368
|
+
|
|
369
|
+
## Security
|
|
370
|
+
|
|
371
|
+
See [SECURITY.md](SECURITY.md) for the security policy and vulnerability reporting instructions.
|
|
372
|
+
|
|
289
373
|
## License
|
|
290
374
|
|
|
291
375
|
MIT
|
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,14 +421,118 @@ 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>;
|
|
424
431
|
|
|
432
|
+
interface GetAllDirsResult {
|
|
433
|
+
downloads: string;
|
|
434
|
+
desktop: string;
|
|
435
|
+
documents: string;
|
|
436
|
+
music: string;
|
|
437
|
+
pictures: string;
|
|
438
|
+
videos: string;
|
|
439
|
+
templates: string;
|
|
440
|
+
publicshare: string;
|
|
441
|
+
configDir: string;
|
|
442
|
+
dataDir: string;
|
|
443
|
+
cacheDir: string;
|
|
444
|
+
stateDir: string;
|
|
445
|
+
logDir: string;
|
|
446
|
+
runtimeDir: string | null;
|
|
447
|
+
fontsDir: string;
|
|
448
|
+
binDir: string | null;
|
|
449
|
+
applicationsDir: string;
|
|
450
|
+
trashDir: string | null;
|
|
451
|
+
homeDir: string;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Returns all directory paths as a single object.
|
|
456
|
+
* Useful for debugging, configuration dumps, or diagnostics.
|
|
457
|
+
* Does not include array-returning functions (`configDirs`, `dataDirs`)
|
|
458
|
+
* or functions requiring arguments (`projectDirs`, `projectUserDirs`).
|
|
459
|
+
* @example
|
|
460
|
+
* ```ts
|
|
461
|
+
* import { getAllDirs } from 'os-user-dirs';
|
|
462
|
+
* const dirs = getAllDirs();
|
|
463
|
+
* console.log(dirs.downloads); // '/home/user/Downloads'
|
|
464
|
+
* console.log(dirs.configDir); // '/home/user/.config'
|
|
465
|
+
* console.log(dirs.homeDir); // '/home/user'
|
|
466
|
+
* ```
|
|
467
|
+
*/
|
|
468
|
+
export function getAllDirs(): GetAllDirsResult;
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Namespace grouping user directory functions.
|
|
472
|
+
* Provides organized access to user-specific directory functions.
|
|
473
|
+
* @example
|
|
474
|
+
* ```ts
|
|
475
|
+
* import { user } from 'os-user-dirs';
|
|
476
|
+
* user.downloads(); // '/home/user/Downloads'
|
|
477
|
+
* user.desktop(); // '/home/user/Desktop'
|
|
478
|
+
* user.homeDir(); // '/home/user'
|
|
479
|
+
* ```
|
|
480
|
+
*/
|
|
481
|
+
export const user: {
|
|
482
|
+
desktop: typeof desktop;
|
|
483
|
+
downloads: typeof downloads;
|
|
484
|
+
documents: typeof documents;
|
|
485
|
+
music: typeof music;
|
|
486
|
+
pictures: typeof pictures;
|
|
487
|
+
videos: typeof videos;
|
|
488
|
+
templates: typeof templates;
|
|
489
|
+
publicshare: typeof publicshare;
|
|
490
|
+
homeDir: typeof homeDir;
|
|
491
|
+
binDir: typeof binDir;
|
|
492
|
+
fontsDir: typeof fontsDir;
|
|
493
|
+
trashDir: typeof trashDir;
|
|
494
|
+
applicationsDir: typeof applicationsDir;
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Namespace grouping XDG base directory functions.
|
|
499
|
+
* Provides organized access to base directory and search path functions.
|
|
500
|
+
* @example
|
|
501
|
+
* ```ts
|
|
502
|
+
* import { base } from 'os-user-dirs';
|
|
503
|
+
* base.configDir(); // '/home/user/.config'
|
|
504
|
+
* base.dataDir(); // '/home/user/.local/share'
|
|
505
|
+
* base.configDirs(); // ['/etc/xdg']
|
|
506
|
+
* ```
|
|
507
|
+
*/
|
|
508
|
+
export const base: {
|
|
509
|
+
configDir: typeof configDir;
|
|
510
|
+
dataDir: typeof dataDir;
|
|
511
|
+
cacheDir: typeof cacheDir;
|
|
512
|
+
stateDir: typeof stateDir;
|
|
513
|
+
logDir: typeof logDir;
|
|
514
|
+
runtimeDir: typeof runtimeDir;
|
|
515
|
+
configDirs: typeof configDirs;
|
|
516
|
+
dataDirs: typeof dataDirs;
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Namespace grouping project-scoped directory functions.
|
|
521
|
+
* Provides organized access to application-scoped directory functions.
|
|
522
|
+
* @example
|
|
523
|
+
* ```ts
|
|
524
|
+
* import { project } from 'os-user-dirs';
|
|
525
|
+
* const dirs = project.dirs('my-app');
|
|
526
|
+
* dirs.config; // '/home/user/.config/my-app'
|
|
527
|
+
* const userDirs = project.userDirs('my-app');
|
|
528
|
+
* userDirs.downloads; // '/home/user/Downloads/my-app'
|
|
529
|
+
* ```
|
|
530
|
+
*/
|
|
531
|
+
export const project: {
|
|
532
|
+
dirs: typeof projectDirs;
|
|
533
|
+
userDirs: typeof projectUserDirs;
|
|
534
|
+
};
|
|
535
|
+
|
|
425
536
|
declare const osUserDirs: typeof downloads & {
|
|
426
537
|
downloads: typeof downloads;
|
|
427
538
|
desktop: typeof desktop;
|
|
@@ -451,6 +562,10 @@ declare const osUserDirs: typeof downloads & {
|
|
|
451
562
|
getXDGUserDir: typeof getXDGUserDir;
|
|
452
563
|
ensureDirSync: typeof ensureDirSync;
|
|
453
564
|
ensureDir: typeof ensureDir;
|
|
565
|
+
getAllDirs: typeof getAllDirs;
|
|
566
|
+
user: typeof user;
|
|
567
|
+
base: typeof base;
|
|
568
|
+
project: typeof project;
|
|
454
569
|
};
|
|
455
570
|
|
|
456
571
|
export default osUserDirs;
|
package/index.js
CHANGED
|
@@ -374,6 +374,30 @@ function homeDir() {
|
|
|
374
374
|
return os.homedir();
|
|
375
375
|
}
|
|
376
376
|
|
|
377
|
+
function getAllDirs() {
|
|
378
|
+
return {
|
|
379
|
+
downloads: downloads(),
|
|
380
|
+
desktop: desktop(),
|
|
381
|
+
documents: documents(),
|
|
382
|
+
music: music(),
|
|
383
|
+
pictures: pictures(),
|
|
384
|
+
videos: videos(),
|
|
385
|
+
templates: templates(),
|
|
386
|
+
publicshare: publicshare(),
|
|
387
|
+
configDir: configDir(),
|
|
388
|
+
dataDir: dataDir(),
|
|
389
|
+
cacheDir: cacheDir(),
|
|
390
|
+
stateDir: stateDir(),
|
|
391
|
+
logDir: logDir(),
|
|
392
|
+
runtimeDir: runtimeDir(),
|
|
393
|
+
fontsDir: fontsDir(),
|
|
394
|
+
binDir: binDir(),
|
|
395
|
+
applicationsDir: applicationsDir(),
|
|
396
|
+
trashDir: trashDir(),
|
|
397
|
+
homeDir: homeDir(),
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
|
|
377
401
|
function ensureDirSync(dirPath) {
|
|
378
402
|
if (!dirPath || typeof dirPath !== "string") {
|
|
379
403
|
throw new Error("ensureDirSync requires a non-empty string path");
|
|
@@ -391,6 +415,39 @@ function ensureDir(dirPath) {
|
|
|
391
415
|
});
|
|
392
416
|
}
|
|
393
417
|
|
|
418
|
+
// Namespace exports
|
|
419
|
+
const user = {
|
|
420
|
+
desktop: desktop,
|
|
421
|
+
downloads: downloads,
|
|
422
|
+
documents: documents,
|
|
423
|
+
music: music,
|
|
424
|
+
pictures: pictures,
|
|
425
|
+
videos: videos,
|
|
426
|
+
templates: templates,
|
|
427
|
+
publicshare: publicshare,
|
|
428
|
+
homeDir: homeDir,
|
|
429
|
+
binDir: binDir,
|
|
430
|
+
fontsDir: fontsDir,
|
|
431
|
+
trashDir: trashDir,
|
|
432
|
+
applicationsDir: applicationsDir,
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
const base = {
|
|
436
|
+
configDir: configDir,
|
|
437
|
+
dataDir: dataDir,
|
|
438
|
+
cacheDir: cacheDir,
|
|
439
|
+
stateDir: stateDir,
|
|
440
|
+
logDir: logDir,
|
|
441
|
+
runtimeDir: runtimeDir,
|
|
442
|
+
configDirs: configDirs,
|
|
443
|
+
dataDirs: dataDirs,
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
const project = {
|
|
447
|
+
dirs: projectDirs,
|
|
448
|
+
userDirs: projectUserDirs,
|
|
449
|
+
};
|
|
450
|
+
|
|
394
451
|
// Backward compatibility: require("os-user-dirs")() returns Downloads path
|
|
395
452
|
module.exports = downloads;
|
|
396
453
|
module.exports.getPath = getPath;
|
|
@@ -421,3 +478,7 @@ module.exports.getXDGUserDir = getXDGUserDir;
|
|
|
421
478
|
module.exports.ensureDirSync = ensureDirSync;
|
|
422
479
|
module.exports.trashDir = trashDir;
|
|
423
480
|
module.exports.ensureDir = ensureDir;
|
|
481
|
+
module.exports.getAllDirs = getAllDirs;
|
|
482
|
+
module.exports.user = user;
|
|
483
|
+
module.exports.base = base;
|
|
484
|
+
module.exports.project = project;
|
package/index.mjs
CHANGED
|
@@ -29,3 +29,7 @@ export const getXDGUserDir = osUserDirs.getXDGUserDir;
|
|
|
29
29
|
export const trashDir = osUserDirs.trashDir;
|
|
30
30
|
export const ensureDirSync = osUserDirs.ensureDirSync;
|
|
31
31
|
export const ensureDir = osUserDirs.ensureDir;
|
|
32
|
+
export const getAllDirs = osUserDirs.getAllDirs;
|
|
33
|
+
export const user = osUserDirs.user;
|
|
34
|
+
export const base = osUserDirs.base;
|
|
35
|
+
export const project = osUserDirs.project;
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "os-user-dirs",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.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
|
+
"type": "commonjs",
|
|
6
7
|
"types": "index.d.ts",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": {
|
|
@@ -27,6 +28,8 @@
|
|
|
27
28
|
"keywords": [
|
|
28
29
|
"os",
|
|
29
30
|
"directories",
|
|
31
|
+
"user-dirs",
|
|
32
|
+
"user-directories",
|
|
30
33
|
"downloads",
|
|
31
34
|
"desktop",
|
|
32
35
|
"documents",
|
|
@@ -35,23 +38,31 @@
|
|
|
35
38
|
"videos",
|
|
36
39
|
"templates",
|
|
37
40
|
"public",
|
|
41
|
+
"home-dir",
|
|
38
42
|
"config",
|
|
39
43
|
"data",
|
|
40
44
|
"cache",
|
|
45
|
+
"state",
|
|
46
|
+
"runtime",
|
|
41
47
|
"xdg",
|
|
42
|
-
"user-dirs",
|
|
43
|
-
"platform-folders",
|
|
44
|
-
"env-paths",
|
|
45
48
|
"xdg-basedir",
|
|
46
|
-
"appdata-path",
|
|
47
49
|
"xdg-base-directory",
|
|
48
|
-
"
|
|
49
|
-
"app-paths",
|
|
50
|
+
"freedesktop",
|
|
50
51
|
"config-dir",
|
|
51
52
|
"data-dir",
|
|
52
53
|
"cache-dir",
|
|
54
|
+
"state-dir",
|
|
55
|
+
"runtime-dir",
|
|
56
|
+
"log-dir",
|
|
53
57
|
"downloads-dir",
|
|
54
58
|
"desktop-dir",
|
|
59
|
+
"fonts-dir",
|
|
60
|
+
"trash-dir",
|
|
61
|
+
"project-dirs",
|
|
62
|
+
"app-paths",
|
|
63
|
+
"env-paths",
|
|
64
|
+
"platform-folders",
|
|
65
|
+
"appdata-path",
|
|
55
66
|
"cross-platform",
|
|
56
67
|
"linux",
|
|
57
68
|
"macos",
|