Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-helpers

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-helpers

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

  • 0.3.12
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
29K
decreased by-13.65%
Maintainers
2
Weekly downloads
 
Created
Source

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

Usage

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

API

AsyncHelpers

Create a new instance of AsyncHelpers

Params

  • options {Object}: options to pass to instance
  • returns {Object}: new AsyncHelpers instance

Example

var asyncHelpers = new AsyncHelpers();

.set

Add a helper to the cache.

Params

  • name {String}: Name of the helper
  • fn {Function}: Helper function
  • returns {Object}: Returns this for chaining

Example

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

.get

Get all helpers or a helper with the given name.

Params

  • 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

Example

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

.wrapHelper

Wrap a helper with async handling capibilities.

Params

  • helper {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.

Example

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

.reset

Reset all the stashed helpers.

  • returns {Object}: Returns this to enable chaining

Example

asyncHelpers.reset();

.resolveId

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

Params

  • key {String}: ID generated when from executing a wrapped helper.

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

  • str {String}: String containing async ids
  • cb {Function}: Callback function accepting an err and content parameters.

Example

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

About

  • assemble: Get the rocks out of your socks! Assemble makes you fast at creating web projects… more | homepage
  • co: generator async control flow goodness | homepage
  • generate: Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the… more | homepage
  • templates: System for creating and managing template collections, and rendering templates with any node.js template engine… more | homepage
  • verb: Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… more | homepage

Contributing

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

Contributors

CommitsContributor
80doowb
31jonschlinkert
1nknapp

Building docs

(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)

To generate the readme and API documentation with verb:

$ npm install -g verb verb-generate-readme && verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Brian Woodward

License

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


This file was generated by verb-generate-readme, v0.4.1, on January 26, 2017.

Keywords

FAQs

Package last updated on 26 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc