@adriangalilea/utils 0.1.0 → 0.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 CHANGED
@@ -162,8 +162,27 @@ expect(() => assert(false, 'boom')).toThrow(Panic)
162
162
  - **File Operations**: Read, write with automatic path resolution
163
163
  - **Directory Operations**: Create, list, walk directories
164
164
  - **KEV**: Redis-style environment variable management with monorepo support
165
+ - **XDG**: XDG Base Directory paths — reads env vars set by [xdg-dirs](https://github.com/adriangalilea/xdg-dirs), falls back to spec defaults
165
166
  - **Project Discovery**: Find project/monorepo roots, detect JS/TS projects
166
167
 
168
+ ### XDG Base Directories
169
+
170
+ XDG paths that respect env vars from [xdg-dirs](https://github.com/adriangalilea/xdg-dirs) with spec-compliant fallbacks:
171
+
172
+ ```typescript
173
+ import { xdg, dir } from '@adriangalilea/utils'
174
+
175
+ xdg.state('notify') // ~/.local/state/notify
176
+ xdg.state('notify', 'watchers.json') // ~/.local/state/notify/watchers.json
177
+ xdg.config('myapp') // ~/.config/myapp
178
+ xdg.data('myapp') // ~/.local/share/myapp
179
+ xdg.cache('myapp') // ~/.cache/myapp
180
+ xdg.runtime('myapp') // $XDG_RUNTIME_DIR/myapp
181
+
182
+ // Ensure the directory exists before writing
183
+ dir.create(xdg.state('notify'))
184
+ ```
185
+
167
186
  ## Release
168
187
 
169
188
  Bump version in `package.json` (and `jsr.json`), push to `main`. CI handles everything:
package/dist/index.d.ts CHANGED
@@ -13,4 +13,5 @@ export * from './platform/dir.js';
13
13
  export * from './platform/path.js';
14
14
  export * from './platform/project.js';
15
15
  export * from './platform/kev.js';
16
+ export * from './platform/xdg.js';
16
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAGvD,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,+BAA+B,CAAA;AAG7C,cAAc,gBAAgB,CAAA;AAI9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAGvD,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,+BAA+B,CAAA;AAG7C,cAAc,gBAAgB,CAAA;AAI9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA"}
package/dist/index.js CHANGED
@@ -17,4 +17,5 @@ export * from './platform/dir.js';
17
17
  export * from './platform/path.js';
18
18
  export * from './platform/project.js';
19
19
  export * from './platform/kev.js';
20
+ export * from './platform/xdg.js';
20
21
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,8CAA8C;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC,wCAAwC;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,+BAA+B,CAAA;AAE7C,yDAAyD;AACzD,cAAc,gBAAgB,CAAA;AAE9B,8BAA8B;AAC9B,mEAAmE;AACnE,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,8CAA8C;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC,wCAAwC;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,+BAA+B,CAAA;AAE7C,yDAAyD;AACzD,cAAc,gBAAgB,CAAA;AAE9B,8BAA8B;AAC9B,mEAAmE;AACnE,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA"}
@@ -0,0 +1,8 @@
1
+ export declare const xdg: {
2
+ config: (...segments: string[]) => string;
3
+ data: (...segments: string[]) => string;
4
+ state: (...segments: string[]) => string;
5
+ cache: (...segments: string[]) => string;
6
+ runtime: (...segments: string[]) => string;
7
+ };
8
+ //# sourceMappingURL=xdg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xdg.d.ts","sourceRoot":"","sources":["../../src/platform/xdg.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,GAAG;0BACS,MAAM,EAAE;wBACR,MAAM,EAAE;yBACR,MAAM,EAAE;yBACR,MAAM,EAAE;2BACR,MAAM,EAAE;CAChC,CAAA"}
@@ -0,0 +1,12 @@
1
+ import { homedir } from 'node:os';
2
+ import { join } from 'node:path';
3
+ const home = homedir();
4
+ const env = (key, fallback) => process.env[key] || fallback;
5
+ export const xdg = {
6
+ config: (...segments) => join(env('XDG_CONFIG_HOME', join(home, '.config')), ...segments),
7
+ data: (...segments) => join(env('XDG_DATA_HOME', join(home, '.local', 'share')), ...segments),
8
+ state: (...segments) => join(env('XDG_STATE_HOME', join(home, '.local', 'state')), ...segments),
9
+ cache: (...segments) => join(env('XDG_CACHE_HOME', join(home, '.cache')), ...segments),
10
+ runtime: (...segments) => join(env('XDG_RUNTIME_DIR', join(home, '.local', 'run')), ...segments),
11
+ };
12
+ //# sourceMappingURL=xdg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xdg.js","sourceRoot":"","sources":["../../src/platform/xdg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,MAAM,IAAI,GAAG,OAAO,EAAE,CAAA;AACtB,MAAM,GAAG,GAAG,CAAC,GAAW,EAAE,QAAgB,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAA;AAE3E,MAAM,CAAC,MAAM,GAAG,GAAG;IACjB,MAAM,EAAG,CAAC,GAAG,QAAkB,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,EAAE,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC;IACpG,IAAI,EAAK,CAAC,GAAG,QAAkB,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC;IAC1G,KAAK,EAAI,CAAC,GAAG,QAAkB,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC;IAC3G,KAAK,EAAI,CAAC,GAAG,QAAkB,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC;IAClG,OAAO,EAAE,CAAC,GAAG,QAAkB,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC;CAC3G,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adriangalilea/utils",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "TypeScript utilities - logger, currency, formatter, and more",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",