Skip to content

Commit

Permalink
Merge pull request #26 from namshi/ES6
Browse files Browse the repository at this point in the history
ES6fying and adding custom interpolations for parameters.
  • Loading branch information
odino authored Jun 26, 2016
2 parents fa253ab + 179ed25 commit cf5f04c
Show file tree
Hide file tree
Showing 11 changed files with 288 additions and 259 deletions.
5 changes: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"moduleId": "Reconfig",
"presets": ["es2015","stage-0"],
"plugins": ["add-module-exports", "transform-es2015-modules-umd"]
}
9 changes: 9 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"parser": "babel-eslint",
"ecmaFeatures": {
"modules": true
},
"env": {
"es6": true
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.log
/node_modules
/node_modules
.idea
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,24 @@ var config = new reconfig({
var greetJohn = config.get('greet', {who: 'John'}); // Hello, John!
```

By default, reconfig uses `:` to interpolate the parameters. For example, in the above code, `:who` gets replaced by the parameter value.
You can specify your own interpolation for resolving the parameters by setting the `paramsInterpolation` option.

```javascript

var reconfig = require('reconfig');

var config = new reconfig({
greet: 'Hello {who}!'
}, {
paramsInterpolation: ['{', '}']
});

var greetJohn = config.get('greet', {who: 'John'}); // Hello, John!
```

Last but not least, reconfig lets you specify a default value to
return if a config valu you're trying to access doesnt exist:
return if a config value you're trying to access doesn't exist:

``` javascript
var reconfig = require('reconfig');
Expand Down Expand Up @@ -155,7 +171,7 @@ var configValues = {
b: [2]
};

var config = new reconfig(configValues, 'MYPREFIX');
var config = new reconfig(configValues, { envPrefix: 'MYPREFIX' });
```

and you'll be able to modify or add new values directly from your shell!
Expand All @@ -177,7 +193,7 @@ The default properties separator is: `_` (1 underscore).
You can use your custom separator passing it to the constructor as 3rd parameter:

```javascript
var config = new reconfig(configValues, 'MYPREFIX', '__');
var config = new reconfig(configValues, { envPrefix: 'MYPREFIX', separator: '__' });
```

## Installation
Expand Down
7 changes: 3 additions & 4 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "reconfig",
"main": "reconfig.js",
"version": "1.4.2",
"main": "build/reconfig.js",
"version": "2.0.0",
"homepage": "https://github.com/namshi/reconfig",
"authors": [
"Alex Nadalin <alessandro.nadalin@gmail.com>"
Expand All @@ -16,8 +16,7 @@
"no-bs"
],
"dependencies": {
"lodash": "4.5.1",
"vpo": "2.0.0"
"lodash": "4.5.1"
},
"license": "MIT",
"ignore": [
Expand Down
2 changes: 2 additions & 0 deletions build/reconfig.js

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

1 change: 1 addition & 0 deletions build/reconfig.min.js.map

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

24 changes: 18 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
{
"name": "reconfig",
"version": "2.1.0",
"version": "3.0.0",
"description": "JavaScript configurations as they're meant to be. Kinda.",
"main": "reconfig.js",
"main": "build/reconfig.js",
"scripts": {
"test": "RECONFIG_envKey=value RECONFIG_confKey=newValue RECONFIG_list_1_key=newValue mocha -b"
"test": "npm run build && RECONFIG_envKey=value RECONFIG_confKey=newValue RECONFIG_list_1_key=newValue mocha -b",
"compile": "babel reconfig.js -o build/reconfig.js",
"build": "npm run compile && uglifyjs build/reconfig.js -o build/reconfig.js --source-map build/reconfig.min.js.map",
"prepublish": "npm test"
},
"repository": {
"type": "git",
"url": "git://github.com/namshi/reconfig.git"
},
"files": [
"build"
],
"keywords": [
"config",
"configuration",
Expand All @@ -22,10 +28,16 @@
},
"homepage": "https://github.com/namshi/reconfig",
"devDependencies": {
"mocha": "*"
"babel-cli": "^6.10.1",
"babel-eslint": "^6.1.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-es2015-modules-umd": "^6.8.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-0": "^6.5.0",
"mocha": "*",
"uglify-js": "^2.6.4"
},
"dependencies": {
"lodash": "4.5.1",
"vpo": "2.0.0"
"lodash": "4.5.1"
}
}
Loading

0 comments on commit cf5f04c

Please # to comment.