think-config
Advanced tools
Comparing version 1.0.3 to 1.0.4
43
index.js
@@ -10,3 +10,3 @@ const helper = require('think-helper'); | ||
*/ | ||
constructor(config = {}){ | ||
constructor(config = {}) { | ||
this.config = config; | ||
@@ -19,15 +19,15 @@ } | ||
*/ | ||
get(name, config){ | ||
if(!name){ | ||
get(name, config) { | ||
if (!name) { | ||
return this.config; | ||
} | ||
config = config || this.config; | ||
if(name.indexOf('.') === -1){ | ||
if (name.indexOf('.') === -1) { | ||
return config[name]; | ||
} | ||
name = name.split('.'); | ||
let length = name.length; | ||
const length = name.length; | ||
name.some((item, index) => { | ||
config = config[item]; | ||
if(index !== length - 1 && !helper.isObject(config)){ | ||
if (index !== length - 1 && !helper.isObject(config)) { | ||
config = undefined; | ||
@@ -43,4 +43,4 @@ return true; | ||
*/ | ||
set(name, value){ | ||
if(name.indexOf('.') === -1){ | ||
set(name, value) { | ||
if (name.indexOf('.') === -1) { | ||
this.config[name] = value; | ||
@@ -50,8 +50,8 @@ } | ||
name = name.split('.'); | ||
let length = name.length; | ||
const length = name.length; | ||
name.forEach((item, index) => { | ||
if(index === length - 1){ | ||
if (index === length - 1) { | ||
config[item] = value; | ||
}else{ | ||
if(!helper.isObject(config[item])){ | ||
} else { | ||
if (!helper.isObject(config[item])) { | ||
config[item] = {}; | ||
@@ -66,9 +66,9 @@ } | ||
function getConfigFn(configs, isMultiModule){ | ||
let configInstances = {}; | ||
if(isMultiModule){ | ||
for(let name in configs){ | ||
function getConfigFn(configs, isMultiModule) { | ||
const configInstances = {}; | ||
if (isMultiModule) { | ||
for (const name in configs) { | ||
configInstances[name] = new Config(configs[name]); | ||
} | ||
}else{ | ||
} else { | ||
configInstances.common = new Config(configs); | ||
@@ -78,13 +78,14 @@ } | ||
let conf = configInstances.common; | ||
if(isMultiModule && m){ | ||
if (isMultiModule && m) { | ||
conf = configInstances[m]; | ||
} | ||
if(value === undefined){ | ||
if (!conf) return; | ||
if (value === undefined) { | ||
return conf.get(name); | ||
} | ||
conf.set(name, value); | ||
} | ||
}; | ||
} | ||
exports.Config = Config; | ||
exports.getConfigFn = getConfigFn; | ||
exports.getConfigFn = getConfigFn; |
{ | ||
"name": "think-config", | ||
"description": "config for ThinkJS", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"author": { | ||
@@ -11,3 +11,4 @@ "name": "welefen", | ||
"test": "eslint index.js && nyc ava test/", | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov" | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov", | ||
"lint": "eslint index.js" | ||
}, | ||
@@ -31,7 +32,6 @@ "ava": { | ||
"ava": "^0.18.0", | ||
"babel-core": "^6.22.1", | ||
"babel-eslint": "^7.1.1", | ||
"codecov": "^1.0.1", | ||
"coveralls": "^2.11.16", | ||
"eslint": "2.8.0", | ||
"eslint": "^4.3.0", | ||
"eslint-config-think": "^1.0.1", | ||
"nyc": "^7.1.0" | ||
@@ -38,0 +38,0 @@ }, |
7142
6
7
150