Skip to content

Latest commit

 

History

History
140 lines (94 loc) · 5.44 KB

.verb.md

File metadata and controls

140 lines (94 loc) · 5.44 KB

[{%= name %}][author-www-url] [![npmjs.com][npmjs-img]][npmjs-url] [![The MIT License][license-img]][license-url] [![npm downloads][downloads-img]][downloads-url]

{%= description %}

[![code climate][codeclimate-img]][codeclimate-url] standard code style [![travis build status][travis-img]][travis-url] [![coverage status][coveralls-img]][coveralls-url] [![dependency status][david-img]][david-url]

Table of Contents

Install

Install with npm

$ npm i {%= name %} --save

What is this for?

Some APIs do not use an error-first callback approach, which is convention in NodeJS land. This library converts those APIs with "result-first" callback to have "error-first" callback.

back to top

Why it exists?

Inspiration for this was [rfpify][] and especially the wanted feature issue#3 at [pify][] library. The @SamVerschueren take on that forks the original [pify][] code base and andjust the needed changes. But I'm curious why? Isn't it easier to convert simply "result-first" to "error-first" and than just pass to original pify.

So that's what this package does. :)

I hope to merge it into [rfpify][] or directly to [pify][] so we can resolve the issue#3.

back to top

How to promisify "result-first" functions

This is example how [rfpify][] can look like in future

var pify = require('pify')
module.exports = (fn, opts) => pify(toCallback(fn), opts)

then we can promisify "result-first" functions:

const rfpify = require('rfpify')
const EventEmitter3 = require('eventemitter3')
const emitter = new EventEmitter3()

// classic "result-first" case
emitter.on('foo', (a, b) => {
  console.log(a, b) // => 33, 55
})

// good idea is to `bind` the given function
const onPromisified = rfpify(emitter.on.bind(emitter))

onPromisified('foo')
  .then((res) => {
    console.log(res[0], res[1])
    // twice
    // => 33, 55
  })
  .catch(console.error) // => Error if something fails

emitter.emit('foo', 33, 55)
emitter.emit('foo', 33, 55)

back to top

Usage

For more use-cases see the tests

const {%= varname %} = require('{%= name %}')

API

{%= apidocs('index.js') %}

back to top

{% if (verb.related && verb.related.list && verb.related.list.length) { %}

Related

{%= related(verb.related.list, {words: 20}) %} {% } %}

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/{%= repository %}/issues/new).
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent [![new message to charlike][new-message-img]][new-message-url] freenode #charlike

[![{%= author.username %}.tk][author-www-img]][author-www-url] [![keybase {%= author.username %}][keybase-img]][keybase-url] [![{%= author.username %} npm][author-npm-img]][author-npm-url] [![{%= author.username %} twitter][author-twitter-img]][author-twitter-url] [![{%= author.username %} github][author-github-img]][author-github-url]

{%= reflinks(verb.reflinks) %}

[npmjs-url]: https://www.npmjs.com/package/{%= name %} [npmjs-img]: https://img.shields.io/npm/v/{%= name %}.svg?label={%= name %}

[license-url]: https://github.com/{%= repository %}/blob/master/LICENSE [license-img]: https://img.shields.io/npm/l/{%= name %}.svg

[downloads-url]: https://www.npmjs.com/package/{%= name %} [downloads-img]: https://img.shields.io/npm/dm/{%= name %}.svg

[codeclimate-url]: https://codeclimate.com/github/{%= repository %} [codeclimate-img]: https://img.shields.io/codeclimate/github/{%= repository %}.svg

[travis-url]: https://travis-ci.org/{%= repository %} [travis-img]: https://img.shields.io/travis/{%= repository %}/master.svg

[coveralls-url]: https://coveralls.io/r/{%= repository %} [coveralls-img]: https://img.shields.io/coveralls/{%= repository %}.svg

[david-url]: https://david-dm.org/{%= repository %} [david-img]: https://img.shields.io/david/{%= repository %}.svg

[author-www-url]: http://www.{%= author.username.toLowerCase() %}.tk [author-www-img]: https://img.shields.io/badge/www-{%= author.username.toLowerCase() %}.tk-fe7d37.svg

[keybase-url]: https://keybase.io/{%= author.username.toLowerCase() %} [keybase-img]: https://img.shields.io/badge/keybase-{%= author.username.toLowerCase() %}-8a7967.svg

[author-npm-url]: https://www.npmjs.com/~{%= author.username.toLowerCase() %} [author-npm-img]: https://img.shields.io/badge/npm-~{%= author.username.toLowerCase() %}-cb3837.svg

[author-twitter-url]: https://twitter.com/{%= author.username %} [author-twitter-img]: https://img.shields.io/badge/twitter-@{%= author.username %}-55acee.svg

[author-github-url]: https://github.com/{%= author.username %} [author-github-img]: https://img.shields.io/badge/github-@{%= author.username %}-4183c4.svg

[new-message-url]: https://github.com/{%= author.username %}/ama [new-message-img]: https://img.shields.io/badge/ask%20me-anything-green.svg