Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 9, 2019
1 parent 4101982 commit ea4cac8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 29 deletions.
37 changes: 24 additions & 13 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/// <reference types="node"/>
import EventEmitter = require('events');
import {Omit} from 'type-fest';
import {Except} from 'type-fest';
import Conf = require('conf');

declare namespace ElectronStore {
type Options<T> = Omit<
type Schema = Conf.Schema;

type Options<T> = Except<
Conf.Options<T>,
'configName' | 'projectName' | 'projectSuffix'
'configName' | 'projectName' | 'projectVersion' | 'projectSuffix'
> & {
/**
Name of the storage file (without extension).
Expand All @@ -19,26 +21,35 @@ declare namespace ElectronStore {
};
}

declare class ElectronStore<T> extends Conf<T> {
/**
Simple data persistence for your [Electron](https://electronjs.org) app or module - Save and load user preferences, app state, cache, etc.
*/
declare class ElectronStore<T = any> extends Conf<T> {
/**
Simple data persistence for your [Electron](https://electronjs.org) app or module - Save and load user preferences, app state, cache, etc.
Changes are written to disk atomically, so if the process crashes during a write, it will not corrupt the existing config.
Changes are written to disk atomically, so if the process crashes during a write, it will not corrupt the existing store.
@example
```
import Store = require('electron-store');
const store = new Store();
type StoreType = {
isRainbow: boolean,
unicorn?: string
}
const store = new Store<StoreType>({
defaults: {
isRainbow: true
}
});
store.get('isRainbow');
//=> true
store.set('unicorn', '🦄');
console.log(store.get('unicorn'));
//=> '🦄'
// Use dot-notation to access nested properties
store.set('foo.bar', true);
console.log(store.get('foo'));
//=> {bar: true}
store.delete('unicorn');
console.log(store.get('unicorn'));
//=> undefined
Expand Down
27 changes: 17 additions & 10 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,33 @@ store.store = {

store.path;

const typedStore = new Store<number | boolean>({
type Schema = Store.Schema;

type TypedStore = {
isEnabled: boolean,
interval: number
};

const typedStore = new Store<TypedStore>({
defaults: {
enabled: true,
isEnabled: true,
interval: 30000
}
});

expectType<number | boolean>(typedStore.get('interval'));
const enabled = false;
typedStore.set('enabled', enabled);
expectType<number>(typedStore.get('interval'));
const isEnabled = false;
typedStore.set('isEnabled', isEnabled);
typedStore.set({
enabled: true,
isEnabled: true,
interval: 10000
});

const offDidChange = typedStore.onDidChange(
'enabled',
(oldValue, newValue) => {
expectType<number | boolean | undefined>(oldValue);
expectType<number | boolean | undefined>(newValue);
'isEnabled',
(newValue, oldValue) => {
expectType<boolean | undefined>(newValue);
expectType<boolean | undefined>(oldValue);
}
);

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
"save"
],
"dependencies": {
"conf": "^5.0.0",
"type-fest": "^0.5.2"
"conf": "^6.0.0",
"type-fest": "^0.7.1"
},
"devDependencies": {
"ava": "^2.1.0",
"electron": "^5.0.5",
"execa": "^1.0.0",
"electron": "^6.0.7",
"execa": "^2.0.4",
"tsd": "^0.7.2",
"xo": "^0.24.0"
},
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import execa from 'execa';
// See https://github.com/sindresorhus/conf for more extensive tests

const run = async file => {
const result = await execa.stdout(electron, [file], {
const {stdout} = await execa(electron, [file], {
env: {
ELECTRON_ENABLE_LOGGING: true,
ELECTRON_ENABLE_STACK_DUMPING: true,
ELECTRON_NO_ATTACH_CONSOLE: true
}
});

return result.trim();
return stdout.trim();
};

test('main', async t => {
Expand Down

0 comments on commit ea4cac8

Please sign in to comment.