os-user-dirs 2.4.0 → 2.6.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 CHANGED
@@ -66,6 +66,22 @@ getBasePath("config");
66
66
  //=> '/home/user/.config'
67
67
  ```
68
68
 
69
+ #### System search directories
70
+
71
+ ```javascript
72
+ import { configDirs, dataDirs } from "os-user-dirs";
73
+
74
+ configDirs();
75
+ //=> ['/etc/xdg'] (Linux)
76
+ //=> ['/Library/Application Support', '/Library/Preferences'] (macOS)
77
+ //=> ['C:\\ProgramData'] (Windows)
78
+
79
+ dataDirs();
80
+ //=> ['/usr/local/share', '/usr/share'] (Linux)
81
+ //=> ['/Library/Application Support'] (macOS)
82
+ //=> ['C:\\ProgramData'] (Windows)
83
+ ```
84
+
69
85
  #### Project directories
70
86
 
71
87
  ```javascript
@@ -149,6 +165,15 @@ Returns the path to the Public Share directory.
149
165
  ### `getPath(name)`
150
166
  Returns the path to the specified user directory. Valid names: `desktop`, `downloads`, `documents`, `music`, `pictures`, `videos`, `templates`, `publicshare`.
151
167
 
168
+ ### `binDir()`
169
+ Returns the path to the user local bin directory (`~/.local/bin` on Linux/macOS), or `null` on Windows.
170
+
171
+ ### `applicationsDir()`
172
+ Returns the path to the user applications directory.
173
+ - Linux: `$XDG_DATA_HOME/applications` (default `~/.local/share/applications`)
174
+ - macOS: `~/Applications`
175
+ - Windows: `%APPDATA%\Microsoft\Windows\Start Menu\Programs`
176
+
152
177
  ### Base Directories
153
178
 
154
179
  #### `configDir()`
