{"id":23243320,"url":"https://github.com/lucivuc/electron-prefs","last_synced_at":"2025-08-20T03:32:25.354Z","repository":{"id":57221839,"uuid":"128139335","full_name":"luciVuc/electron-prefs","owner":"luciVuc","description":"User preferences and configuration settings persistence feature for Electron-based apps.","archived":false,"fork":false,"pushed_at":"2020-07-07T03:54:22.000Z","size":73,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-06T21:49:20.401Z","etag":null,"topics":["configuration","electron","node","node-js","nodejs","settings-storage","user-preferences"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luciVuc.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-05T00:20:57.000Z","updated_at":"2024-12-26T08:19:26.000Z","dependencies_parsed_at":"2022-08-29T04:10:13.487Z","dependency_job_id":null,"html_url":"https://github.com/luciVuc/electron-prefs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/luciVuc/electron-prefs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luciVuc%2Felectron-prefs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luciVuc%2Felectron-prefs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luciVuc%2Felectron-prefs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luciVuc%2Felectron-prefs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luciVuc","download_url":"https://codeload.github.com/luciVuc/electron-prefs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luciVuc%2Felectron-prefs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271258891,"owners_count":24728178,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-20T02:00:09.606Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration","electron","node","node-js","nodejs","settings-storage","user-preferences"],"created_at":"2024-12-19T06:16:23.189Z","updated_at":"2025-08-20T03:32:25.135Z","avatar_url":"https://github.com/luciVuc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Electron-prefs\n\n\u003e *User preferences and configuration settings persistence feature for `Electron`-based apps.*\n\n## Overview\n\nAs `Electron` doesn't provide a built-in mechanism to easily persist and retrieve user preferences and configuration settings, install and include the `electron-prefs` module in your `Electron` project and let it handle that for you, so you can focus on your app development.\n\nYou can use the `electron-prefs` module directly in both the main and renderer process.\n\nAll user preferences and configuration settings are stored locally in a JSON file and can be accessed using `app.getPath('userData')`.\n\n## Installation\n\n`npm install electron-prefs`\n\nor\n\n`npm install --save electron-prefs`\n\n---\n\n## Usage\n\n```js\n\nconst electron = require(\"electron\");\nconst ElectronPrefs = require('electron-prefs');\nconst prefs = new ElectronPrefs({\n  fileName: \"config.js\",\n  defaults: {\n    window: {\n      width: 600,\n      height: 300\n    }\n  }\n});\n\nprefs.set('foo', 'bar');\nconsole.log(prefs.get('foo'));\n//=\u003e bar\n\nconsole.log(prefs.get(\"window\"));\n//=\u003e { width: 600, height: 300 }\n\n// use dot-notation to access nested properties\nprefs.set('window.width', 700);\nconsole.log(prefs.get(\"window\"));\n//=\u003e { width: 700, height: 300 }\nconsole.log(prefs.get('window.width'));\n//=\u003e 700\n\nprefs.delete('foo');\nconsole.log(prefs.get('foo'));\n//=\u003e undefined\n\n```\n\n---\n\n## API\n\n* ### ***Constructor:***\n\n  ▸ **`new ElectronPrefs(mOptions)`**\n\n  Creates an instance of `ElectronPrefs`.\n\n  *Parameters:*\n\n  |Type|Name|Description|\n  |:---|:---|:----------|\n  |`Object`|`mOptions`|A JSON-like object containing instance options|\n  |`String`|`mOptions.fileName`|The name of the file where preferences are stored|\n  |`String`|`mOptions.sFilePath`|The full path to the settings data file.|\n  |`Object`|`mOptions.defaults`|A set of default settings and/or preferences|\n\n  ---\n\n* ### ***Properties:***\n\n  |Type|Name|Description|Read-only|Static|\n  |:---|:---|:---|:---|:---|\n  |`Object`|**`defaults`**|The default values for this instance.|Yes|No|\n  |`String`|**`path`**|The full path to the configuration data file.|Yes|No|\n  |`Number`|**`size`**|he number of entries in the settings file (same as `length`).|Yes|No|\n  |`Number`|**`length`**|he number of entries in the settings file (same as `size`).|Yes|No|\n  |`Function`|**`superClass`**|Returns a reference to the super class.|Yes|Yes|\n\n  ---\n\n* ### ***Methods:***\n\n  ▸ **`ElectronPrefs.superClass.parseDataFile(sFilePath, mDefaults)`**\n\n    Reads the settings data file and returns its content as a `JSON` object.\n\n    ***Parameters:***\n\n    |Type|Name|Description|\n    |:---|:---|:----------|\n    |`String`|`sFilePath`|The full path to the settings data file.|\n    |`Object`|`mDefaults`|A set of default values to return if it fails loading the settings data file.|\n\n    ***Returns:*** `Object` - A `JSON`-like object containing the settings and user preferences iub the data file.\n\n    ---\n\n  ▸ **`ElectronPrefs.superClass.flattenObject(oObj, sSeparator)`**\n\n    *Flattens* nested objects into a single-depth object. For example:\n\n    `{ foo: 'bar', baz: { foo: 'bar' } }`\n\n    will turn into:\n\n    `{ foo: 'bar', 'baz.foo': 'bar' }`\n\n    ***Parameters:***\n\n    |Type|Name|Description|\n    |:---|:---|:----------|\n    |`Object`|`oObj`|The object (with nested objects) to *flatten*.|\n    |`String`|`sSeparator`|A string to use as separator between the keys. By default, the separator is `.` (dot).|\n\n    ***Returns:*** `Object` - The *flatten* object.\n\n    ---\n\n  ▸ **`ElectronPrefs.prototype.clear()`**\n\n    Removes all the settings in the settings list.\n\n    ***Parameters:*** None\n\n    ***Returns:*** `ElectronPrefs` - Self-reference for method chaining calls.\n\n    ---\n\n  ▸ **`ElectronPrefs.prototype.delete(sKey)`**\n\n    Removes the specified settings item from the settings list.\n\n    ***Parameters:***\n\n    |Type|Name|Description|\n    |:---|:---|:----------|\n    |`String`|`sKey`|The settings item to remove.|\n\n    ***Returns:*** `ElectronPrefs` - Self-reference for method chaining calls.\n\n    ---\n\n  ▸ **`ElectronPrefs.prototype.entries()`**\n\n    Returns a array containing all the `[key, value]` pairs for each settings item in the settings list.\n\n    ***Parameters:*** None\n\n    ***Returns:*** `Array` - The `[key, value]` pairs array.\n\n    ---\n\n  ▸ **`ElectronPrefs.prototype.forEach(fCallback, thisArg)`**\n\n    Executes the given function once for each `key-value` pair in the settings list.\n\n    ***Parameters:***\n\n    |Type|Name|Description|\n    |:---|:---|:----------|\n    |`Function`|`fCallback`|The function to execute for each `key-value` pair.|\n    |`Object`|`thisArg`|The value of `this` when executing the callback function.|\n\n    ***Returns:*** `ElectronPrefs` - Self-reference for method chaining calls.\n\n    ---\n\n  ▸ **`ElectronPrefs.prototype.has(sKey)`**\n\n    Returns whether the settings list contains a settings item with the given key or not.\n\n    ***Parameters:***\n\n    |Type|Name|Description|\n    |:---|:---|:----------|\n    |`String`|`sKey`|The key to check the settings list for.|\n\n    ***Returns:*** `Boolean` - `true` if the settings list contains a settings item with given key, or `false` otherwise.\n\n    ---\n\n  ▸ **`ElectronPrefs.prototype.get(sKey)`**\n\n    Gets the value of the settings item referenced by the given key in the settings list, or the whole list if no key is given.\n\n    ***Parameters:***\n\n    |Type|Name|Description|\n    |:---|:---|:----------|\n    |`String`|`sKey`|The key of a settings item in the settings list.|\n\n    ***Returns:*** `any` - The value of the settings item referenced by the key in the settings list, or the whole list if no key is given.\n\n    ---\n\n  ▸ **`ElectronPrefs.prototype.set(sKey, sValue)`**\n\n    Sets the given value as the value of the settings item referenced by the given key in the settings list.\n\n    ***Parameters:***\n\n    |Type|Name|Description|\n    |:---|:---|:----------|\n    |`String`|`sKey`|The key of a settings item in the settings list.|\n    |`any`|`sValue`|The value to assign to the settings item referenced by the key in the settings list.|\n\n    ***Returns:*** `ElectronPrefs` - Self-reference for method chaining calls.\n\n    ---\n\n  ▸ **`ElectronPrefs.prototype.keys()`**\n\n    Returns the names of all enumerable settings and preferences of this object.\n\n    ***Parameters:*** None\n\n    ***Returns:*** `String[]` - The names of the enumerable settings and preferences.\n\n    ---\n\n  ▸ **`ElectronPrefs.prototype.values()`**\n\n    Returns the names of all enumerable settings and preferences of this object.\n\n    ***Parameters:*** None\n\n    ***Returns:*** `String[]` - The values of the enumerable settings and preferences.\n\n---\n\n## Version\n\n  1.0.8\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucivuc%2Felectron-prefs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucivuc%2Felectron-prefs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucivuc%2Felectron-prefs/lists"}