Skip to content

Commit

Permalink
Adding custom interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
shidhincr committed Jun 23, 2016
1 parent 8dd7b6d commit 54ec5f2
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
6 changes: 1 addition & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"parser": "babel-eslint",
"ecmaFeatures": {
"jsx": true,
"modules": true
},
"env": {
"es6": true
},
"plugins": [
"react"
]
}
}
2 changes: 1 addition & 1 deletion build/reconfig.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/reconfig.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reconfig",
"version": "2.1.0",
"version": "2.2.0",
"description": "JavaScript configurations as they're meant to be. Kinda.",
"main": "build/reconfig.js",
"scripts": {
Expand Down
10 changes: 7 additions & 3 deletions reconfig.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import vpo from 'vpo';
let getConfigFromEnv = (prefix, separator = '_') => {
let envConfig = {};

_.forEach(process.env, (value, key) => {
_.forEach(process.env, (value, key) => {
if (_.includes(key, prefix)) {
let path = key.replace(prefix + separator, '').replace(new RegExp(separator, 'g'), '.');
vpo.set(envConfig, path, value);
Expand All @@ -25,9 +25,10 @@ export default class Reconfig {
* @param envPrefix
* @param separator
*/
constructor(config, envPrefix, separator) {
constructor(config, {envPrefix, separator, paramsInterpolation=[':', '']}={}) { // @TODO: Breaking changes for backward compatibility. Check with Alex
this._envPrefix = envPrefix;
this._separator = separator;
this._paramsInterpolation = paramsInterpolation;
this.set(config);
}

Expand Down Expand Up @@ -83,7 +84,10 @@ export default class Reconfig {
resolveParameters(value, parameters) {
for (let property in parameters) {
if (value) {
value = value.replace(RegExp(':' + property, 'g'), (parameters[property] || ''));
value = value.replace(
RegExp(this._paramsInterpolation[0] + property + this._paramsInterpolation[1], 'g'),
(parameters[property] || '')
);
}
}

Expand Down
Loading

0 comments on commit 54ec5f2

Please sign in to comment.