Home

Awesome

async-helpers NPM version NPM monthly downloads NPM total downloads Linux Build Status Windows Build Status

Use async helpers in templates with engines that typically only handle sync helpers. Handlebars and Lodash have been tested.

Install

Install with npm:

$ npm install --save async-helpers

Install with yarn:

$ yarn add async-helpers

Usage

var asyncHelpers = require('async-helpers');

API

AsyncHelpers

Create a new instance of AsyncHelpers

Params

Example

var asyncHelpers = new AsyncHelpers();

.set

Add a helper to the cache.

Params

Example

asyncHelpers.set('upper', function(str, cb) {
  cb(null, str.toUpperCase());
});

.get

Get all helpers or a helper with the given name.

Params

Example

var helpers = asyncHelpers.get();
var wrappedHelpers = asyncHelpers.get({wrap: true});

.wrapHelper

Wrap a helper with async handling capibilities.

Params

Example

var wrappedHelper = asyncHelpers.wrap('upper');
var wrappedHelpers = asyncHelpers.wrap();

.reset

Reset all the stashed helpers.

Example

asyncHelpers.reset();

.resolveId

Resolve a stashed helper by the generated id. This is a generator function and should be used with co

Params

Example

var upper = asyncHelpers.get('upper', {wrap: true});
var id = upper('doowb');

co(asyncHelpers.resolveId(id))
  .then(console.log)
  .catch(console.error);

//=> DOOWB

.resolveIds

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.

Params

Example

asyncHelpers.resolveIds(renderedString, function(err, content) {
  if (err) return console.error(err);
  console.log(content);
});

About

Related projects

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Contributors

CommitsContributor
85doowb
44jonschlinkert
1nknapp

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

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:

$ npm install && npm test

Author

Brian Woodward

License

Copyright © 2017, Brian Woodward. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on December 13, 2017.