mini-tools
Advanced tools
Comparing version 0.2.5 to 0.2.6
45
LEEME.md
@@ -20,2 +20,3 @@ <!--multilang v0 es:LEEME.md en:README.md --> | ||
[](https://david-dm.org/codenautas/mini-tools) | ||
[](http://codenautas.com/github/codenautas/mini-tools) | ||
@@ -180,4 +181,48 @@ <!--multilang buttons--> | ||
[!--lang:*--> | ||
### readConfig(list, opts) | ||
```js | ||
MiniTools.readConfig( | ||
[ | ||
{production: true}, | ||
'package.json', | ||
'other-configs.yml', | ||
'more-configs', | ||
], | ||
{whenNotExist:'ignore'} | ||
).then(function(config){ | ||
console.log(config); | ||
}); | ||
``` | ||
<!--lang:es--> | ||
Lee la configuración de la lista empezando por el primer archivo | ||
y agregando la configuración de los siguientes archivos | ||
(usando [best-globals.changing](https://www.npmjs.com/package/best-globals#changingoriginalconfig-changes-options)). | ||
Si el elemento de la lista es un nombre de archivo terminado en .json .yaml o .yml se lee y se parsea, | ||
si no tiene extensión se busca uno con alguna de esas extensiones, | ||
si es un objeto plano se usa directamente. | ||
**opciones** | ||
* whenNotExist:'ignore' | ||
* whenNotExist:'fail' | ||
<!--lang:en--] | ||
Reads the chain of configuration merging with [best-globals.changing](https://www.npmjs.com/package/best-globals#changingoriginalconfig-changes-options). | ||
If the list element is a fileName ending with .json .yaml o .yml, it reads and parse, | ||
if doesn't have extension it search first, | ||
if it is a plain object it uses directly. | ||
**options** | ||
* whenNotExist:'ignore' | ||
* whenNotExist:'fail' | ||
<!--lang:es--> | ||
## Licencia | ||
@@ -184,0 +229,0 @@ |
"use strict"; | ||
/*jshint eqnull:true */ | ||
/*jshint globalstrict:true */ | ||
/*jshint node:true */ | ||
@@ -88,3 +87,4 @@ /*eslint-disable no-console */ | ||
}).then(function(fileContent){ | ||
var htmlText=renderizer.render(fileContent); | ||
return renderizer.render(fileContent); | ||
}).then(function(htmlText){ | ||
MiniTools.serveText(htmlText,textType)(req,res); | ||
@@ -109,3 +109,4 @@ }).catch(MiniTools.serveErr(req,res,next)); | ||
MiniTools.readConfig = function readConfig(listOfFileNamesOrConfigObjects){ | ||
MiniTools.readConfig = function readConfig(listOfFileNamesOrConfigObjects, opts){ | ||
opts = opts || {}; | ||
return Promises.all(listOfFileNamesOrConfigObjects.map(function(fileNameOrObject){ | ||
@@ -122,3 +123,7 @@ if(typeof fileNameOrObject==="string"){ | ||
if(!exts.length){ | ||
return Promises.reject(Error('Config file does not found '+fileNameOrObject)); | ||
if(opts.whenNotExist==='ignore'){ | ||
return {ext:"direct", fileName:{}}; | ||
}else{ | ||
return Promises.reject(Error('Config file does not found '+fileNameOrObject)); | ||
} | ||
} | ||
@@ -152,4 +157,5 @@ var ext=exts.shift(); | ||
".json": fs.readJson.bind(fs), | ||
"direct": function(x){ return x; }, | ||
}; | ||
module.exports=MiniTools; |
{ | ||
"name": "mini-tools", | ||
"description": "mini tools for express and others", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"author": "Codenautas <codenautas@googlegroups.com>", | ||
@@ -43,3 +43,4 @@ "license": "MIT", | ||
"curly": true, | ||
"forin": true | ||
"forin": true, | ||
"esversion": 6 | ||
}, | ||
@@ -54,6 +55,9 @@ "eslintConfig": { | ||
"no-unused-vars": 1 | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 6 | ||
} | ||
}, | ||
"qa-control": { | ||
"package-version": "0.1.3", | ||
"package-version": "0.2.0", | ||
"run-in": "server", | ||
@@ -60,0 +64,0 @@ "test-appveyor": true, |
@@ -13,2 +13,3 @@ # mini-tools | ||
[](https://david-dm.org/codenautas/mini-tools) | ||
[](http://codenautas.com/github/codenautas/mini-tools) | ||
@@ -115,2 +116,30 @@ | ||
### readConfig(list, opts) | ||
```js | ||
MiniTools.readConfig( | ||
[ | ||
{production: true}, | ||
'package.json', | ||
'other-configs.yml', | ||
'more-configs', | ||
], | ||
{whenNotExist:'ignore'} | ||
).then(function(config){ | ||
console.log(config); | ||
}); | ||
``` | ||
Reads the chain of configuration merging with [best-globals.changing](https://www.npmjs.com/package/best-globals#changingoriginalconfig-changes-options). | ||
If the list element is a fileName ending with .json .yaml o .yml, it reads and parse, | ||
if doesn't have extension it search first, | ||
if it is a plain object it uses directly. | ||
**options** | ||
* whenNotExist:'ignore' | ||
* whenNotExist:'fail' | ||
## License | ||
@@ -117,0 +146,0 @@ |
@@ -323,2 +323,10 @@ "use strict"; | ||
}); | ||
it("must ignore if file not found {whenNotExist:'ignore'}", function(done){ | ||
MiniTools.readConfig([ | ||
'test/fixtures/read-config1.json', | ||
'test/fixtures/read-config0', | ||
], {whenNotExist:'ignore'}).then(function(cfg){ | ||
expect(cfg).to.eql({"config1": 1}); | ||
}).then(done,done); | ||
}); | ||
it("must control parameter types", function(done){ | ||
@@ -325,0 +333,0 @@ MiniTools.readConfig([ |
37585
554
148