simple-parameter-injector

Injects parameters into strings (of objects and arrays)


Keywords
objects, arrays, parameter, injection, replacement, replace
License
MIT
Install
npm install simple-parameter-injector@1.0.1

Documentation

Simple Parameter Injector Build Status

npm version Test Coverage Code Climate Dependency Status

Simple Parameter Injector is a Javascript module which injects parameters out of array's and object's into strings.

Installation

Run this command:

$ npm install simple-parameter-injector --save

Examples

var paramsInjector = require('simple-parameter-injector');

// injecting a string into another string
var str = paramsInjector.inject('replace this ? with a real string', 'placeholder');
// output: replace this placeholder with a real string


// injecting a number into a string
var str = paramsInjector.inject('mambo nr ?', 5);
// output: mambo nr 5


// injecting an array of placeholders into a string
var str = paramsInjector.inject('replace this ? with another ?', ['placeholder', 'real string']);
// output: replace this placeholder with another real string


// injecting an object of named placeholders into a string
var placeholders = {
    firstString: 'placeholder',
    secondString: 'real string'
};
var str = paramsInjector.inject('replace this :firstString with another :secondString', placeholders);
// output: replace this placeholder with another real string


// injecting an object of named placeholders into another object with placeholders
var placeholders = {
    firstString: 'placeholder',
    secondString: 'real string'
};
var obj = {
    firstKey: 'i need a :firstString',
    secondKey: 'with a :secondString'
};
var resultObject = paramsInjector.inject(obj, placeholders);
// resultObject: {
//     firstKey: 'i need a placeholder',
//     secondKey: 'with a real string'
// }

Versioning

Simple Parameter Injector follows Semantic Versioning 2.0.0

Contributing

  1. Fork it!
  2. Create your feature branch (git checkout -b feature/my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin feature/my-new-feature)
  5. Create new Pull Request

Author

Dimitri König (@dimitrikoenig)

License

The Simple Parameter Injector is open-sourced software licensed under the MIT license