diff --git a/index.js b/index.js index e6d65ac..67c6d75 100644 --- a/index.js +++ b/index.js @@ -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); } @@ -26,7 +31,7 @@ export default class Configstore { if (defaults) { this.all = { ...defaults, - ...this.all + ...this.all, }; } } @@ -76,7 +81,7 @@ export default class Configstore { } get(key) { - return dotProp.get(this.all, key); + return getProperty(this.all, key); } set(key, value) { @@ -84,22 +89,22 @@ export default class Configstore { 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; } diff --git a/package.json b/package.json index 84457b4..2774462 100644 --- a/package.json +++ b/package.json @@ -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 diff --git a/test.js b/test.js index 30c2f6a..8fa1297 100644 --- a/test.js +++ b/test.js @@ -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'; @@ -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'}); @@ -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$/); }); @@ -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');