Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

atomic-json-store

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

atomic-json-store

Get and set configuration in a JSON file

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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 (configstore creates it upon instantiation)
  • Similarly, on get, atomic-json-store does not create the parent directory
  • Throws on invalid JSON in the store, instead of rudely deleting the entire configuration

npm status node

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') // 3000

install

With npm do:

npm install atomic-json-store

license

BSD-2-Clause © ironSource. Original work © Google.

Keywords

FAQs

Package last updated on 06 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc