Skip to content

Commit

Permalink
Add support for XDG_STATE_HOME (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall committed Aug 5, 2021
1 parent 3fc64a8 commit 2bbd2ce
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
13 changes: 13 additions & 0 deletions index.d.ts
Expand Up @@ -24,6 +24,19 @@ console.log(xdgConfig);
*/
export const xdgConfig: string | undefined;

/**
Directory for user-specific state files.
@example
```
import {xdgState} from 'xdg-basedir';
console.log(xdgState);
//=> '/home/sindresorhus/.local/state'
```
*/
export const xdgState: string | undefined;

/**
Directory for user-specific non-essential data files.
Expand Down
3 changes: 3 additions & 0 deletions index.js
Expand Up @@ -10,6 +10,9 @@ export const xdgData = env.XDG_DATA_HOME ||
export const xdgConfig = env.XDG_CONFIG_HOME ||
(homeDirectory ? path.join(homeDirectory, '.config') : undefined);

export const xdgState = env.XDG_STATE_HOME ||
(homeDirectory ? path.join(homeDirectory, '.local', 'state') : undefined);

export const xdgCache = env.XDG_CACHE_HOME || (homeDirectory ? path.join(homeDirectory, '.cache') : undefined);

export const xdgRuntime = env.XDG_RUNTIME_DIR || undefined;
Expand Down
8 changes: 5 additions & 3 deletions index.test-d.ts
@@ -1,10 +1,12 @@
import {expectType, expectError} from 'tsd';
import {xdgData, xdgConfig, xdgCache, xdgRuntime, xdgConfigDirectories, xdgDataDirectories} from './index.js';
import {xdgData, xdgConfig, xdgState, xdgCache, xdgRuntime, xdgConfigDirectories, xdgDataDirectories} from './index.js';

expectType<string | undefined>(xdgData);
expectError<string>(xdgData);
expectType<string | undefined>(xdgCache);
expectError<string>(xdgCache);
expectType<string | undefined>(xdgConfig);
expectError<string>(xdgConfig);
expectType<string | undefined>(xdgState);
expectError<string>(xdgState);
expectType<string | undefined>(xdgCache);
expectError<string>(xdgCache);
expectType<string | undefined>(xdgRuntime);
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Expand Up @@ -37,6 +37,10 @@ Directory for user-specific data files.

Directory for user-specific configuration files.

### xdgState

Directory for user-specific state files.

### xdgCache

Directory for user-specific non-essential data files.
Expand Down
6 changes: 6 additions & 0 deletions test.js
Expand Up @@ -19,6 +19,12 @@ test('x', t => {
// t.is(xdgConfig, 'config');
// });
//
// test('xdgState', t => {
// process.env.XDG_CONFIG_HOME = 'state';
// const {xdgState} = importFresh('.');
// t.is(xdgState, 'state');
// });
//
// test('xdgCache', t => {
// process.env.XDG_CACHE_HOME = 'cache';
// const {xdgCache} = importFresh('.');
Expand Down

0 comments on commit 2bbd2ce

Please sign in to comment.