All Projects â†’ electron-userland â†’ Electron Json Storage

electron-userland / Electron Json Storage

📦 Easily write and read user settings in Electron apps

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Electron Json Storage

Rxkprefs
🛠 A small Kotlin library to make shared preferences easy + RxJava and Coroutines support
Stars: ✭ 264 (-77.87%)
Mutual labels:  settings, storage
Simple Settings
A simple way to manage your project settings.
Stars: ✭ 165 (-86.17%)
Mutual labels:  settings, json
Unqlite
An Embedded NoSQL, Transactional Database Engine
Stars: ✭ 1,583 (+32.69%)
Mutual labels:  json, storage
Proxy Storage
Provides an adapter for storage mechanisms (cookies, localStorage, sessionStorage, memoryStorage) and implements the Web Storage interface
Stars: ✭ 10 (-99.16%)
Mutual labels:  json, storage
Sirix
SirixDB is a temporal, evolutionary database system, which uses an accumulate only approach. It keeps the full history of each resource. Every commit stores a space-efficient snapshot through structural sharing. It is log-structured and never overwrites data. SirixDB uses a novel page-level versioning approach called sliding snapshot.
Stars: ✭ 638 (-46.52%)
Mutual labels:  json, storage
Sleekdb
Pure PHP NoSQL database with no dependency. Flat file, JSON based document database.
Stars: ✭ 450 (-62.28%)
Mutual labels:  json, storage
Datoji
A tiny JSON storage service. Create, Read, Update, Delete and Search JSON data.
Stars: ✭ 222 (-81.39%)
Mutual labels:  json, storage
Vue Ls
💥 Vue plugin for work with local storage, session storage and memory storage from Vue context
Stars: ✭ 468 (-60.77%)
Mutual labels:  json, storage
Conf
Simple config handling for your app or module
Stars: ✭ 707 (-40.74%)
Mutual labels:  json, storage
Pantry
🥑 Free data storage as a service that allows devs to store JSON for multiple apps & users. A good resource when building personal projects, apps for hackathons, and prototypes alike.
Stars: ✭ 42 (-96.48%)
Mutual labels:  json, storage
React Json Graph
React component for rendering graphs
Stars: ✭ 71 (-94.05%)
Mutual labels:  json
Rest
☕ REST: Yoctoframework — https://rest.n2o.dev
Stars: ✭ 71 (-94.05%)
Mutual labels:  json
Ffck
🦊 & 🧅 hardening
Stars: ✭ 72 (-93.96%)
Mutual labels:  settings
Zbox
Zero-details, privacy-focused in-app file system.
Stars: ✭ 1,185 (-0.67%)
Mutual labels:  storage
Metajson
Non-intrusive, high performance C++17 lightweight JSON de/serializer
Stars: ✭ 71 (-94.05%)
Mutual labels:  json
Devis
A microservices framework for Node.js
Stars: ✭ 72 (-93.96%)
Mutual labels:  json
Fipe Json
🚘 FIPE API - Listagem com preço médio de veículos: carro, moto e caminhão.
Stars: ✭ 71 (-94.05%)
Mutual labels:  json
Eloquent Settings
Eloquent Settings allows you to bind key-value pairs to any Laravel Eloquent model. It supports even casting for boolean, float or integer types.
Stars: ✭ 71 (-94.05%)
Mutual labels:  settings
Jokeapi
A REST API that serves uniformly and well formatted jokes in JSON, XML, YAML or plain text format that also offers a great variety of filtering methods
Stars: ✭ 71 (-94.05%)
Mutual labels:  json
Mson React
React and Material-UI Rendering Layer for MSON
Stars: ✭ 74 (-93.8%)
Mutual labels:  json

electron-json-storage

Easily write and read user settings in Electron apps

npm version dependencies Build Status Build status

Electron lacks an easy way to persist and read user settings for your application. electron-json-storage implements an API somehow similar to localStorage to write and read JSON objects to/from the operating system application data directory, as defined by app.getPath('userData').

Related modules:

Installation

Install electron-json-storage by running:

$ npm install --save electron-json-storage

You can require this module from either the main or renderer process (with and without remote).

Running on Electron >10 renderer processes

When loaded in renderer processes, this module will try to make use of electron.remote in order to fetch the userData path.

Electron 10 now defaults enableRemoteModule to false, which means that electron-json-storage will not be able to calculate a data path by default.

The solution is to manually call storage.setDataPath() before reading or writing any values or setting enableRemoteModule to true.

Documentation

storage.getDefaultDataPath() ⇒ String | Null

