JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 41350
  • Score
    100M100P100Q163275F
  • License

Use async helpers in template engines like Handlebars and Lodash.

Package Exports

  • async-helpers

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (async-helpers) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

async-helpers NPM version Build Status

Use async helpers in template engines like Handlebars and Lodash.

Install with npm

npm i async-helpers --save

Usage

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

API

AsyncHelpers

Create a new instance of AsyncHelpers

  • returns {Object}: new AsyncHelpers instance
var asyncHelpers = new AsyncHelpers();

.set

Add a helper to the cache.

  • name {String}: Name of the helper
  • fn {Function}: Helper function
  • returns {Object}: Returns this for chaining
asyncHelpers.set('upper', function (str, done) {
  done(null, str.toUpperCase());
});

.get

Get all helpers or a helper with the given name.

  • name {String}: Optionally pass in a name of a helper to get.
  • options {Object}: Additional options to use.
  • returns {Function|Object}: Single helper function when name is provided, otherwise object of all helpers
var helpers = asyncHelpers.get();
var wrappedHelpers = helperAync.get({wrap: true});

.wrap

Wrap a helper with async handling capibilities.

  • name {String}: Optionally pass the name of the helper to wrap
  • returns {Function|Object}: Single wrapped helper function when name is provided, otherwise object of all wrapped helpers.
var wrappedHelper = asyncHelpers.wrap('upper');
var wrappedHelpers = asyncHelpers.wrap();

.reset

Reset all the stashed helpers.

  • returns {Object}: Returns this to enable chaining
asyncHelpers.reset();

.resolve

Resolve a stashed helper by the generated id.

  • key {String}: ID generated when from executing a wrapped helper.
  • done {Function}: Callback function with the results of executing the async helper.
var upper = asyncHelpers.get('upper', {wrap: true});
var id = upper('doowb');
asyncHelpers.resolve(id, function (err, result) {
  console.log(result);
  //=> DOOWB
});

Run tests

Install dev dependencies:

npm i -d && npm test

Contributing

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

Author

Brian Woodward

License

Copyright (c) 2015 Brian Woodward
Released under the MIT license


This file was generated by verb-cli on March 18, 2015.