@depup/electron-store 11.0.2-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # @depup/electron-store
2
+
3
+ > Dependency-bumped version of [electron-store](https://www.npmjs.com/package/electron-store)
4
+
5
+ Generated by [DepUp](https://github.com/depup/npm) -- all production
6
+ dependencies bumped to latest versions.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @depup/electron-store
12
+ ```
13
+
14
+ | Field | Value |
15
+ |-------|-------|
16
+ | Original | [electron-store](https://www.npmjs.com/package/electron-store) @ 11.0.2 |
17
+ | Processed | 2026-03-17 |
18
+ | Smoke test | failed |
19
+ | Deps updated | 2 |
20
+
21
+ ## Dependency Changes
22
+
23
+ | Dependency | From | To |
24
+ |------------|------|-----|
25
+ | conf | ^15.0.2 | ^15.1.0 |
26
+ | type-fest | ^5.0.1 | ^5.4.4 |
27
+
28
+ ---
29
+
30
+ Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/electron-store
31
+
32
+ License inherited from the original package.
package/changes.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "bumped": {
3
+ "conf": {
4
+ "from": "^15.0.2",
5
+ "to": "^15.1.0"
6
+ },
7
+ "type-fest": {
8
+ "from": "^5.0.1",
9
+ "to": "^5.4.4"
10
+ }
11
+ },
12
+ "timestamp": "2026-03-17T22:55:33.405Z",
13
+ "totalUpdated": 2
14
+ }
package/index.d.ts ADDED
@@ -0,0 +1,64 @@
1
+ import {type Except} from 'type-fest';
2
+ import Conf, {type Options as ConfigOptions} from 'conf';
3
+
4
+ export {Schema} from 'conf';
5
+
6
+ export type Options<T extends Record<string, any>> = Except<ConfigOptions<T>, 'configName' | 'projectName' | 'projectVersion' | 'projectSuffix'> & {
7
+ /**
8
+ Name of the storage file (without extension).
9
+
10
+ This is useful if you want multiple storage files for your app. Or if you're making a reusable Electron module that persists some data, in which case you should **not** use the name `config`.
11
+
12
+ @default 'config'
13
+ */
14
+ readonly name?: string;
15
+ };
16
+
17
+ /**
18
+ Simple data persistence for your [Electron](https://electronjs.org) app or module - Save and load user settings, app state, cache, etc.
19
+ */
20
+ export default class ElectronStore<T extends Record<string, any> = Record<string, unknown>> extends Conf<T> {
21
+ /**
22
+ Initializer to set up the required `ipc` communication channels for the module when a `Store` instance is not created in the main process and you are creating a `Store` instance in the Electron renderer process only.
23
+ */
24
+ static initRenderer(): void;
25
+
26
+ /**
27
+ Changes are written to disk atomically, so if the process crashes during a write, it will not corrupt the existing store.
28
+
29
+ @example
30
+ ```
31
+ import Store from 'electron-store';
32
+
33
+ type StoreType = {
34
+ isRainbow: boolean,
35
+ unicorn?: string
36
+ }
37
+
38
+ const store = new Store<StoreType>({
39
+ defaults: {
40
+ isRainbow: true
41
+ }
42
+ });
43
+
44
+ store.get('isRainbow');
45
+ //=> true
46
+
47
+ store.set('unicorn', '🦄');
48
+ console.log(store.get('unicorn'));
49
+ //=> '🦄'
50
+
51
+ store.delete('unicorn');
52
+ console.log(store.get('unicorn'));
53
+ //=> undefined
54
+ ```
55
+ */
56
+ constructor(options?: Options<T>);
57
+
58
+ /**
59
+ Open the storage file in the user's editor.
60
+
61
+ Returns a promise that resolves when the editor has been opened, or rejects if it failed to open.
62
+ */
63
+ openInEditor(): Promise<void>;
64
+ }
package/index.js ADDED
@@ -0,0 +1,83 @@
1
+ import process from 'node:process';
2
+ import path from 'node:path';
3
+ import electron from 'electron';
4
+ import Conf from 'conf';
5
+
6
+ const {app, ipcMain, shell} = electron;
7
+
8
+ let isInitialized = false;
9
+
10
+ // Set up the `ipcMain` handler for communication between renderer and main process.
11
+ const initDataListener = () => {
12
+ if (!ipcMain || !app) {
13
+ throw new Error('Electron Store: You need to call `.initRenderer()` from the main process.');
14
+ }
15
+
16
+ const appData = {
17
+ defaultCwd: app.getPath('userData'),
18
+ appVersion: app.getVersion(),
19
+ };
20
+
21
+ if (isInitialized) {
22
+ return appData;
23
+ }
24
+
25
+ ipcMain.on('electron-store-get-data', event => {
26
+ event.returnValue = appData;
27
+ });
28
+
29
+ isInitialized = true;
30
+
31
+ return appData;
32
+ };
33
+
34
+ export default class ElectronStore extends Conf {
35
+ constructor(options) {
36
+ let defaultCwd;
37
+ let appVersion;
38
+
39
+ // If we are in the renderer process, we communicate with the main process
40
+ // to get the required data for the module otherwise, we pull from the main process.
41
+ if (process.type === 'renderer') {
42
+ const appData = electron.ipcRenderer.sendSync('electron-store-get-data');
43
+
44
+ if (!appData) {
45
+ throw new Error('Electron Store: You need to call `.initRenderer()` from the main process.');
46
+ }
47
+
48
+ ({defaultCwd, appVersion} = appData);
49
+ } else if (ipcMain && app) {
50
+ ({defaultCwd, appVersion} = initDataListener());
51
+ }
52
+
53
+ options = {
54
+ name: 'config',
55
+ ...options,
56
+ };
57
+
58
+ options.projectVersion ||= appVersion;
59
+
60
+ if (options.cwd) {
61
+ options.cwd = path.isAbsolute(options.cwd) ? options.cwd : path.join(defaultCwd, options.cwd);
62
+ } else {
63
+ options.cwd = defaultCwd;
64
+ }
65
+
66
+ options.configName = options.name;
67
+ delete options.name;
68
+
69
+ super(options);
70
+ }
71
+
72
+ static initRenderer() {
73
+ initDataListener();
74
+ }
75
+
76
+ async openInEditor() {
77
+ const error = await shell.openPath(this.path);
78
+
79
+ if (error) {
80
+ throw new Error(error);
81
+ }
82
+ }
83
+ }
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,95 @@
1
+ {
2
+ "name": "@depup/electron-store",
3
+ "version": "11.0.2-depup.0",
4
+ "description": "[DepUp] Simple data persistence for your Electron app or module - Save and load user settings, app state, cache, etc",
5
+ "license": "MIT",
6
+ "repository": "sindresorhus/electron-store",
7
+ "funding": "https://github.com/sponsors/sindresorhus",
8
+ "author": {
9
+ "name": "Sindre Sorhus",
10
+ "email": "sindresorhus@gmail.com",
11
+ "url": "https://sindresorhus.com"
12
+ },
13
+ "type": "module",
14
+ "exports": {
15
+ "types": "./index.d.ts",
16
+ "default": "./index.js"
17
+ },
18
+ "sideEffects": false,
19
+ "engines": {
20
+ "node": ">=20"
21
+ },
22
+ "scripts": {
23
+ "test": "xo && ava && tsd"
24
+ },
25
+ "files": [
26
+ "index.js",
27
+ "index.d.ts",
28
+ "changes.json",
29
+ "README.md"
30
+ ],
31
+ "keywords": [
32
+ "depup",
33
+ "dependency-bumped",
34
+ "updated-deps",
35
+ "electron-store",
36
+ "electron",
37
+ "store",
38
+ "app",
39
+ "config",
40
+ "storage",
41
+ "conf",
42
+ "configuration",
43
+ "settings",
44
+ "preferences",
45
+ "json",
46
+ "data",
47
+ "persist",
48
+ "persistent",
49
+ "save"
50
+ ],
51
+ "dependencies": {
52
+ "conf": "^15.1.0",
53
+ "type-fest": "^5.4.4"
54
+ },
55
+ "devDependencies": {
56
+ "ava": "^6.4.1",
57
+ "electron": "^38.1.2",
58
+ "execa": "^9.6.0",
59
+ "tsd": "^0.33.0",
60
+ "xo": "^0.60.0"
61
+ },
62
+ "xo": {
63
+ "envs": [
64
+ "node",
65
+ "browser"
66
+ ],
67
+ "rules": {
68
+ "n/no-unsupported-features/node-builtins": "off"
69
+ }
70
+ },
71
+ "tsd": {
72
+ "compilerOptions": {
73
+ "module": "node16",
74
+ "moduleResolution": "node16",
75
+ "moduleDetection": "force"
76
+ }
77
+ },
78
+ "depup": {
79
+ "changes": {
80
+ "conf": {
81
+ "from": "^15.0.2",
82
+ "to": "^15.1.0"
83
+ },
84
+ "type-fest": {
85
+ "from": "^5.0.1",
86
+ "to": "^5.4.4"
87
+ }
88
+ },
89
+ "depsUpdated": 2,
90
+ "originalPackage": "electron-store",
91
+ "originalVersion": "11.0.2",
92
+ "processedAt": "2026-03-17T22:55:48.766Z",
93
+ "smokeTest": "failed"
94
+ }
95
+ }
package/readme.md ADDED
@@ -0,0 +1,482 @@
1
+ # electron-store
2
+
3
+ > Simple data persistence for your [Electron](https://electronjs.org) app or module - Save and load user settings, app state, cache, etc
4
+
5
+ Electron doesn't have a built-in way to persist user settings and other data. This module handles that for you, so you can focus on building your app. The data is saved in a JSON file named config.json in [`app.getPath('userData')`](https://electronjs.org/docs/api/app#appgetpathname).
6
+
7
+ You can use this module directly in both the main and renderer process. For use in the renderer process only, you need to call `Store.initRenderer()` in the main process, or create a new Store instance (`new Store()`) in the main process.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install electron-store
13
+ ```
14
+
15
+ *Requires Electron 30 or later.*
16
+
17
+ > [!NOTE]
18
+ > This package is native [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) and no longer provides a CommonJS export. If your project uses CommonJS, you will have to [convert to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c). More info about [Electron and ESM](https://www.electronjs.org/docs/latest/tutorial/esm). Please don't open issues for questions regarding CommonJS and ESM.
19
+
20
+ ## Usage
21
+
22
+ ```js
23
+ import Store from 'electron-store';
24
+
25
+ const store = new Store();
26
+
27
+ store.set('unicorn', '🦄');
28
+ console.log(store.get('unicorn'));
29
+ //=> '🦄'
30
+
31
+ // Use dot-notation to access nested properties
32
+ store.set('foo.bar', true);
33
+ console.log(store.get('foo'));
34
+ //=> {bar: true}
35
+
36
+ store.delete('unicorn');
37
+ console.log(store.get('unicorn'));
38
+ //=> undefined
39
+ ```
40
+
41
+ ## API
42
+
43
+ Changes are written to disk atomically, so if the process crashes during a write, it will not corrupt the existing config.
44
+
45
+ ### Store(options?)
46
+
47
+ Returns a new instance.
48
+
49
+ ### options
50
+
51
+ Type: `object`
52
+
53
+ #### defaults
54
+
55
+ Type: `object`
56
+
57
+ Default values for the store items.
58
+
59
+ **Note:** The values in `defaults` will overwrite the `default` key in the `schema` option.
60
+
61
+ #### schema
62
+
63
+ type: `object`
64
+
65
+ [JSON Schema](https://json-schema.org) to validate your config data.
66
+
67
+ Under the hood, the JSON Schema validator [ajv](https://ajv.js.org/json-schema.html) is used to validate your config. We use [JSON Schema draft-2020-12](https://json-schema.org/draft/2020-12/release-notes) and support all validation keywords and formats.
68
+
69
+ You should define your schema as an object where each key is the name of your data's property and each value is a JSON schema used to validate that property. See more [here](https://json-schema.org/understanding-json-schema/reference/object.html#properties).
70
+
71
+ Example:
72
+
73
+ ```js
74
+ import Store from 'electron-store';
75
+
76
+ const schema = {
77
+ foo: {
78
+ type: 'number',
79
+ maximum: 100,
80
+ minimum: 1,
81
+ default: 50
82
+ },
83
+ bar: {
84
+ type: 'string',
85
+ format: 'url'
86
+ }
87
+ };
88
+
89
+ const store = new Store({schema});
90
+
91
+ console.log(store.get('foo'));
92
+ //=> 50
93
+
94
+ store.set('foo', '1');
95
+ // [Error: Config schema violation: `foo` should be number]
96
+ ```
97
+
98
+ **Note:** The `default` value will be overwritten by the `defaults` option if set.
99
+
100
+ #### migrations
101
+
102
+ Type: `object`
103
+
104
+ **Important: I cannot provide support for this feature. It has some known bugs. I have no plans to work on it, but pull requests are welcome.**
105
+
106
+ You can use migrations to perform operations to the store whenever a version is upgraded.
107
+
108
+ The `migrations` object should consist of a key-value pair of `'version': handler`. The `version` can also be a [semver range](https://github.com/npm/node-semver#ranges).
109
+
110
+ Example:
111
+
112
+ ```js
113
+ import Store from 'electron-store';
114
+
115
+ const store = new Store({
116
+ migrations: {
117
+ '0.0.1': store => {
118
+ store.set('debugPhase', true);
119
+ },
120
+ '1.0.0': store => {
121
+ store.delete('debugPhase');
122
+ store.set('phase', '1.0.0');
123
+ },
124
+ '1.0.2': store => {
125
+ store.set('phase', '1.0.2');
126
+ },
127
+ '>=2.0.0': store => {
128
+ store.set('phase', '>=2.0.0');
129
+ }
130
+ }
131
+ });
132
+ ```
133
+
134
+ ### beforeEachMigration
135
+
136
+ Type: `Function`\
137
+ Default: `undefined`
138
+
139
+ The given callback function will be called before each migration step.
140
+
141
+ The function receives the store as the first argument and a context object as the second argument with the following properties:
142
+
143
+ - `fromVersion` - The version the migration step is being migrated from.
144
+ - `toVersion` - The version the migration step is being migrated to.
145
+ - `finalVersion` - The final version after all the migrations are applied.
146
+ - `versions` - All the versions with a migration step.
147
+
148
+ This can be useful for logging purposes, preparing migration data, etc.
149
+
150
+ Example:
151
+
152
+ ```js
153
+ import Store from 'electron-store';
154
+
155
+ console.log = someLogger.log;
156
+
157
+ const mainConfig = new Store({
158
+ beforeEachMigration: (store, context) => {
159
+ console.log(`[main-config] migrate from ${context.fromVersion} → ${context.toVersion}`);
160
+ },
161
+ migrations: {
162
+ '0.4.0': store => {
163
+ store.set('debugPhase', true);
164
+ }
165
+ }
166
+ });
167
+
168
+ const secondConfig = new Store({
169
+ beforeEachMigration: (store, context) => {
170
+ console.log(`[second-config] migrate from ${context.fromVersion} → ${context.toVersion}`);
171
+ },
172
+ migrations: {
173
+ '1.0.1': store => {
174
+ store.set('debugPhase', true);
175
+ }
176
+ }
177
+ });
178
+ ```
179
+
180
+ #### name
181
+
182
+ Type: `string`\
183
+ Default: `'config'`
184
+
185
+ Name of the storage file (without extension).
186
+
187
+ This is useful if you want multiple storage files for your app. Or if you're making a reusable Electron module that persists some data, in which case you should **not** use the name `config`.
188
+
189
+ #### cwd
190
+
191
+ Type: `string`\
192
+ Default: [`app.getPath('userData')`](https://electronjs.org/docs/api/app#appgetpathname)
193
+
194
+ Storage file location. *Don't specify this unless absolutely necessary! By default, it will pick the optimal location by adhering to system conventions. You are very likely to get this wrong and annoy users.*
195
+
196
+ If a relative path, it's relative to the default cwd. For example, `{cwd: 'unicorn'}` would result in a storage file in `~/Library/Application Support/App Name/unicorn`.
197
+
198
+ #### encryptionKey
199
+
200
+ Type: `string | Buffer | TypedArray | DataView`\
201
+ Default: `undefined`
202
+
203
+ Note that this is **not intended for security purposes**, since the encryption key would be easily found inside a plain-text Node.js app.
204
+
205
+ Its main use is for obscurity. If a user looks through the config directory and finds the config file, since it's just a JSON file, they may be tempted to modify it. By providing an encryption key, the file will be obfuscated, which should hopefully deter any users from doing so.
206
+
207
+ When specified, the store will be encrypted using the [`aes-256-cbc`](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation) encryption algorithm.
208
+
209
+ #### fileExtension
210
+
211
+ Type: `string`\
212
+ Default: `'json'`
213
+
214
+ Extension of the config file.
215
+
216
+ You would usually not need this, but could be useful if you want to interact with a file with a custom file extension that can be associated with your app. These might be simple save/export/preference files that are intended to be shareable or saved outside of the app.
217
+
218
+ #### clearInvalidConfig
219
+
220
+ Type: `boolean`\
221
+ Default: `false`
222
+
223
+ The config is cleared if reading the config file causes a `SyntaxError`. This is a good behavior for unimportant data, as the config file is not intended to be hand-edited, so it usually means the config is corrupt and there's nothing the user can do about it anyway. However, if you let the user edit the config file directly, mistakes might happen and it could be more useful to throw an error when the config is invalid instead of clearing.
224
+
225
+ #### serialize
226
+
227
+ Type: `Function`\
228
+ Default: `value => JSON.stringify(value, null, '\t')`
229
+
230
+ Function to serialize the config object to a UTF-8 string when writing the config file.
231
+
232
+ You would usually not need this, but it could be useful if you want to use a format other than JSON.
233
+
234
+ #### deserialize
235
+
236
+ Type: `Function`\
237
+ Default: `JSON.parse`
238
+
239
+ Function to deserialize the config object from a UTF-8 string when reading the config file.
240
+
241
+ You would usually not need this, but it could be useful if you want to use a format other than JSON.
242
+
243
+ #### accessPropertiesByDotNotation
244
+
245
+ Type: `boolean`\
246
+ Default: `true`
247
+
248
+ Accessing nested properties by dot notation. For example:
249
+
250
+ ```js
251
+ import Store from 'electron-store';
252
+
253
+ const store = new Store();
254
+
255
+ store.set({
256
+ foo: {
257
+ bar: {
258
+ foobar: '🦄'
259
+ }
260
+ }
261
+ });
262
+
263
+ console.log(store.get('foo.bar.foobar'));
264
+ //=> '🦄'
265
+ ```
266
+
267
+ Alternatively, you can set this option to `false` so the whole string would be treated as one key.
268
+
269
+ ```js
270
+ const store = new Store({accessPropertiesByDotNotation: false});
271
+
272
+ store.set({
273
+ `foo.bar.foobar`: '🦄'
274
+ });
275
+
276
+ console.log(store.get('foo.bar.foobar'));
277
+ //=> '🦄'
278
+ ```
279
+
280
+ #### watch
281
+
282
+ Type: `boolean`\
283
+ Default: `false`
284
+
285
+ Watch for any changes in the config file and call the callback for `onDidChange` or `onDidAnyChange` if set. This is useful if there are multiple processes changing the same config file, for example, if you want changes done in the main process to be reflected in a renderer process.
286
+
287
+ ### Instance
288
+
289
+ You can use [dot-notation](https://github.com/sindresorhus/dot-prop) in a `key` to access nested properties.
290
+
291
+ The instance is [`iterable`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols) so you can use it directly in a [`for…of`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of) loop.
292
+
293
+ #### .set(key, value)
294
+
295
+ Set an item.
296
+
297
+ The `value` must be JSON serializable. Trying to set the type `undefined`, `function`, or `symbol` will result in a TypeError.
298
+
299
+ #### .set(object)
300
+
301
+ Set multiple items at once.
302
+
303
+ #### .get(key, defaultValue?)
304
+
305
+ Get an item or `defaultValue` if the item does not exist.
306
+
307
+ #### .reset(...keys)
308
+
309
+ Reset items to their default values, as defined by the `defaults` or `schema` option.
310
+
311
+ Use `.clear()` to reset all items.
312
+
313
+ #### .has(key)
314
+
315
+ Check if an item exists.
316
+
317
+ #### .delete(key)
318
+
319
+ Delete an item.
320
+
321
+ #### .appendToArray(key, value)
322
+
323
+ Append an item to an array.
324
+
325
+ If the key doesn't exist, it will be created as an array. If the key exists and is not an array, a `TypeError` will be thrown.
326
+
327
+ The `value` must be JSON serializable. Trying to set the type like `undefined`, `function`, or `symbol` will result in a `TypeError`.
328
+
329
+ ```js
330
+ store.set('items', [{name: 'foo'}]);
331
+ store.appendToArray('items', {name: 'bar'});
332
+ console.log(store.get('items'));
333
+ //=> [{name: 'foo'}, {name: 'bar'}]
334
+
335
+ // Creates array if key doesn't exist
336
+ store.appendToArray('newItems', 'first');
337
+ console.log(store.get('newItems'));
338
+ //=> ['first']
339
+ ```
340
+
341
+ #### .clear()
342
+
343
+ Delete all items.
344
+
345
+ This resets known items to their default values, if defined by the `defaults` or `schema` option.
346
+
347
+ #### .onDidChange(key, callback)
348
+
349
+ `callback`: `(newValue, oldValue) => {}`
350
+
351
+ Watches the given `key`, calling `callback` on any changes.
352
+
353
+ When a key is first set `oldValue` will be `undefined`, and when a key is deleted `newValue` will be `undefined`.
354
+
355
+ Returns a function which you can use to unsubscribe:
356
+
357
+ ```js
358
+ const unsubscribe = store.onDidChange(key, callback);
359
+
360
+ unsubscribe();
361
+ ```
362
+
363
+ #### .onDidAnyChange(callback)
364
+
365
+ `callback`: `(newValue, oldValue) => {}`
366
+
367
+ Watches the whole config object, calling `callback` on any changes.
368
+
369
+ `oldValue` and `newValue` will be the config object before and after the change, respectively. You must compare `oldValue` to `newValue` to find out what changed.
370
+
371
+ Returns a function which you can use to unsubscribe:
372
+
373
+ ```js
374
+ const unsubscribe = store.onDidAnyChange(callback);
375
+
376
+ unsubscribe();
377
+ ```
378
+
379
+ #### .size
380
+
381
+ Get the item count.
382
+
383
+ #### .store
384
+
385
+ Get all the data as an object or replace the current data with an object:
386
+
387
+ ```js
388
+ import Store from 'electron-store';
389
+
390
+ const store = new Store();
391
+
392
+ store.store = {
393
+ hello: 'world'
394
+ };
395
+ ```
396
+
397
+ #### .path
398
+
399
+ Get the path to the storage file.
400
+
401
+ #### .openInEditor()
402
+
403
+ Open the storage file in the user's editor.
404
+
405
+ Returns a promise that resolves when the editor has been opened, or rejects if it failed to open.
406
+
407
+ ### initRenderer()
408
+
409
+ Initializer to set up the required `ipc` communication channels for the module when a `Store` instance is not created in the main process and you are creating a `Store` instance in the Electron renderer process only.
410
+
411
+ In the main process:
412
+
413
+ ```js
414
+ import Store from 'electron-store';
415
+
416
+ Store.initRenderer();
417
+ ```
418
+
419
+ And in the renderer process:
420
+
421
+ ```js
422
+ import Store from 'electron-store';
423
+
424
+ const store = new Store();
425
+
426
+ store.set('unicorn', '🦄');
427
+ console.log(store.get('unicorn'));
428
+ //=> '🦄'
429
+ ```
430
+
431
+ ## FAQ
432
+
433
+ #### [Advantages over `window.localStorage`](https://github.com/sindresorhus/electron-store/issues/17)
434
+
435
+ #### Can I use YAML or another serialization format?
436
+
437
+ The `serialize` and `deserialize` options can be used to customize the format of the config file, as long as the representation is compatible with `utf8` encoding.
438
+
439
+ Example using YAML:
440
+
441
+ ```js
442
+ import Store from 'electron-store';
443
+ import yaml from 'js-yaml';
444
+
445
+ const store = new Store({
446
+ fileExtension: 'yaml',
447
+ serialize: yaml.safeDump,
448
+ deserialize: yaml.safeLoad
449
+ });
450
+ ```
451
+
452
+ #### How do I get store values in the renderer process when my store was initialized in the main process?
453
+
454
+ The store is not a singleton, so you will need to either [initialize the store in a file that is imported in both the main and renderer process](https://github.com/sindresorhus/electron-store/issues/15), or you have to pass the values back and forth as messages. Electron provides a handy [`invoke/handle` API](https://www.electronjs.org/docs/api/ipc-main#ipcmainhandlechannel-listener) that works well for accessing these values.
455
+
456
+ ```js
457
+ ipcMain.handle('getStoreValue', (event, key) => {
458
+ return store.get(key);
459
+ });
460
+ ```
461
+
462
+ ```js
463
+ const foo = await ipcRenderer.invoke('getStoreValue', 'foo');
464
+ ```
465
+
466
+ #### Can I use it for large amounts of data?
467
+
468
+ This package is not a database. It simply uses a JSON file that is read/written on every change. Prefer using it for smaller amounts of data like user settings, value caching, state, etc.
469
+
470
+ If you need to store large blobs of data, I recommend saving it to disk and to use this package to store the path to the file instead.
471
+
472
+ ## Related
473
+
474
+ - [electron-util](https://github.com/sindresorhus/electron-util) - Useful utilities for developing Electron apps and modules
475
+ - [electron-debug](https://github.com/sindresorhus/electron-debug) - Adds useful debug features to your Electron app
476
+ - [electron-context-menu](https://github.com/sindresorhus/electron-context-menu) - Context menu for your Electron app
477
+ - [electron-dl](https://github.com/sindresorhus/electron-dl) - Simplified file downloads for your Electron app
478
+ - [electron-unhandled](https://github.com/sindresorhus/electron-unhandled) - Catch unhandled errors and promise rejections in your Electron app
479
+ - [electron-reloader](https://github.com/sindresorhus/electron-reloader) - Simple auto-reloading for Electron apps during development
480
+ - [electron-serve](https://github.com/sindresorhus/electron-serve) - Static file serving for Electron apps
481
+ - [conf](https://github.com/sindresorhus/conf) - Simple config handling for your app or module
482
+ - [More…](https://github.com/search?q=user%3Asindresorhus+electron)