monfy v0.1.1
__ monfy
Multi configurations for different deployment environments (development, qa, staging, production, etc.) in simple object.
Installation
npm install --save-dev monfy
Quick Start
Base monfy tag: __{suffix}
Negation tag: __{suffix}$
const monfy = require('monfy');
//OR
const {monfy, monfyToArray} = require('monfy');
let baseConfig = {
a: 20,
a__dev: 50
};
let config = monfy(baseConfig, 'dev');
console.log(config);
//output -> {a: 50}
let config2 = monfy(baseConfig);
console.log(config2);
//output -> {a: 20}
API
monfy(config, suffix)
Return new object|array
which override base config.
(It keeps references to base config nested object whenever it`s possible)
config
Type: object|array
Object with config
suffix
Type: string
Name of suffix which distinguishes different configurations
monfyToArray(config, suffix)
Similar to monfy
; returns array from object values (without keys)
monfy tags
with key suffix
Example:
{ propertyA: 20, propertyA__dev: 50 }
Override
propertyA
to50
ifmonfy
called with suffix eqdev
with key suffix with negation operator
$
Example:
{ propertyB__dev$: true }
Only set
propertyB
totrue
to ifmonfy
called with suffix not eqdev
or override
propertyB
if already existsas key in nested object
Example:
{ loaders: [{ name: 'loader1' }, { __: 'dev', name: 'loader2' }] }
Keep object
{name: 'loader2'}
in array only when suffix eqdev
; else removeas key in nested object with negation operator
$
Example:
{ loaders: [{ name: 'loader1' }, { __: 'dev$', name: 'loader2' }] }
Keep object
{name: 'loader2'}
in array only when suffix not eqdev
; else remove
Examples
1.
let config = {
a:{
a2: true
},
a__dev:{
b1: [1,2,3]
},
c: {
c1:{
c2:{
c3: 'tak',
c3__test$: 'nie'
}
}
}
}
console.log(monfy(config));
Output:
{
a: {
a2: true
},
c: {
c1:{
c2:{
c3: 'nie'
}
}
}
}
2.
let config = [
{
plugin: 'plugin1',
options: {}
},
{
__: 'dev',
plugin: 'plugin2',
options: {}
}]
console.log(monfy(config, 'dev'));
Output:
[
{
plugin: 'plugin1',
options: {},
},
{
plugin: 'plugin2',
options: {}
}
]