@@ -169,9 +194,20 @@ Returns the path to the log directory (`~/.local/state` on Linux, `~/Library/Log
169
194
  #### `runtimeDir()`
170
195
  Returns the path to the runtime directory (`$XDG_RUNTIME_DIR` on Linux), or `null` if unavailable.
171
196
 
197
+ #### `fontsDir()`
198
+ Returns the path to the user fonts directory (`~/.local/share/fonts` on Linux, `~/Library/Fonts` on macOS, `%LOCALAPPDATA%/Microsoft/Windows/Fonts` on Windows). On Linux, respects `$XDG_DATA_HOME`.
199
+
172
200
  #### `getBasePath(name)`
173
201
  Returns the path to the specified base directory. Valid names: `config`, `data`, `cache`, `state`, `log`, `runtime`.
174
202
 
203
+ ### System Search Directories
204
+
205
+ #### `configDirs()`
206
+ Returns the system config directory search path list (`string[]`). On Linux, reads `$XDG_CONFIG_DIRS` (default: `["/etc/xdg"]`). On macOS: `["/Library/Application Support", "/Library/Preferences"]`. On Windows: `[%PROGRAMDATA%]`.
207
+
208
+ #### `dataDirs()`
209
+ Returns the system data directory search path list (`string[]`). On Linux, reads `$XDG_DATA_DIRS` (default: `["/usr/local/share", "/usr/share"]`). On macOS: `["/Library/Application Support"]`. On Windows: `[%PROGRAMDATA%]`.
210
+
175
211
  ### Project Directories
176
212
 
177
213
  #### `projectDirs(name, options?)`
package/index.d.ts CHANGED
@@ -27,6 +27,9 @@ export function publicshare(): string;
27
27
  /** Returns the path to the specified user directory. */
28
28
  export function getPath(name: DirName): string;
29
29
 
30
+ /** Returns the path to the user local bin directory (~/.local/bin), or null on Windows. */
31
+ export function binDir(): string | null;
32
+
30
33
  type BaseDirName = "config" | "data" | "cache" | "state" | "log" | "runtime";
31
34
 
32
35
  /** Returns the path to the XDG config directory. */
@@ -47,6 +50,25 @@ export function logDir(): string;
47
50
  /** Returns the path to the XDG runtime directory, or null if unavailable. */
48
51
  export function runtimeDir(): string | null;
49
52
 
53
+ /** Returns the path to the user fonts directory. */
54
+ export function fontsDir(): string;
55
+
56
+ /**
57
+ * Returns the system config directory search path list.
58
+ * On Linux, reads `$XDG_CONFIG_DIRS` (default: `["/etc/xdg"]`).
59
+ * On macOS: `["/Library/Application Support", "/Library/Preferences"]`.
60
+ * On Windows: `[%PROGRAMDATA%]`.
61
+ */
62
+ export function configDirs(): string[];
63
+
64
+ /**
65
+ * Returns the system data directory search path list.
66
+ * On Linux, reads `$XDG_DATA_DIRS` (default: `["/usr/local/share", "/usr/share"]`).
67
+ * On macOS: `["/Library/Application Support"]`.
68
+ * On Windows: `[%PROGRAMDATA%]`.
69
+ */
70
+ export function dataDirs(): string[];
71
+
50
72
  /** Returns the path to the specified base directory. */
51
73
  export function getBasePath(name: "config"): string;
52
74
  export function getBasePath(name: "data"): string;
@@ -78,6 +100,14 @@ interface ProjectDirsResult {
78
100
  */
79
101
  export function projectDirs(name: string, options?: ProjectDirsOptions): ProjectDirsResult;
80
102
 
103
+ /**
104
+ * Returns the path to the user applications directory.
105
+ * Linux: `$XDG_DATA_HOME/applications` (default `~/.local/share/applications`)
106
+ * macOS: `~/Applications`
107
+ * Windows: `%APPDATA%/Microsoft/Windows/Start Menu/Programs`
108
+ */
109
+ export function applicationsDir(): string;
110
+
81
111
  /**
82
112
  * Reads an XDG user-dirs.dirs config and returns the directory for the given key.
83
113
  * @param key - XDG key (e.g. "XDG_DOWNLOAD_DIR")
@@ -101,14 +131,19 @@ declare const osUserDirs: typeof downloads & {
101
131
  templates: typeof templates;
102
132
  publicshare: typeof publicshare;
103
133
  getPath: typeof getPath;
134
+ binDir: typeof binDir;
104
135
  configDir: typeof configDir;
105
136
  dataDir: typeof dataDir;
106
137
  cacheDir: typeof cacheDir;
107
138
  stateDir: typeof stateDir;
108
139
  logDir: typeof logDir;
109
140
  runtimeDir: typeof runtimeDir;
141
+ fontsDir: typeof fontsDir;
110
142
  getBasePath: typeof getBasePath;
143
+ configDirs: typeof configDirs;
144
+ dataDirs: typeof dataDirs;
111
145
  projectDirs: typeof projectDirs;
146
+ applicationsDir: typeof applicationsDir;
112
147
  getXDGUserDir: typeof getXDGUserDir;
113
148
  getXDGDownloadDir: typeof getXDGDownloadDir;
114
149
  };
package/index.js CHANGED
@@ -137,6 +137,13 @@ function resolveBase(name) {
137
137
  return cfg.linux ? path.join(homedir, cfg.linux) : null;
138
138
  }
139
139
 
140
+ function binDir() {
141
+ if (process.platform === "win32") {
142
+ return null;
143
+ }
144
+ return path.join(os.homedir(), ".local", "bin");
145
+ }
146
+
140
147
  function configDir() { return resolveBase("config"); }
141
148
  function dataDir() { return resolveBase("data"); }
142
149
  function cacheDir() { return resolveBase("cache"); }
@@ -144,6 +151,84 @@ function stateDir() { return resolveBase("state"); }
144
151
  function logDir() { return resolveBase("log"); }
145
152
  function runtimeDir() { return resolveBase("runtime"); }
146
153
 
154
+ function fontsDir() {
155
+ var platform = process.platform;
156
+ var homedir = os.homedir();
157
+
158
+ if (platform === "linux") {
159
+ var envVal = process.env.XDG_DATA_HOME;
160
+ if (envVal) {
161
+ return path.join(path.resolve(envVal), "fonts");
162
+ }
163
+ return path.join(homedir, ".local", "share", "fonts");
164
+ }
165
+
166
+ if (platform === "darwin") {
167
+ return path.join(homedir, "Library", "Fonts");
168
+ }
169
+
170
+ if (platform === "win32") {
171
+ var localAppData = process.env.LOCALAPPDATA || path.join(homedir, "AppData", "Local");
172
+ return path.join(localAppData, "Microsoft", "Windows", "Fonts");
173
+ }
174
+
175
+ // Unknown platform: use XDG-style default
176
+ return path.join(homedir, ".local", "share", "fonts");
177
+ }
178
+
179
+ const SEARCH_DIRS_CONFIG = {
180
+ config: {
181
+ env: "XDG_CONFIG_DIRS",
182
+ linux: ["/etc/xdg"],
183
+ darwin: ["/Library/Application Support", "/Library/Preferences"],
184
+ win32: "PROGRAMDATA",
185
+ },
186
+ data: {
187
+ env: "XDG_DATA_DIRS",
188
+ linux: ["/usr/local/share", "/usr/share"],
189
+ darwin: ["/Library/Application Support"],
190
+ win32: "PROGRAMDATA",
191
+ },
192
+ };
193
+
194
+ function resolveSearchDirs(name) {
195
+ const cfg = SEARCH_DIRS_CONFIG[name];
196
+ if (!cfg) {
197
+ throw new Error("Unknown search directory: " + name + ". Valid names: " + Object.keys(SEARCH_DIRS_CONFIG).join(", "));
198
+ }
199
+
200
+ const platform = process.platform;
201
+
202
+ if (platform === "linux") {
203
+ const envVal = process.env[cfg.env];
204
+ if (envVal) {
205
+ const dirs = envVal.split(":").filter(Boolean);
206
+ if (dirs.length > 0) {
207
+ return dirs.map(function (d) { return path.resolve(d); });
208
+ }
209
+ }
210
+ return cfg.linux.slice();
211
+ }
212
+
213
+ if (platform === "darwin") {
214
+ return cfg.darwin.slice();
215
+ }
216
+
217
+ if (platform === "win32") {
218
+ const winVal = process.env[cfg.win32];
219
+ if (winVal) {
220
+ return [path.resolve(winVal)];
221
+ }
222
+ return [path.join(process.env.SYSTEMDRIVE || "C:", "ProgramData")];
223
+ }
224
+
225
+ // Unknown platform: use Linux defaults
226
+ return cfg.linux.slice();
227
+ }
228
+
229
+ function configDirs() { return resolveSearchDirs("config"); }
230
+ function dataDirs() { return resolveSearchDirs("data"); }
231
+
147
232
  function getBasePath(name) {
148
233
  return resolveBase(name);
149
234
  }
@@ -208,6 +293,29 @@ function projectDirs(name, options) {
208
293
  };
209
294
  }
210
295
 
296
+ function applicationsDir() {
297
+ var homedir = os.homedir();
298
+ var platform = process.platform;
299
+
300
+ if (platform === "linux") {
301
+ var envVal = process.env.XDG_DATA_HOME;
302
+ var base = envVal ? path.resolve(envVal) : path.join(homedir, ".local", "share");
303
+ return path.join(base, "applications");
304
+ }
305
+
306
+ if (platform === "darwin") {
307
+ return path.join(homedir, "Applications");
308
+ }
309
+
310
+ if (platform === "win32") {
311
+ var appdata = process.env.APPDATA || path.join(homedir, "AppData", "Roaming");
312
+ return path.join(appdata, "Microsoft", "Windows", "Start Menu", "Programs");
313
+ }
314
+
315
+ // Unknown platform: use XDG-style default
316
+ return path.join(homedir, ".local", "share", "applications");
317
+ }
318
+
211
319
  // Backward compatibility: require("os-user-dirs")() returns Downloads path
212
320
  module.exports = downloads;
213
321
  module.exports.getPath = getPath;
@@ -219,14 +327,19 @@ module.exports.pictures = pictures;
219
327
  module.exports.videos = videos;
220
328
  module.exports.templates = templates;
221
329
  module.exports.publicshare = publicshare;
330
+ module.exports.binDir = binDir;
222
331
  module.exports.configDir = configDir;
223
332
  module.exports.dataDir = dataDir;
224
333
  module.exports.cacheDir = cacheDir;
225
334
  module.exports.stateDir = stateDir;
226
335
  module.exports.logDir = logDir;
227
336
  module.exports.runtimeDir = runtimeDir;
337
+ module.exports.fontsDir = fontsDir;
228
338
  module.exports.getBasePath = getBasePath;
339
+ module.exports.configDirs = configDirs;
340
+ module.exports.dataDirs = dataDirs;
229
341
  module.exports.projectDirs = projectDirs;
342
+ module.exports.applicationsDir = applicationsDir;
230
343
  module.exports.getXDGUserDir = getXDGUserDir;
231
344
 
232
345
  // Deprecated: kept for backward compatibility
package/index.mjs CHANGED
@@ -10,13 +10,18 @@ export const videos = osUserDirs.videos;
10
10
  export const templates = osUserDirs.templates;
11
11
  export const publicshare = osUserDirs.publicshare;
12
12
  export const getPath = osUserDirs.getPath;
13
+ export const binDir = osUserDirs.binDir;
13
14
  export const configDir = osUserDirs.configDir;
14
15
  export const dataDir = osUserDirs.dataDir;
15
16
  export const cacheDir = osUserDirs.cacheDir;
16
17
  export const stateDir = osUserDirs.stateDir;
17
18
  export const logDir = osUserDirs.logDir;
18
19
  export const runtimeDir = osUserDirs.runtimeDir;
20
+ export const fontsDir = osUserDirs.fontsDir;
19
21
  export const getBasePath = osUserDirs.getBasePath;
22
+ export const configDirs = osUserDirs.configDirs;
23
+ export const dataDirs = osUserDirs.dataDirs;
20
24
  export const projectDirs = osUserDirs.projectDirs;
25
+ export const applicationsDir = osUserDirs.applicationsDir;
21
26
  export const getXDGUserDir = osUserDirs.getXDGUserDir;
22
27
  export const getXDGDownloadDir = osUserDirs.getXDGDownloadDir;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "os-user-dirs",
3
- "version": "2.4.0",
3
+ "version": "2.6.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",