0.1.1 • Published 7 years ago

monfy v0.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

__ monfy

npm version Build Status Coverage Status Dependency Status

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 to 50 if monfy called with suffix eq dev

      
  • with key suffix with negation operator $

    Example:

      {
          propertyB__dev$: true
      }

    Only set propertyB to true to if monfy called with suffix not eq dev

    or override propertyB if already exists

  • as key in nested object

    Example:

      {
          loaders: [{
            name: 'loader1'
          },
          {  
            __: 'dev',
            name: 'loader2'
          }]
      }

    Keep object {name: 'loader2'} in array only when suffix eq dev; else remove

  • as key in nested object with negation operator $

    Example:

      {
          loaders: [{
            name: 'loader1'
          },
          {  
            __: 'dev$',
            name: 'loader2'
          }]
      }

    Keep object {name: 'loader2'} in array only when suffix not eq dev; 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: {}
        }
    ]
0.1.1

7 years ago

0.1.0

7 years ago