Skip to content

Commit

Permalink
Update all dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Jul 13, 2024
1 parent 5fc436a commit 61b83f0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
26 changes: 14 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
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';
import uniqueString from 'unique-string';

const configDirectory = xdgConfig || path.join(os.tmpdir(), uniqueString());
Expand All @@ -13,16 +15,16 @@ const writeFileOptions = {mode: 0o0600};

export default class Configstore {
constructor(id, defaults, options = {}) {
const pathPrefix = options.globalConfigPath ?
path.join(id, 'config.json') :
path.join('configstore', `${id}.json`);
const pathPrefix = options.globalConfigPath
? path.join(id, 'config.json')
: path.join('configstore', `${id}.json`);

this._path = options.configPath || path.join(configDirectory, pathPrefix);

if (defaults) {
this.all = {
...defaults,
...this.all
...this.all,
};
}
}
Expand Down Expand Up @@ -72,30 +74,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,14 +36,14 @@
],
"dependencies": {
"atomically": "^2.0.3",
"dot-prop": "^6.0.1",
"graceful-fs": "^4.2.6",
"dot-prop": "^9.0.0",
"graceful-fs": "^4.2.11",
"unique-string": "^3.0.0",
"xdg-basedir": "^5.0.1"
"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 61b83f0

Please sign in to comment.