configstore-fork

Easily load and save config without having to think about where and how

Deprecated. Please use original configstore.
Last updated 7 years ago by jason-dent .
BSD-2-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install configstore-fork 
SYNC missed versions from official npm registry.

Note this is a fork of configstore

This fork only contains minor differences:

  1. Reads are side effect free
  2. Only create the store directory on write if it does not exist
  3. Only writes to the store if there is something to write

This fork is not meant to be a general replacement for configstore. It was solely created to solve issues relating to the changes above. All credit for this package should go to the original authors.

configstore Build Status

Easily load and persist config without having to think about where and how

Config is stored in a JSON file located in $XDG_CONFIG_HOME or ~/.config.
Example: ~/.config/configstore/some-id.json

If you need this for Electron, check out electron-store instead.

Usage

const Configstore = require('configstore');
const pkg = require('./package.json');

// create a Configstore instance with an unique ID e.g.
// Package name and optionally some default values
const conf = new Configstore(pkg.name, {foo: 'bar'});

console.log(conf.get('foo'));
//=> 'bar'

conf.set('awesome', true);
console.log(conf.get('awesome'));
//=> true

// Use dot-notation to access nested properties
conf.set('bar.baz', true);
console.log(conf.get('bar'));
//=> {baz: true}

conf.delete('awesome');
console.log(conf.get('awesome'));
//=> undefined

API

Configstore(packageName, [defaults], [options])

Returns a new instance.

packageName

Type: string

Name of your package.

defaults

Type: Object

Default config.

options

globalConfigPath

Type: boolean
Default: false

Store the config at $CONFIG/package-name/config.json instead of the default $CONFIG/configstore/package-name.json. This is not recommended as you might end up conflicting with other tools, rendering the "without having to think" idea moot.

Instance

You can use dot-notation in a key to access nested properties.

.set(key, value)

Set an item.

.set(object)

Set multiple items at once.

.get(key)

Get an item.

.has(key)

Check if an item exists.

.delete(key)

Delete an item.

.clear()

Delete all items.

.size

Get the item count.

.path

Get the path to the config file. Can be used to show the user where the config file is located or even better open it for them.

.all

Get all the config as an object or replace the current config with an object:

conf.all = {
	hello: 'world'
};

License

BSD license
Copyright Google

Current Tags

  • 3.1.6                                ...           latest (7 years ago)

3 Versions

  • 3.1.6 [deprecated]           ...           7 years ago
  • 3.1.5 [deprecated]           ...           7 years ago
  • 3.1.3 [deprecated]           ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (6)
Dev Dependencies (2)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |