git ssb

0+

clemo / env2obj



Commit 72bde94fde877d563ff0c8f5931269e9341eb0c6

init

Signed-off-by: clemo <clemo@cbcode.at>
clemo committed on 3/28/2016, 6:01:25 PM

Files changed

.gitignoreadded
README.mdadded
env2obj.jsadded
package.jsonadded
.gitignoreView
@@ -1,0 +1,1 @@
1 +node_modules/
README.mdView
@@ -1,0 +1,11 @@
1 +#env2obj
2 +
3 +a small module to convert envirument variables to a object
4 +
5 +## sample:
6 +
7 +```
8 +EXAMPLE_FOO=hello EXAMPLE_BAR=World node
9 +var config = require ('env2obj');
10 +config('EXAMPLE'); //{ foo: 'hello', bar: 'World' }
11 +```
env2obj.jsView
@@ -1,0 +1,18 @@
1 +var _ = require('lodash')
2 +module.exports = function(search){
3 + var configEnv = {};
4 + for(var envname in process.env){
5 + var deep = envname.split('_');
6 + if(deep[0] === search){
7 + var theone = process.env[envname.toUpperCase()];
8 + for(var i = deep.length-1; i > 0;i--){ //skip first/last
9 + var key = deep[i].toLowerCase();
10 + var newobj = {};
11 + newobj[key] = theone;
12 + theone = newobj;
13 + }
14 + _.merge(configEnv,theone);
15 + }
16 + }
17 + return configEnv;
18 +}
package.jsonView
@@ -1,0 +1,19 @@
1 +{
2 + "name": "env2obj",
3 + "version": "1.0.0",
4 + "description": "converts envirument variables to a object",
5 + "main": "env2obj.js",
6 + "dependencies": {
7 + "lodash": "^4.6.1"
8 + },
9 + "scripts": {
10 + "test": "echo \"Error: no test specified\" && exit 1"
11 + },
12 + "keywords": [
13 + "envirument",
14 + "object",
15 + "config"
16 + ],
17 + "author": "Clemens Burger",
18 + "license": "GPL-3.0"
19 +}

Built with git-ssb-web