@vanesyan/config
v2.0.0
Published
Simple in memory key-value configuration manager
Downloads
1
Maintainers
Readme
@vanesyan/config
Simple in memory configuration manager.
Installation
The easiest way to get the package is to install it through npm
$ npm install @vanesyan/config
Example
const config = new Config()
config.set('db.conn.port', 8912)
console.log(config.get('db.conn.port')) // => 8912
Application Programming Interface
Config()
const config = new Config()
Config#size
Returns config size (entries count).
config.size // => number
Config#get(keyPath)
Returns value associated to the keyPath
if exists otherwise returns
undefined
. Returns entire config keyPath
is omitted.
config.get('app.auth.secret') // => value or undefined
Config#set(keyPath[, val])
Set value under specified keyPath
in config. Set the entire config, if
keyPath
is an object and val
is omitted.
config.set('app.auth.secret', 'Your secret here!') // => undefined
Config#delete([keyPath])
Removes the specified element by keyPath
from the config. Removes the whole
config, if keyPath
is omitted. Returns true
if it was successfully removed
from config, otherwise false
.
config.delete('app.auth.secret') // => boolean
Config#has(keyPath)
Check whether an element with specified keyPath
exists or not.
Returns true
if exists, otherwise false
.
config.has('app.auth.secret') // => boolean
Licence
Released under the MIT licence.