From 58a7593f7edad761b122c995c6c9cd947fa8baa6 Mon Sep 17 00:00:00 2001 From: "Harish.K" Date: Thu, 6 Jul 2017 15:59:04 +0530 Subject: [PATCH] * Feature: parse env variable value with JSON.parse so that, we can set set config variables with proper type --- index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 539e6df..341b0a2 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,15 @@ if( !configDir ){ '\n Please set CONFIG_DIR env variable'); } - +function processSpecial( str ){ + var out; + try { + out = JSON.parse(str); + } catch (e) { + out = str; + } + return out; +} function loadConfig( name ){ var out = {}; @@ -74,7 +82,7 @@ assignDeep( finalConfig, loadConfig('default'), loadConfig( env ) ); Object.keys( process.env ).filter( function(v){ var match = v.match( envRegex ); if( match ){ - setProp( finalConfig, match[1], process.env[v] ); + setProp( finalConfig, match[1], processSpecial( process.env[v] ) ); } });