async-helpers
Advanced tools
Comparing version 0.3.14 to 0.3.15
92
index.js
/*! | ||
* async-helpers <https://github.com/doowb/async-helpers> | ||
* | ||
* Copyright (c) 2015, Brian Woodward. | ||
* Licensed under the MIT License. | ||
* Copyright (c) 2015-2017, Brian Woodward. | ||
* Released under the MIT License. | ||
*/ | ||
@@ -11,5 +11,3 @@ | ||
var typeOf = require('kind-of'); | ||
var stringify = require('safe-json-stringify'); | ||
var define = require('define-property'); | ||
var extend = require('extend-shallow'); | ||
var co = require('co'); | ||
@@ -40,3 +38,3 @@ | ||
} | ||
this.options = extend({}, options); | ||
this.options = Object.assign({}, options); | ||
this.prefix = this.options.prefix || '{$ASYNCID$'; | ||
@@ -76,6 +74,6 @@ this.globalCounter = AsyncHelpers.globalCounter++; | ||
if (isObject(name)) { | ||
for (var key in name) { | ||
if (name.hasOwnProperty(key)) { | ||
this.set(key, name[key]); | ||
} | ||
var keys = Object.keys(name); | ||
for (var i = 0; i < keys.length; i++) { | ||
var key = keys[i]; | ||
this.set(key, name[key]); | ||
} | ||
@@ -113,3 +111,3 @@ return this; | ||
if (typeof helper === 'string') { | ||
return this.wrapHelper(helper, options); | ||
return this.wrapHelper.apply(this, arguments); | ||
} | ||
@@ -151,7 +149,5 @@ return this.wrapHelpers(this.helpers, helper); | ||
} | ||
if (options.wrap && helper.wrapped !== true) { | ||
return this.wrapper(helper.name || helper.displayName, helper, this); | ||
} | ||
return helper; | ||
@@ -176,16 +172,16 @@ default: { | ||
var res = {}; | ||
for (var key in helpers) { | ||
if (helpers.hasOwnProperty(key)) { | ||
var helper = helpers[key]; | ||
if (isObject(helper)) { | ||
res[key] = this.wrapHelpers(helper, options); | ||
var keys = Object.keys(helpers); | ||
for (var i = 0; i < keys.length; i++) { | ||
var key = keys[i]; | ||
var helper = helpers[key]; | ||
if (isObject(helper)) { | ||
res[key] = this.wrapHelpers(helper, options); | ||
} else { | ||
if (helper.wrapped !== true) { | ||
if (typeOf(helper) === 'function' && !helper.name && !helper.displayName) { | ||
helper.displayName = key; | ||
} | ||
res[key] = this.wrapHelper(helper, options); | ||
} else { | ||
if (helper.wrapped !== true) { | ||
if (typeOf(helper) === 'function' && !helper.name && !helper.displayName) { | ||
helper.displayName = key; | ||
} | ||
res[key] = this.wrapHelper(helper, options); | ||
} else { | ||
res[key] = helper; | ||
} | ||
res[key] = helper; | ||
} | ||
@@ -259,13 +255,3 @@ } | ||
} | ||
var matches = []; | ||
var match; | ||
var input = str; | ||
while ((match = this.prefixRegex.exec(input))) { | ||
matches.push(match[0]); | ||
input = input.slice(match.index + match[0].length); | ||
} | ||
return matches; | ||
return str.match(this.prefixRegex); | ||
}; | ||
@@ -455,4 +441,4 @@ | ||
var matches = this.matches(str); | ||
var self = this; | ||
var self = this; | ||
co(function * () { | ||
@@ -470,5 +456,3 @@ if (!matches) { | ||
}) | ||
.then(function(res) { | ||
cb(null, res); | ||
}) | ||
.then((res) => cb(null, res)) | ||
.catch(cb); | ||
@@ -488,17 +472,4 @@ }; | ||
function formatError(err, helper, args) { | ||
args = args.filter(function(arg) { | ||
if (!arg || typeof arg === 'function') { | ||
return false; | ||
} | ||
return true; | ||
}).map(function(arg) { | ||
return stringify(arg); | ||
}); | ||
err.reason = '"' + helper.name | ||
+ '" helper cannot resolve: `' | ||
+ args.join(', ') + '`'; | ||
err.helper = helper; | ||
err.args = args; | ||
define(err, 'args', args); | ||
return err; | ||
@@ -542,3 +513,3 @@ } | ||
} | ||
var regex = new RegExp(createRegexString(key)); | ||
var regex = new RegExp(createRegexString(key), 'g'); | ||
cache[key] = regex; | ||
@@ -574,6 +545,9 @@ return regex; | ||
if (typeof helpers === 'function' || isObject(helpers)) { | ||
var keys = Object.keys(helpers).filter(function(name) { | ||
return ['async', 'sync', 'displayName'].indexOf(name) === -1; | ||
}); | ||
return keys.length > 1; | ||
var keys = Object.keys(helpers); | ||
for (var i = 0; i < keys.length; i++) { | ||
var name = keys[i]; | ||
if (name !== 'async' && name !== 'sync' && name !== 'displayName') { | ||
return true; | ||
} | ||
} | ||
} | ||
@@ -580,0 +554,0 @@ return false; |
{ | ||
"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.14", | ||
"version": "0.3.15", | ||
"homepage": "https://github.com/doowb/async-helpers", | ||
"author": "Brian Woodward (https://github.com/doowb)", | ||
"contributors": [ | ||
"Brian Woodward (https://twitter.com/doowb)", | ||
"Jon Schlinkert (http://twitter.com/jonschlinkert)", | ||
"Nils Knappmeier (https://blog.knappi.org)" | ||
], | ||
"repository": "doowb/async-helpers", | ||
@@ -13,4 +18,3 @@ "bugs": { | ||
"files": [ | ||
"index.js", | ||
"utils.js" | ||
"index.js" | ||
], | ||
@@ -26,17 +30,15 @@ "main": "index.js", | ||
"co": "^4.6.0", | ||
"define-property": "^0.2.5", | ||
"extend-shallow": "^2.0.1", | ||
"kind-of": "^3.1.0", | ||
"safe-json-stringify": "^1.0.3" | ||
"define-property": "^1.0.0", | ||
"kind-of": "^6.0.0" | ||
}, | ||
"devDependencies": { | ||
"async": "^1.5.2", | ||
"async": "^2.5.0", | ||
"gulp": "^3.9.1", | ||
"gulp-eslint": "^3.0.1", | ||
"gulp-format-md": "^0.1.7", | ||
"gulp-istanbul": "^1.1.1", | ||
"gulp-eslint": "^4.0.0", | ||
"gulp-format-md": "^1.0.0", | ||
"gulp-istanbul": "^1.1.2", | ||
"gulp-mocha": "^3.0.1", | ||
"handlebars": "^4.0.5", | ||
"lodash": "^4.6.1", | ||
"mocha": "^3.2.0" | ||
"handlebars": "^4.0.11", | ||
"lodash": "^4.17.4", | ||
"mocha": "^3.5.2" | ||
}, | ||
@@ -65,5 +67,5 @@ "keywords": [ | ||
"assemble", | ||
"co", | ||
"generate", | ||
"templates", | ||
"update", | ||
"verb" | ||
@@ -70,0 +72,0 @@ ] |
@@ -1,5 +0,7 @@ | ||
# async-helpers [![NPM version](https://img.shields.io/npm/v/async-helpers.svg?style=flat)](https://www.npmjs.com/package/async-helpers) [![NPM monthly downloads](https://img.shields.io/npm/dm/async-helpers.svg?style=flat)](https://npmjs.org/package/async-helpers) [![NPM total downloads](https://img.shields.io/npm/dt/async-helpers.svg?style=flat)](https://npmjs.org/package/async-helpers) [![Linux Build Status](https://img.shields.io/travis/doowb/async-helpers.svg?style=flat&label=Travis)](https://travis-ci.org/doowb/async-helpers) [![Windows Build Status](https://img.shields.io/appveyor/ci/doowb/async-helpers.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/doowb/async-helpers) | ||
# async-helpers [![NPM version](https://img.shields.io/npm/v/async-helpers.svg?style=flat)](https://www.npmjs.com/package/async-helpers) [![NPM monthly downloads](https://img.shields.io/npm/dm/async-helpers.svg?style=flat)](https://npmjs.org/package/async-helpers) [![NPM total downloads](https://img.shields.io/npm/dt/async-helpers.svg?style=flat)](https://npmjs.org/package/async-helpers) [![Linux Build Status](https://img.shields.io/travis/doowb/async-helpers.svg?style=flat&label=Travis)](https://travis-ci.org/doowb/async-helpers) [![Windows Build Status](https://img.shields.io/appveyor/ci/doowb/async-helpers.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/doowb/async-helpers) | ||
> Use async helpers in templates with engines that typically only handle sync helpers. Handlebars and Lodash have been tested. | ||
Please consider following this project's author, [Brian Woodward](https://github.com/doowb), and consider starring the project to show your :heart: and support. | ||
## Install | ||
@@ -21,3 +23,3 @@ | ||
### [AsyncHelpers](index.js#L35) | ||
### [AsyncHelpers](index.js#L34) | ||
@@ -37,3 +39,3 @@ Create a new instance of AsyncHelpers | ||
### [.set](index.js#L72) | ||
### [.set](index.js#L71) | ||
@@ -56,3 +58,3 @@ Add a helper to the cache. | ||
### [.get](index.js#L108) | ||
### [.get](index.js#L107) | ||
@@ -74,3 +76,3 @@ Get all helpers or a helper with the given name. | ||
### [.wrapHelper](index.js#L128) | ||
### [.wrapHelper](index.js#L127) | ||
@@ -91,3 +93,3 @@ Wrap a helper with async handling capibilities. | ||
### [.reset](index.js#L238) | ||
### [.reset](index.js#L235) | ||
@@ -104,3 +106,3 @@ Reset all the stashed helpers. | ||
### [.resolveId](index.js#L297) | ||
### [.resolveId](index.js#L284) | ||
@@ -126,3 +128,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#L439) | ||
### [.resolveIds](index.js#L426) | ||
@@ -147,24 +149,23 @@ 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. | ||
### Related projects | ||
<details> | ||
<summary><strong>Contributing</strong></summary> | ||
* [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble "Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit") | ||
* [co](https://www.npmjs.com/package/co): generator async control flow goodness | [homepage](https://github.com/tj/co#readme "generator async control flow goodness") | ||
* [generate](https://www.npmjs.com/package/generate): Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the… [more](https://github.com/generate/generate) | [homepage](https://github.com/generate/generate "Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the robustness and configurability of Yeoman, the expressiveness and simplicity of Slush, and more powerful flow control and composability than either.") | ||
* [templates](https://www.npmjs.com/package/templates): System for creating and managing template collections, and rendering templates with any node.js template engine… [more](https://github.com/jonschlinkert/templates) | [homepage](https://github.com/jonschlinkert/templates "System for creating and managing template collections, and rendering templates with any node.js template engine. Can be used as the basis for creating a static site generator or blog framework.") | ||
* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb "Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.") | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). | ||
### Contributing | ||
</details> | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). | ||
<details> | ||
<summary><strong>Running Tests</strong></summary> | ||
### Contributors | ||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: | ||
| **Commits** | **Contributor** | | ||
| --- | --- | | ||
| 85 | [doowb](https://github.com/doowb) | | ||
| 31 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 1 | [nknapp](https://github.com/nknapp) | | ||
```sh | ||
$ npm install && npm test | ||
``` | ||
### Building docs | ||
</details> | ||
<details> | ||
<summary><strong>Building docs</strong></summary> | ||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ | ||
@@ -178,10 +179,22 @@ | ||
### Running tests | ||
</details> | ||
Install dev dependencies: | ||
### Related projects | ||
```sh | ||
$ npm install && npm test | ||
``` | ||
You might also be interested in these projects: | ||
* [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble "Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit") | ||
* [generate](https://www.npmjs.com/package/generate): Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the… [more](https://github.com/generate/generate) | [homepage](https://github.com/generate/generate "Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the robustness and configurability of Yeoman, the expressiveness and simplicity of Slush, and more powerful flow control and composability than either.") | ||
* [templates](https://www.npmjs.com/package/templates): System for creating and managing template collections, and rendering templates with any node.js template engine… [more](https://github.com/jonschlinkert/templates) | [homepage](https://github.com/jonschlinkert/templates "System for creating and managing template collections, and rendering templates with any node.js template engine. Can be used as the basis for creating a static site generator or blog framework.") | ||
* [update](https://www.npmjs.com/package/update): Be scalable! Update is a new, open source developer framework and CLI for automating updates… [more](https://github.com/update/update) | [homepage](https://github.com/update/update "Be scalable! Update is a new, open source developer framework and CLI for automating updates of any kind in code projects.") | ||
* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb "Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.") | ||
### Contributors | ||
| **Commits** | **Contributor** | | ||
| --- | --- | | ||
| 85 | [doowb](https://github.com/doowb) | | ||
| 34 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 1 | [nknapp](https://github.com/nknapp) | | ||
### Author | ||
@@ -197,6 +210,6 @@ | ||
Copyright © 2017, [Brian Woodward](https://github.com/doowb). | ||
MIT | ||
Released under the [MIT License](LICENSE). | ||
*** | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.1, on January 27, 2017._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on November 05, 2017._ |
Sorry, the diff of this file is not supported yet
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
23802
3
205
483
+ Addeddefine-property@1.0.0(transitive)
+ Addedis-descriptor@1.0.3(transitive)
+ Addedkind-of@6.0.3(transitive)
- Removedextend-shallow@^2.0.1
- Removedsafe-json-stringify@^1.0.3
- Removeddefine-property@0.2.5(transitive)
- Removedextend-shallow@2.0.1(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-descriptor@0.1.7(transitive)
- Removedis-extendable@0.1.1(transitive)
- Removedkind-of@3.2.2(transitive)
- Removedsafe-json-stringify@1.2.0(transitive)
Updateddefine-property@^1.0.0
Updatedkind-of@^6.0.0