From 076540b212d419291f0ec76be1e2ba636c68e70b Mon Sep 17 00:00:00 2001 From: Evan Sharp Date: Tue, 24 Apr 2018 12:40:32 -0400 Subject: [PATCH] fix(env-var): default value not environment --- packages/env-var/index.js | 46 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/packages/env-var/index.js b/packages/env-var/index.js index 21d8a160b..1a42c6c0b 100644 --- a/packages/env-var/index.js +++ b/packages/env-var/index.js @@ -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]; }