This function will return null when running in the renderer process without support for the remote IPC mechanism. You have to explicitly set a data path using .setDataPath() in these cases.

Kind: static method of storage
Summary: Get the default data path
Returns: String | Null - default data path
Access: public
Example

const defaultDataPath = storage.getDefaultDataPath()

storage.setDataPath(directory)

The default value will be used if the directory is undefined.

Kind: static method of storage
Summary: Set current data path
Access: public

Param Type Description
directory String | Undefined directory

Example

const os = require('os');
const storage = require('electron-json-storage');

storage.setDataPath(os.tmpdir());

storage.getDataPath() ⇒ String

Returns the current data path. It defaults to a directory called "storage" inside Electron's userData path.

Kind: static method of storage
Summary: Get current user data path
Returns: String - the user data path
Access: public
Example

const storage = require('electron-json-storage');

const dataPath = storage.getDataPath();
console.log(dataPath);

storage.get(key, [options], callback)

If the key doesn't exist in the user data, an empty object is returned. Also notice that the .json extension is added automatically, but it's ignored if you pass it yourself.

Passing an extension other than .json will result in a file created with both extensions. For example, the key foo.data will result in a file called foo.data.json.

Kind: static method of storage
Summary: Read user data
Access: public

Param Type Description
key String key
[options] Object options
[options.dataPath] String data path
callback function callback (error, data)

Example

const storage = require('electron-json-storage');

storage.get('foobar', function(error, data) {
  if (error) throw error;

  console.log(data);
});

storage.getMany(keys, [options], callback)

This function returns an object with the data of all the passed keys. If one of the keys doesn't exist, an empty object is returned for it.

Kind: static method of storage
Summary: Read many user data keys
Access: public

Param Type Description
keys Array.<String> keys
[options] Object options
[options.dataPath] String data path
callback function callback (error, data)

Example

const storage = require('electron-json-storage');

storage.getMany([ 'foobar', 'barbaz' ], function(error, data) {
  if (error) throw error;

  console.log(data.foobar);
  console.log(data.barbaz);
});

storage.getAll([options], callback)

This function returns an empty object if there is no data to be read.

Kind: static method of storage
Summary: Read all user data
Access: public

Param Type Description
[options] Object options
[options.dataPath] String data path
callback function callback (error, data)

Example

const storage = require('electron-json-storage');

storage.getAll(function(error, data) {
  if (error) throw error;

  console.log(data);
});

storage.set(key, json, [options], callback)

Kind: static method of storage
Summary: Write user data
Access: public

Param Type Description
key String key
json Object json object
[options] Object options
[options.dataPath] String data path
[options.validate] String validate writes by reading the data back
[options.prettyPrinting] boolean adds line breaks and spacing to the written data
callback function callback (error)

Example

const storage = require('electron-json-storage');

storage.set('foobar', { foo: 'bar' }, function(error) {
  if (error) throw error;
});

storage.has(key, [options], callback)

Kind: static method of storage
Summary: Check if a key exists
Access: public

Param Type Description
key String key
[options] Object options
[options.dataPath] String data path
callback function callback (error, hasKey)

Example

const storage = require('electron-json-storage');

storage.has('foobar', function(error, hasKey) {
  if (error) throw error;

  if (hasKey) {
    console.log('There is data stored as `foobar`');
  }
});

storage.keys([options], callback)

Kind: static method of storage
Summary: Get the list of saved keys
Access: public

Param Type Description
[options] Object options
[options.dataPath] String data path
callback function callback (error, keys)

Example

const storage = require('electron-json-storage');

storage.keys(function(error, keys) {
  if (error) throw error;

  for (var key of keys) {
    console.log('There is a key called: ' + key);
  }
});

storage.remove(key, [options], callback)

Notice this function does nothing, nor throws any error if the key doesn't exist.

Kind: static method of storage
Summary: Remove a key
Access: public

Param Type Description
key String key
[options] Object options
[options.dataPath] String data path
callback function callback (error)

Example

const storage = require('electron-json-storage');

storage.remove('foobar', function(error) {
  if (error) throw error;
});

storage.clear([options], callback)

Kind: static method of storage
Summary: Clear all stored data in the current user data path
Access: public

Param Type Description
[options] Object options
[options.dataPath] String data path
callback function callback (error)

Example

const storage = require('electron-json-storage');

storage.clear(function(error) {
  if (error) throw error;
});

Support

If you're having any problem, please raise an issue on GitHub and we'll be happy to help.

Tests

Run the test suite by doing:

$ npm test

Contribute

Before submitting a PR, please make sure that you include tests, and that jshint runs without any warning:

$ npm run-script lint

License

The project is licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].