async-helpers
Advanced tools
Comparing version 0.3.11 to 0.3.12
45
index.js
@@ -149,3 +149,3 @@ /*! | ||
if (options.wrap && helper.wrapped !== true) { | ||
return this.wrapper(helper, helper, this); | ||
return this.wrapper(helper.name || helper.displayName, helper, this); | ||
} | ||
@@ -179,2 +179,5 @@ | ||
if (helper.wrapped !== true) { | ||
if (typeOf(helper) === 'function' && !helper.name && !helper.displayName) { | ||
helper.displayName = key; | ||
} | ||
res[key] = this.wrapHelper(helper, options); | ||
@@ -458,4 +461,4 @@ } else { | ||
if (typeof val !== 'string') { | ||
throw new TypeError('AsyncHelpers#resolveIds expected val to be a string'); | ||
if (['string', 'number', 'boolean'].indexOf(typeOf(val)) === -1) { | ||
console.log(`[WARNING]: AsyncHelpers#resolveIds ${formatWarning(key, val)}`); | ||
} | ||
@@ -503,2 +506,33 @@ | ||
/** | ||
* Format a warning message to provide better information about the | ||
* helper and the arguments passed to the helper when the returned results aren't | ||
* what's expected. | ||
* | ||
* @param {String} `key` Helper async id used to find more information about the helper. | ||
* @param {Mixed} `val` Value returned from the helper | ||
* @return {String} Formatted warning message | ||
*/ | ||
function formatWarning(key, val) { | ||
var helper = stash[key]; | ||
if (!helper) { | ||
return `Expected returned result to be a string, number or boolean. Instead result is typeof "${typeOf(val)}"`; | ||
} | ||
var args = helper.args.slice(); | ||
args = args.filter(function(arg) { | ||
if (!arg || typeof arg === 'function') { | ||
return false; | ||
} | ||
return true; | ||
}).map(function(arg) { | ||
return stringify(arg); | ||
}); | ||
var res = `Expected the returned result from "${helper.name}" to be a string, number or boolean. Instead result is typeof "${typeOf(val)}".`; | ||
// res += `\nHelper arguments: \`${args.join(', ')}\``; | ||
return res; | ||
} | ||
/** | ||
* Create a prefix to use when generating an async id. | ||
@@ -570,3 +604,6 @@ * | ||
var len = Object.keys(helpers).length; | ||
var min = (helpers.async || helpers.sync) ? 1 : 0; | ||
var min = ['async', 'sync', 'displayName'].reduce(function(acc, name) { | ||
acc += (helpers[name] ? 1 : 0); | ||
return acc; | ||
}, 0); | ||
return len > min; | ||
@@ -573,0 +610,0 @@ } |
{ | ||
"name": "async-helpers", | ||
"description": "Use async helpers in templates with engines that typically only handle sync helpers. Handlebars and Lodash have been tested.", | ||
"version": "0.3.11", | ||
"version": "0.3.12", | ||
"homepage": "https://github.com/doowb/async-helpers", | ||
@@ -6,0 +6,0 @@ "author": "Brian Woodward (https://github.com/doowb)", |
@@ -36,3 +36,3 @@ # async-helpers [](https://www.npmjs.com/package/async-helpers) [](https://npmjs.org/package/async-helpers) [](https://npmjs.org/package/async-helpers) [](https://travis-ci.org/doowb/async-helpers) [](https://ci.appveyor.com/project/doowb/async-helpers) | ||
### [.set](index.js#L81) | ||
### [.set](index.js#L72) | ||
@@ -55,3 +55,3 @@ Add a helper to the cache. | ||
### [.get](index.js#L117) | ||
### [.get](index.js#L108) | ||
@@ -73,3 +73,3 @@ Get all helpers or a helper with the given name. | ||
### [.wrapHelper](index.js#L137) | ||
### [.wrapHelper](index.js#L128) | ||
@@ -90,3 +90,3 @@ Wrap a helper with async handling capibilities. | ||
### [.reset](index.js#L246) | ||
### [.reset](index.js#L238) | ||
@@ -103,3 +103,3 @@ Reset all the stashed helpers. | ||
### [.resolveId](index.js#L289) | ||
### [.resolveId](index.js#L297) | ||
@@ -125,3 +125,3 @@ Resolve a stashed helper by the generated id. This is a generator function and should be used with [co](https://github.com/tj/co) | ||
### [.resolveIds](index.js#L430) | ||
### [.resolveIds](index.js#L439) | ||
@@ -162,4 +162,4 @@ After rendering a string using wrapped async helpers, use `resolveIds` to invoke the original async helpers and replace the async ids with results from the async helpers. | ||
| --- | --- | | ||
| 73 | [doowb](https://github.com/doowb) | | ||
| 21 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 80 | [doowb](https://github.com/doowb) | | ||
| 31 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 1 | [nknapp](https://github.com/nknapp) | | ||
@@ -199,2 +199,2 @@ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.1, on January 25, 2017._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.1, on January 26, 2017._ |
24737
534