Comparing version 1.1.0 to 1.2.0
34
index.js
@@ -48,3 +48,14 @@ 'use strict'; | ||
set: function(prop, value, save) { | ||
config[prop] = value; | ||
let schema = config; // a moving reference to internal objects within obj | ||
let pList = prop.split(':'); | ||
let len = pList.length; | ||
for(let i = 0; i < len-1; i++) { | ||
let elem = pList[i]; | ||
if(!schema[elem]){ | ||
schema[elem] = {}; | ||
} | ||
schema = schema[elem]; | ||
} | ||
schema[pList[len-1]] = value; | ||
if(!save && saveToDisk){ | ||
@@ -58,3 +69,3 @@ fs.writeFileSync(currentPath, JSON.stringify(config, null, 4) + '\n', 'utf8'); | ||
let tempConfig = {}; | ||
for(let prop in data){ | ||
for(let prop in data){ // jshint ignore:line | ||
if (data.hasOwnProperty(prop)) { | ||
@@ -64,7 +75,16 @@ tempConfig[prop] = data[prop]; | ||
} | ||
tempConfig[prop] = value; | ||
let schema = tempConfig; // a moving reference to internal objects within obj | ||
let pList = prop.split(':'); | ||
let len = pList.length; | ||
for(let i = 0; i < len-1; i++) { | ||
let elem = pList[i]; | ||
if(!schema[elem]){ | ||
schema[elem] = {}; | ||
} | ||
schema = schema[elem]; | ||
} | ||
schema[pList[len-1]] = value; | ||
fs.writeFileSync(currentPath, JSON.stringify(tempConfig, null, 4) + '\n', 'utf8'); | ||
} | ||
} | ||
config[prop] = value; | ||
}, | ||
@@ -83,3 +103,9 @@ joinGets: function(gets, joins){ | ||
return finalResult; | ||
}, | ||
args: function(save){ | ||
process.argv.slice(2).forEach(function(val) { | ||
val = val.slice(2).split('='); // Gets us ['db:host', 'localhost'] from '--db:host=localhost' | ||
module.exports.set(val[0], val[1], save); | ||
}); | ||
} | ||
}; |
{ | ||
"name": "cz", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A simple config utility for nodejs", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -23,4 +23,4 @@ # cz | ||
// Below are two ways of getting objects, the bottom one is the prefered way as it joins the retrieved values for you | ||
console.log('db:host+db:username+db:password+db:port', 'mongodb://' + config.get('db:username') + ':' + config.get('db:password') + '@' + config.get('db:host') + ':' + config.get('db:port') + '/' + config.get('db:collection')); | ||
console.log('db:host+db:username+db:password+db:port', 'mongodb://' + config.joinGets(['db:username', 'db:password', 'db:host', 'db:port', 'db:collection'], [':', '@', ':', '/'])); | ||
console.log('mongodb://' + config.get('db:username') + ':' + config.get('db:password') + '@' + config.get('db:host') + ':' + config.get('db:port') + '/' + config.get('db:collection')); | ||
console.log('mongodb://' + config.joinGets(['db:username', 'db:password', 'db:host', 'db:port', 'db:collection'], [':', '@', ':', '/'])); | ||
```` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6977
7
118