simple-parameter-injector
v2.0.0
Published
Injects parameters into strings (of objects and arrays)
Downloads
6
Maintainers
Readme
Simple Parameter Injector
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
import ParamsInjector from 'simple-parameter-injector';
// injecting a string into another string
const str = ParamsInjector.inject('replace this ? with a real string', 'placeholder');
// output: replace this placeholder with a real string
// injecting a number into a string
const str = ParamsInjector.inject('mambo nr ?', 5);
// output: mambo nr 5
// injecting an array of placeholders into a string
const 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
const placeholders = {
firstString: 'placeholder',
secondString: 'real string'
};
const 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
const placeholders = {
firstString: 'placeholder',
secondString: 'real string'
};
const obj = {
firstKey: 'i need a :firstString',
secondKey: 'with a :secondString'
};
const 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
- Fork it!
- Create your feature branch (
git checkout -b feature/my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/my-new-feature
) - Create new Pull Request
Author
Dimitri König (@dimitrikoenig)
License
The Simple Parameter Injector is open-sourced software licensed under the MIT license