Skip to content

Commit

Permalink
Update dependencies (#95)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
fregante and sindresorhus committed Jul 13, 2024
1 parent 6985be5 commit 278ee3c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
31 changes: 18 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import path from 'path';
import os from 'os';
import path from 'node:path';
import os from 'node:os';
import fs from 'graceful-fs';
import {xdgConfig} from 'xdg-basedir';
import {writeFileSync} from 'atomically';
import dotProp from 'dot-prop';
import {
getProperty,
setProperty,
hasProperty,
deleteProperty,
} from 'dot-prop';

function getConfigDirectory(id, globalConfigPath) {
const pathPrefix = globalConfigPath ?
path.join(id, 'config.json') :
path.join('configstore', `${id}.json`);
const pathPrefix = globalConfigPath
? path.join(id, 'config.json')
: path.join('configstore', `${id}.json`);

const configDirectory = xdgConfig || fs.mkdtempSync(fs.realpathSync(os.tmpdir()) + path.sep);
const configDirectory = xdgConfig ?? fs.mkdtempSync(fs.realpathSync(os.tmpdir()) + path.sep);

return path.join(configDirectory, pathPrefix);
}
Expand All @@ -26,7 +31,7 @@ export default class Configstore {
if (defaults) {
this.all = {
...defaults,
...this.all
...this.all,
};
}
}
Expand Down Expand Up @@ -76,30 +81,30 @@ export default class Configstore {
}

get(key) {
return dotProp.get(this.all, key);
return getProperty(this.all, key);
}

set(key, value) {
const config = this.all;

if (arguments.length === 1) {
for (const k of Object.keys(key)) {
dotProp.set(config, k, key[k]);
setProperty(config, k, key[k]);
}
} else {
dotProp.set(config, key, value);
setProperty(config, key, value);
}

this.all = config;
}

has(key) {
return dotProp.has(this.all, key);
return hasProperty(this.all, key);
}

delete(key) {
const config = this.all;
dotProp.delete(config, key);
deleteProperty(config, key);
this.all = config;
}

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
],
"dependencies": {
"atomically": "^2.0.3",
"dot-prop": "^6.0.1",
"graceful-fs": "^4.2.6",
"xdg-basedir": "^5.0.1"
"dot-prop": "^9.0.0",
"graceful-fs": "^4.2.11",
"xdg-basedir": "^5.1.0"
},
"devDependencies": {
"ava": "^3.15.0",
"xo": "^0.38.2"
"ava": "^6.1.3",
"xo": "^0.58.0"
},
"ava": {
"serial": true
Expand Down
20 changes: 10 additions & 10 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
import fs from 'node:fs';
import path from 'node:path';
import os from 'node:os';
import test from 'ava';
import Configstore from './index.js';

Expand Down Expand Up @@ -33,17 +33,17 @@ test('.set() with object and .get()', t => {
baz: {
boo: 'foo',
foo: {
bar: 'baz'
}
}
bar: 'baz',
},
},
});
t.is(config.get('foo1'), 'bar1');
t.is(config.get('foo2'), 'bar2');
t.deepEqual(config.get('baz'), {
boo: 'foo',
foo: {
bar: 'baz'
}
bar: 'baz',
},
});
t.is(config.get('baz.boo'), 'foo');
t.deepEqual(config.get('baz.foo'), {bar: 'baz'});
Expand Down Expand Up @@ -119,7 +119,7 @@ test('support `configPath` option', t => {
const customPath = path.join(os.tmpdir(), 'configstore-custom-path', 'foo.json');
const config = new Configstore('ignored-namespace', {}, {
globalConfigPath: true,
configPath: customPath
configPath: customPath,
});
t.regex(config.path, /configstore-custom-path(\/|\\)foo.json$/);
});
Expand All @@ -144,7 +144,7 @@ test('ensure necessary sub-directories are created', t => {
const customPath = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'configstore-recursive-')), 'foo', 'bar', 'baz.json');
const config = new Configstore('ignored-namespace', undefined, {
globalConfigPath: true,
configPath: customPath
configPath: customPath,
});
t.false(fs.existsSync(config.path));
config.set('foo', 'bar');
Expand Down

0 comments on commit 278ee3c

Please sign in to comment.