1.0.5 • Published 4 years ago

json-config-ts v1.0.5

Weekly downloads
23
License
MIT
Repository
github
Last release
4 years ago

json-config-ts

Build Status npm version

Easy-to-use config storage via JSON with optional base-64 encryption for sensitive data

Install

$ npm i -S json-config-ts

Usage

const Store = require('json-config-ts')
const store = new Store({
	directory: '/home',
	collection: 'foods',
	name: 'fruits',
	encryptedFields: ['creds.password'],
	defaultData: {
		apples: 2,
		oranges: 5,
		creds: {
			username: 'admin',
			password: 'password'
		}
	}
})

Specs

  • Config store in DIRECTORY/.json_config/COLLECTION/NAME.json Directory argument is optional, if not provided, homedir is used Collection argument is optional, if not provided, no additional collection folder is created

Params

  • String name: config name
  • String directory: database directory (optional directory to store JSON configs)
  • String collection: collection name (optional folder for json file)
  • Object defaultData: default data if json file does not exist
  • Arraystring encryptedFields: fields to be encrypted (in field.name form for nested keys)

Methods

  • data * returns unencrypted object
  • load() * loads current data from file, useful when updating config from concurrent processes
  • get(key) * gets value from path
  • set(key, value) * set value for path
  • update(data) * update config with object (preserves object structure and updates nested objects/properties)
  • write(data) * overwrites config with object
  • clear() * clears config and writes empty object

Documentation