Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

relike-all

hybridables11MIT2.2.0

Promisify all function in an object, using [relike][].

all, async, asynchronous, callback, cb, fn, func, function, letta, promise, promises, promisify, promisify-all, relike, relike-all, sync, synchronous, then, thenify

readme

relike-all npmjs.com The MIT License npm downloads

Promisify all function in an object, using relike.

code climate standard code style travis build status coverage status dependency status

Install

npm i relike-all --save

Usage

For more use-cases see the tests

const relikeAll = require('relike-all')

relikeAll

Promisify functions in an object. You can pass pattern to filter what should be promisified and what not. Using is-match, which is thin wrapper around micromatch. You should install is-match, if you want to use filtering.

Params

  • <source> {Object|Function}: The source object to promisify.
  • [pattern] {String|Array|RegExp|Function}: A glob pattern to filter, using micromatch.
  • [options] {Object}: Options passed to micromatch.
  • returns {Object|Function}: Same as incoming source.

Example

const relikeAll = require('relike-all')
const fs = relikeAll(require('fs'))

fs.readFile('package.json', 'utf8')
  .then(JSON.parse)
  .then(data => {
    console.log(data.name) // => 'relike-all'
    return 'package.json'
  })
  .then(fs.statSync)
  .then(stats => {
    console.log(stats) // => Stats object
  }, err => {
    console.error(err.stack)
  })

.promisify

Returns a function that will wrap the given fn. Instead of taking a callback, the returned function will return a promise whose fate is decided by the callback behavior of the given fn node function. The node function should conform to node.js convention of accepting a callback as last argument and calling that callback with error as the first argument and success value on the second argument. – Bluebird Docs on .promisify

Params

  • fn {Function}: Some sync or async function to promisify.
  • [Promize] {Function}: Promise constructor to be used on enviroment where no support for native.
  • returns {Function}: Promisified function, which always return a Promise.

Example

const fs = require('fs')
const relikeAll = require('relike-all')
const readFile = relikeAll.promisify(fs.readFile)

readFile('package.json', 'utf8')
  .then(JSON.parse)
  .then(data => {
    console.log(data.name) // => 'relike-all'
  }, err => {
    console.error(err.stack)
  })

.Promise

Customizing what Promise constructor to be used in old environments where there's no support for native Promise.
See more in relike's .Promise section for more info.

Example

const fs = require('fs')
const relikeAll = require('relike-all')

// using `when` promise on node <= 0.11.12
relikeAll.promisify.Promise = require('when') 

const readFile = relikeAll.promisify(fs.readFile)
const promise = readFile('index.js')

console.log(promise.Promise) // => The `when` promise constructor, on old enviroments
console.log(promise.___customPromise) // => `true` on old environments

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

changelog

2.2.0 - 2016-05-15

  • Release v2.2.0 / npm@v2.2.0
  • breaking: .Prome to .Promise based on `relike@1.1.x` changes, see its changelog and readme
  • update deps: mainly, relike which leads to partially breaking changes here
  • update docs: better docs, use verb, related list and etc

2.1.1 - 2016-01-26

  • Release v2.1.1 / npm@v2.1.1
  • support promisify module that is function and have methods on it
    • for example simple-get module - simpleGet() and simpleGet.post()

2.1.0 - 2016-01-26

  • Release v2.1.0 / npm@v2.1.0
  • add notice to the readme
  • may breaking: make is-match devDependency, so if you want to use globs - install it first!

2.0.2 - 2016-01-26

  • Release v2.0.2 / npm@v2.0.2
  • expose relike.promisify method
  • use relike.promisify method

2.0.1 - 2016-01-26

  • Release v2.0.1 / npm@v2.0.1
  • don't call is-match if not pattern

2.0.0 - 2016-01-26

  • Release v2.0.0 / npm@v2.0.0
  • update pkg
  • docs
  • increase coverage
  • change purpose of the lib! - previous idea was moved to relike-value
    • now acts like thenify-all and hybridify-all - promisify object of functions
    • use relike-value if you want previous behaving

1.0.0 - 2016-01-15

  • Release v1.0.0 / npm@v1.0.0
  • docs and update
  • remove lazy-cache
  • implement :star:

0.0.0 - 2016-01-15

  • Initial commit