1.0.16 • Published 5 years ago
@bravejs/routing v1.0.16
BraveJS Config
A simple package to add configration for a typescript application
Installation
npm i @bravejs/configUsage
Set a new instance of Config class, this class take a one parameter is an object of all configration values.
var config = new Config({
app: {
name: 'BraveJS',
version: 1.0.0
}
})Now let's say we need to read our app name.
config.get('app.name', 'defaultValue')The above example will look for app.name value if it doesn't exists it will return defaultValue
Let's add some other configration values.
config.set('app.foo', { foo: 'bar' })Imagine that you want to merge values with exists values of a key.
For example you want to merge app.foo value with { blah: 'blah' }.
config.merge('app.foo', { blash: 'blash' })Let's check if app.foo exists.
config.has('app.foo') // trueHmmm, what if we has an object and we want to prepend value to it, Let's just first define an object.
config.set('object', {
name: 'Hello',
world: 'World',
})To prepend a value to it.
config.prepend('object', {
test1: 'test1',
test2: 'test2',
})The results should be.
[
{
test1: 'test1',
test2: 'test2',
},
{
name: 'Hello',
world: 'World',
}
]There's also a method called push it's the same usage as prepend