Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add option to load config in sync mode (#67)
* feat: Add option to load config in sync mode * docs: Clarify usage for transform func in async, sync * refactor: Use funcRunner for chaining funcs and avoid code repetition * chore: Correct comment in creteExplorer for cache * docs: Add returns annotation for funcRunner * refactor: Set func name to funcRunner * test: Add tests for funcRunner * test: rm mysterious test failing on node <= 4
- Loading branch information
1 parent
334065d
commit bed5dc0
Showing
18 changed files
with
1,262 additions
and
485 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
var isPromise = require('is-promise'); | ||
|
||
/** | ||
* Runs given functions. If the `init` param is a promise, functions are | ||
* chained using `p.then()`. Otherwise, functions are chained by passing | ||
* the result of each function to the next. | ||
* | ||
* @param {*} init | ||
* @param {Array<Function>} funcs | ||
* @returns {*} A promise if `init` was one, otherwise result of function | ||
* chain execution. | ||
*/ | ||
module.exports = function funcRunner(init, funcs) { | ||
var async = isPromise(init); | ||
|
||
var res = init; | ||
funcs.forEach(function (func) { | ||
if (async === true) res = res.then(func); | ||
else res = func(res); | ||
}); | ||
|
||
return res; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.