Skip to content

Commit

Permalink
feat: added support for variables in variables
Browse files Browse the repository at this point in the history
  • Loading branch information
niftylettuce committed Jul 2, 2020
1 parent 3144999 commit 133419c
Show file tree
Hide file tree
Showing 4 changed files with 1,459 additions and 1,695 deletions.
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ const setupEnv = (config = {}) => {
env[element] = Mustache.render(env[element], env);
}

//
// add support for variables defined in other variables
// (basically double looping will do the trick)
//
for (const element of keys) {
if (env[element].includes('{{'))
env[element] = Mustache.render(env[element], env);
}

env = dotenvParseVariables(env);
Object.assign(process.env, env);
return env;
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
"Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)"
],
"dependencies": {
"dotenv-extended": "^2.7.1",
"dotenv-parse-variables": "^0.2.3",
"mustache": "^4.0.0"
"dotenv-extended": "^2.8.0",
"dotenv-parse-variables": "^0.3.0",
"mustache": "^4.0.1"
},
"devDependencies": {
"ava": "2.x",
"codecov": "^3.6.5",
"codecov": "^3.7.0",
"cross-env": "6.x",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"husky": "3.x",
"lint-staged": "^10.0.7",
"nyc": "^15.0.0",
"prettier": "^1.19.1",
"remark-cli": "^7.0.1",
"remark-preset-github": "^0.0.16",
"lint-staged": "^10.2.11",
"nyc": "^15.1.0",
"prettier": "^2.0.5",
"remark-cli": "^8.0.0",
"remark-preset-github": "^2.0.0",
"xo": "0.24"
},
"engines": {
Expand Down
6 changes: 3 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ const test = require('ava');

const env = require('..');

test('NODE_ENV is test', t => {
test('NODE_ENV is test', (t) => {
t.is(process.env.NODE_ENV, 'test');
t.is(env().NODE_ENV, 'test');
});

test('is function', t => {
test('is function', (t) => {
t.true(typeof env === 'function');
});

test('returns object', t => {
test('returns object', (t) => {
t.true(typeof env() === 'object');
});
Loading

0 comments on commit 133419c

Please sign in to comment.