atomic-json-store
v1.0.0
Published
Get and set configuration in a JSON file
Readme
atomic-json-store
A configuration store adapted from configstore, with the following key differences:
- Decoupled from file location (a small part's been extracted to
config-root) - Does not create the JSON file until necessary (
configstorecreates it upon instantiation) - Similarly, on
get,atomic-json-storedoes not create the parent directory - Throws on invalid JSON in the store, instead of rudely deleting the entire configuration
usage
Create a config at ~/.config/my-config.json:
const JSONStore = require('atomic-json-store')
const root = require('config-root')
const config = JSONStore(root + '/my-config.json')
config.set('name', 'milly')
config.get('name')
config.toJSON()
config.delete('name')
config.clear()store = Store(path, [options])
- path: where to save the JSON file
Options:
- defaults: an object with default keys and values to save upon instantiation
tip
Instead of setting defaults, which are saved to the JSON file, use family-store:
const JSONStore = require('atomic-json-store')
const FamilyStore = require('family-store')
const defs = FamilyStore('defaults', JSONStore('defaults.json'))
const beep = FamilyStore('beep', JSONStore('beep.json'))
beep.inherit(defs)
defs.set('port', 3000)
beep.get('port') // 3000install
With npm do:
npm install atomic-json-storelicense
BSD-2-Clause © ironSource. Original work © Google.
