Skip to content

Commit

Permalink
fix(env-var): default value not environment
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSharpieOne committed Apr 24, 2018
1 parent bc7e6da commit 076540b
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions packages/env-var/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,31 @@ export function getCurrentEnv(windowOverride = window) {
: windowOverride.location;
const subdomain = hostname.split('.availity')[0];

return (
Object.keys(environments).reduce((prev, env) => {
if (prev) return prev;
let envTests = environments[env];
if (!Array.isArray(envTests)) {
envTests = [envTests];
}
return Object.keys(environments).reduce((prev, env) => {
if (prev) return prev;
let envTests = environments[env];
if (!Array.isArray(envTests)) {
envTests = [envTests];
}

return (
envTests.some(test => {
switch (Object.prototype.toString.call(test)) {
case '[object String]':
return test === subdomain;
case '[object RegExp]':
return test.test(subdomain);
case '[object Function]':
return test();
default:
return false;
}
}) && env
);
}, '') || 'local'
);
return (
envTests.some(test => {
switch (Object.prototype.toString.call(test)) {
case '[object String]':
return test === subdomain;
case '[object RegExp]':
return test.test(subdomain);
case '[object Function]':
return test();
default:
return false;
}
}) && env
);
}, '');
}

export default function(varObj, windowOverride) {
const env = getCurrentEnv(windowOverride);
return varObj[env];
return typeof varObj[env] === 'undefined' ? varObj.local : varObj[env];
}

0 comments on commit 076540b

Please sign in to comment.