{"id":26550013,"url":"https://github.com/limbus-foundation/electron-save","last_synced_at":"2026-04-15T08:37:53.738Z","repository":{"id":283387201,"uuid":"951602636","full_name":"Limbus-Foundation/electron-save","owner":"Limbus-Foundation","description":"Electron Save Data Module","archived":false,"fork":false,"pushed_at":"2025-03-20T00:27:45.000Z","size":2,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-20T01:29:12.385Z","etag":null,"topics":["electron","js","json","nodejs","savedata"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Limbus-Foundation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-20T00:14:36.000Z","updated_at":"2025-03-20T00:27:48.000Z","dependencies_parsed_at":"2025-03-20T03:45:59.765Z","dependency_job_id":null,"html_url":"https://github.com/Limbus-Foundation/electron-save","commit_stats":null,"previous_names":["limbus-foundation/electron-save"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Limbus-Foundation%2Felectron-save","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Limbus-Foundation%2Felectron-save/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Limbus-Foundation%2Felectron-save/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Limbus-Foundation%2Felectron-save/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Limbus-Foundation","download_url":"https://codeload.github.com/Limbus-Foundation/electron-save/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244920731,"owners_count":20532092,"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","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":["electron","js","json","nodejs","savedata"],"created_at":"2025-03-22T07:22:54.354Z","updated_at":"2026-04-15T08:37:53.696Z","avatar_url":"https://github.com/Limbus-Foundation.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\n![ElectronSave](https://github.com/user-attachments/assets/3c30a01c-628c-4cf5-a18e-9176ff4f0de8)\n\n# ElectronSave\n\nSave Electron (or any other Node.js app) data locally as JSON.\n\n## Installation\n\nTo install ElectronSave, use npm:\n\n```sh\nnpm install @limbusfoundation/electronsave\n```\n\n## Usage\n\nImport the module and create an instance:\n\n```javascript\nconst ElectronSave = require(\"@limbusfoundation/electronsave\");\nconst config = new ElectronSave();\n```\n\nBy default, the configuration file is stored in the user's home directory as `appConfig.json`. You can specify a custom path:\n\n```javascript\nconfig.setPath(\"/absolute/path/to/config.json\");\n```\n\n### Methods\n\n#### `setPath(newPath)`\n\nSets a custom path for the configuration file.\n\n- `newPath` (string) - Must be an absolute path.\n\n#### `getPath()`\n\nReturns the current path of the configuration file.\n\n#### `setEncryptionKey(key)`\n\nSets an encryption key for secure storage.\n\n- `key` (string) - Must be 32 characters long.\n\n#### `setSchema(schema)`\n\nSets a JSON schema for validating the configuration file data.\n\n- `schema` (object) - JSON schema object.\n\n#### `set(key, value)`\n\nSaves a key-value pair in the configuration file.\n\n- `key` (string) - The property name.\n- `value` (any) - The value to store.\n\n**Example:**\n\n```javascript\nconfig.set(\"theme\", \"dark\");\nconfig.set(\"user\", { name: \"John\", age: 30 });\n```\n\n#### `get(key,dafaultValue)`\n\nRetrieves a value from the configuration file.\n\n- `key` (string) - The property name.\n- `defaultValue` (any) - a value to return if the key is not found.\n\n**Example:**\n\n```javascript\nconst theme = config.get(\"theme\", \"light\");\nconsole.log(theme); // Outputs: \"dark\"\n```\n\n#### `delete(key)`\n\nRemoves a key from the configuration file.\n\n- `key` (string) - The property name to delete.\n\n**Example:**\n\n```javascript\nconfig.delete(\"theme\");\n```\n\n#### `clear()`\n\nRemoves all data from the configuration file.\n\n**Example:**\n\n```javascript\nconfig.clear();\n```\n\n#### `backup()`\n\nCreates a backup of the current configuration file.\n\n- The backup file is saved with a timestamp format: `backup-MM-DD-YYYY-HH-MM-SS.json`.\n\n**Example:**\n\n```javascript\nconfig.backup(); // Saves backup to default location\n```\n\n#### `restore(timestamp)`\n\nRestores a backup from the given timestamp.\n\n- `timestamp` (string) - The timestamp portion of the backup filename, formatted as `MM-DD-YYYY-HH-MM-SS`.\n\n**Example:**\n\n```javascript\nconfig.restore(\"03-20-2025-14-30-00\"); // Restores from 'backup-03-20-2025-14-30-00.json'\n```\n\n#### `onChange(key, callback)`\n\nAdds an observer for a key. The callback will be triggered when the key changes.\n\n- `key` (string) - The property name.\n- `callback` (function) - The function to call when the key changes.\n\n**Example:**\n\n```javascript\nconfig.onChange(\"theme\", (newValue) =\u003e {\n    console.log(`Theme changed to: ${newValue}`);\n});\n```\n\n#### `mask(data)`\n\nEncrypts the data using the AES-256-CBC algorithm.\n\n- `data` (any) - The data to encrypt.\n\n**Example:**\n\n```javascript\nconst encrypted = config.mask({ sensitive: \"data\" });\n```\n\n#### `unmask(encryptedData)`\n\nDecrypts the data using the AES-256-CBC algorithm.\n\n- `encryptedData` (string) - The encrypted data to decrypt.\n\n**Example:**\n\n```javascript\nconst decrypted = config.unmask(encryptedData);\n```\n\n## Learn Schema Validation \n\n### JSON Schema Validation Types\n\n1. **Type Validations:**\n   - `\"type\": \"string\"`\n   - `\"type\": \"number\"`\n   - `\"type\": \"integer\"`\n   - `\"type\": \"boolean\"`\n   - `\"type\": \"object\"`\n   - `\"type\": \"array\"`\n   - `\"type\": \"null\"`\n   - `\"type\": \"any\"`\n\n2. **String Validation:**\n   - `\"minLength\": \u003cnumber\u003e` – Minimum length of the string.\n   - `\"maxLength\": \u003cnumber\u003e` – Maximum length of the string.\n   - `\"pattern\": \u003cregex\u003e` – The string must match the regular expression.\n\n3. **Number Validation:**\n   - `\"minimum\": \u003cnumber\u003e` – Minimum value of the number.\n   - `\"maximum\": \u003cnumber\u003e` – Maximum value of the number.\n   - `\"exclusiveMinimum\": \u003cnumber\u003e` – Exclusive minimum value (greater than the specified number).\n   - `\"exclusiveMaximum\": \u003cnumber\u003e` – Exclusive maximum value (less than the specified number).\n   - `\"multipleOf\": \u003cnumber\u003e` – The number must be a multiple of the specified value.\n\n4. **Array Validation:**\n   - `\"minItems\": \u003cnumber\u003e` – Minimum number of items in the array.\n   - `\"maxItems\": \u003cnumber\u003e` – Maximum number of items in the array.\n   - `\"uniqueItems\": true` – All items in the array must be unique.\n\n5. **Object Validation:**\n   - `\"properties\": {}` – Define properties for objects and their types.\n   - `\"required\": [\u003cpropertyName\u003e]` – Specifies required properties for an object.\n   - `\"additionalProperties\": false` – Disallow properties that are not defined in `properties`.\n\n6. **Enum Validation:**\n   - `\"enum\": [\u003cvalue1\u003e, \u003cvalue2\u003e, ...]` – The value must be one of the listed options.\n\n7. **Conditional Validation:**\n   - `\"if\"`, `\"then\"`, `\"else\"` – Conditional validation based on the value of another property.\n   Example:\n   ```json\n   {\n     \"if\": {\n       \"properties\": { \"status\": { \"const\": \"active\" } }\n     },\n     \"then\": {\n       \"properties\": { \"activationDate\": { \"type\": \"string\" } }\n     },\n     \"else\": {\n       \"properties\": { \"activationDate\": { \"type\": \"null\" } }\n     }\n   }\n\n\n### `setSchema(schema)`\n\nDefines a JSON schema to validate the configuration file data.\n\n#### Validation process:\n1. **Schema definition**: The schema specifies the structure, data types, and required fields for the configuration.\n   Example:\n   ```json\n   {\n     \"type\": \"object\",\n     \"properties\": {\n       \"theme\": { \"type\": \"string\" },\n       \"user\": {\n         \"type\": \"object\",\n         \"properties\": {\n           \"name\": { \"type\": \"string\" },\n           \"age\": { \"type\": \"integer\" }\n         },\n         \"required\": [\"name\", \"age\"]\n       }\n     },\n     \"required\": [\"theme\", \"user\"]\n   }\n   ```\n\n2. **Validation**: When saving data with `set(key, value)`, the data is validated against the schema. If invalid (wrong type, missing fields), it won't be saved, and an error is logged.\n\n3. **Error handling**: If validation fails, the error details are available in `validate.errors` from the `Ajv` validator.\n\n#### Example:\n```javascript\nconst config = new ElectronSave();\nconst schema = {\n  type: \"object\",\n  properties: {\n    theme: { type: \"string\" }\n  },\n  required: [\"theme\"]\n};\n\nconfig.setSchema(schema);\nconfig.set(\"theme\", 123); // Error: \"theme\" must be a string\n```\n\n#### Benefits:\n- Ensures data integrity by enforcing structure and type constraints.\n- Prevents invalid data from being saved in the configuration file.\n\n\n## Notes\n- Ensure the file path set with `setPath()` is absolute.\n- Backups are stored using a timestamp format.\n- When restoring a backup, the existing configuration file is completely replaced with the backup content.\n- Encryption key must be defined for masking/unmasking functionality.\n\n## License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimbus-foundation%2Felectron-save","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flimbus-foundation%2Felectron-save","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimbus-foundation%2Felectron-save/lists"}