npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@limbusfoundation/electronsave

v2.2.1

Published

Save Electron app data locally as JSON.

Downloads

11

Readme

ElectronSave

ElectronSave

Save Electron (or any other Node.js app) data locally as JSON.

Installation

To install ElectronSave, use npm:

npm install @limbusfoundation/electronsave

Usage

Import the module and create an instance:

const ElectronSave = require("@limbusfoundation/electronsave");
const config = new ElectronSave();

By default, the configuration file is stored in the user's home directory as appConfig.json. You can specify a custom path:

config.setPath("/absolute/path/to/config.json");

Methods

setPath(newPath)

Sets a custom path for the configuration file.

  • newPath (string) - Must be an absolute path.

getPath()

Returns the current path of the configuration file.

setEncryptionKey(key)

Sets an encryption key for secure storage.

  • key (string) - Must be 32 characters long.

setSchema(schema)

Sets a JSON schema for validating the configuration file data.

  • schema (object) - JSON schema object.

set(key, value)

Saves a key-value pair in the configuration file.

  • key (string) - The property name.
  • value (any) - The value to store.

Example:

config.set("theme", "dark");
config.set("user", { name: "John", age: 30 });

get(key,dafaultValue)

Retrieves a value from the configuration file.

  • key (string) - The property name.
  • defaultValue (any) - a value to return if the key is not found.

Example:

const theme = config.get("theme", "light");
console.log(theme); // Outputs: "dark"

delete(key)

Removes a key from the configuration file.

  • key (string) - The property name to delete.

Example:

config.delete("theme");

clear()

Removes all data from the configuration file.

Example:

config.clear();

backup()

Creates a backup of the current configuration file.

  • The backup file is saved with a timestamp format: backup-MM-DD-YYYY-HH-MM-SS.json.

Example:

config.backup(); // Saves backup to default location

restore(timestamp)

Restores a backup from the given timestamp.

  • timestamp (string) - The timestamp portion of the backup filename, formatted as MM-DD-YYYY-HH-MM-SS.

Example:

config.restore("03-20-2025-14-30-00"); // Restores from 'backup-03-20-2025-14-30-00.json'

onChange(key, callback)

Adds an observer for a key. The callback will be triggered when the key changes.

  • key (string) - The property name.
  • callback (function) - The function to call when the key changes.

Example:

config.onChange("theme", (newValue) => {
    console.log(`Theme changed to: ${newValue}`);
});

mask(data)

Encrypts the data using the AES-256-CBC algorithm.

  • data (any) - The data to encrypt.

Example:

const encrypted = config.mask({ sensitive: "data" });

unmask(encryptedData)

Decrypts the data using the AES-256-CBC algorithm.

  • encryptedData (string) - The encrypted data to decrypt.

Example:

const decrypted = config.unmask(encryptedData);

Learn Schema Validation

JSON Schema Validation Types

  1. Type Validations:

    • "type": "string"
    • "type": "number"
    • "type": "integer"
    • "type": "boolean"
    • "type": "object"
    • "type": "array"
    • "type": "null"
    • "type": "any"
  2. String Validation:

    • "minLength": <number> – Minimum length of the string.
    • "maxLength": <number> – Maximum length of the string.
    • "pattern": <regex> – The string must match the regular expression.
  3. Number Validation:

    • "minimum": <number> – Minimum value of the number.
    • "maximum": <number> – Maximum value of the number.
    • "exclusiveMinimum": <number> – Exclusive minimum value (greater than the specified number).
    • "exclusiveMaximum": <number> – Exclusive maximum value (less than the specified number).
    • "multipleOf": <number> – The number must be a multiple of the specified value.
  4. Array Validation:

    • "minItems": <number> – Minimum number of items in the array.
    • "maxItems": <number> – Maximum number of items in the array.
    • "uniqueItems": true – All items in the array must be unique.
  5. Object Validation:

    • "properties": {} – Define properties for objects and their types.
    • "required": [<propertyName>] – Specifies required properties for an object.
    • "additionalProperties": false – Disallow properties that are not defined in properties.
  6. Enum Validation:

    • "enum": [<value1>, <value2>, ...] – The value must be one of the listed options.
  7. Conditional Validation:

    • "if", "then", "else" – Conditional validation based on the value of another property. Example:
    {
      "if": {
        "properties": { "status": { "const": "active" } }
      },
      "then": {
        "properties": { "activationDate": { "type": "string" } }
      },
      "else": {
        "properties": { "activationDate": { "type": "null" } }
      }
    }
    
    

setSchema(schema)

Defines a JSON schema to validate the configuration file data.

Validation process:

  1. Schema definition: The schema specifies the structure, data types, and required fields for the configuration. Example:

    {
      "type": "object",
      "properties": {
        "theme": { "type": "string" },
        "user": {
          "type": "object",
          "properties": {
            "name": { "type": "string" },
            "age": { "type": "integer" }
          },
          "required": ["name", "age"]
        }
      },
      "required": ["theme", "user"]
    }
  2. 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.

  3. Error handling: If validation fails, the error details are available in validate.errors from the Ajv validator.

Example:

const config = new ElectronSave();
const schema = {
  type: "object",
  properties: {
    theme: { type: "string" }
  },
  required: ["theme"]
};

config.setSchema(schema);
config.set("theme", 123); // Error: "theme" must be a string

Benefits:

  • Ensures data integrity by enforcing structure and type constraints.
  • Prevents invalid data from being saved in the configuration file.

Notes

  • Ensure the file path set with setPath() is absolute.
  • Backups are stored using a timestamp format.
  • When restoring a backup, the existing configuration file is completely replaced with the backup content.
  • Encryption key must be defined for masking/unmasking functionality.

License

This project is licensed under the MIT License.