From e91d21d658d20f73ea6f278a3b42a7a4500cb74b Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Fri, 7 Jul 2017 16:45:04 -0700 Subject: [PATCH] Add types for electron-store 1.2 --- types/electron-store/electron-store-tests.ts | 34 +++++++++ types/electron-store/index.d.ts | 79 ++++++++++++++++++++ types/electron-store/tsconfig.json | 22 ++++++ types/electron-store/tslint.json | 7 ++ 4 files changed, 142 insertions(+) create mode 100644 types/electron-store/electron-store-tests.ts create mode 100644 types/electron-store/index.d.ts create mode 100644 types/electron-store/tsconfig.json create mode 100644 types/electron-store/tslint.json diff --git a/types/electron-store/electron-store-tests.ts b/types/electron-store/electron-store-tests.ts new file mode 100644 index 0000000000..61d74d6f18 --- /dev/null +++ b/types/electron-store/electron-store-tests.ts @@ -0,0 +1,34 @@ +import ElectronStore = require('electron-store'); + +new ElectronStore({ + defaults: {} +}); + +new ElectronStore({ + name: 'myConfiguration', + cwd: 'unicorn' +}); + +const electronStore = new ElectronStore(); + +electronStore.set('foo', 'bar'); +electronStore.set({ + foo: 'bar', + foo2: 'bar2' +}); +electronStore.delete('foo'); +electronStore.get('foo'); +electronStore.get('foo', 42); +electronStore.has('foo'); +electronStore.clear(); + +electronStore.openInEditor(); + +electronStore.size; +electronStore.store; + +electronStore.store = { + foo: 'bar' +}; + +electronStore.path; diff --git a/types/electron-store/index.d.ts b/types/electron-store/index.d.ts new file mode 100644 index 0000000000..e270fb2b8e --- /dev/null +++ b/types/electron-store/index.d.ts @@ -0,0 +1,79 @@ +// Type definitions for electron-store 1.2 +// Project: https://github.com/sindresorhus/electron-store +// Definitions by: Daniel Perez Alvarez +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface ElectronStoreOptions { + /** + * Default config. + */ + defaults?: {}; + + /** + * Name of the config file (without extension). + */ + name?: string; + + /** + * Storage file location. *Don't specify this unless absolutely necessary!* + */ + cwd?: string; +} + +declare class ElectronStore implements Iterable<[string, string | number | boolean | symbol | {}]> { + constructor(options?: ElectronStoreOptions); + + /** + * Sets an item. + */ + set(key: string, value: any): void; + + /** + * Sets multiple items at once. + */ + set(object: {}): void; + + /** + * Retrieves an item. + */ + get(key: string, defaultValue?: any): any; + + /** + * Checks if an item exists. + */ + has(key: string): boolean; + + /** + * Deletes an item. + */ + delete(key: string): void; + + /** + * Deletes all items. + */ + clear(): void; + + /** + * Open the storage file in the user's editor. + */ + openInEditor(): void; + + /** + * Gets the item count. + */ + size: number; + + /** + * Gets all the config as an object or replace the current config with an object. + */ + store: {}; + + /** + * Gets the path to the config file. + */ + path: string; + + [Symbol.iterator](): Iterator<[string, string | number | boolean | symbol | {}]>; +} + +export = ElectronStore; diff --git a/types/electron-store/tsconfig.json b/types/electron-store/tsconfig.json new file mode 100644 index 0000000000..311e831103 --- /dev/null +++ b/types/electron-store/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "electron-store-tests.ts" + ] +} diff --git a/types/electron-store/tslint.json b/types/electron-store/tslint.json new file mode 100644 index 0000000000..e830836d23 --- /dev/null +++ b/types/electron-store/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": "dtslint/dt.json" , + "rules": { + "no-namespace":false, + "object-literal-key-quotes": false + } +}