{"name":"relike","version":"1.0.3","description":"Simple promisify a callback-style function with sane defaults. Support promisify-ing sync functions.","repository":{"type":"git","url":"git+https://github.com/hybridables/relike.git"},"author":{"name":"Charlike Mike Reagent","email":"@tunnckoCore","url":"http://www.tunnckocore.tk"},"main":"index.js","license":"MIT","scripts":{"test":"standard && node test.js"},"dependencies":{"handle-arguments":"^3.0.4","is-async-function":"^1.1.0","lazy-cache":"^1.0.3","native-or-another":"^3.0.1","sliced":"^1.0.1"},"devDependencies":{"assertit":"^0.1.0","is-buffer":"^1.1.0","isarray":"1.0.0","pinkie":"^2.0.1","semver":"^5.0.3"},"files":["index.js","utils.js"],"keywords":["anything","bluebird","callback","defaults","everywhere","native","native-promise","promise","promisify","simple"],"gitHead":"56ebb4aecc0b46b8db04efc70673b46643a69b26","bugs":{"url":"https://github.com/hybridables/relike/issues"},"homepage":"https://github.com/hybridables/relike#readme","_id":"relike@1.0.3","_shasum":"61f425387cd582fc7ab945f50817c45fe4785003","_from":".","_npmVersion":"3.5.3","_nodeVersion":"5.5.0","_npmUser":{"name":"tunnckocore","email":"mameto_100@mail.bg"},"dist":{"shasum":"61f425387cd582fc7ab945f50817c45fe4785003","tarball":"http://registry-npm.ywwl.com/relike/download/relike-1.0.3.tgz","integrity":"sha512-0tbQz1qF5vx54+vsB4yQEwEZfm7wN3zLAqi1rhkARJuRcwGWhThXgAS/l/5SCEIu8G2/sSlruvo2qQ0Un/cVDA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDlnUp5HfNYssLt9u5knhb1wYvRb/PRle4zQzdTtMom5QIgYtEih4jLVbOZPDDjs/ZnH9COBn7YhQO2HZqMLQoPqAM="}],"size":5140,"noattachment":false,"key":"/relike/-/relike-1.0.3.tgz"},"maintainers":[{"name":"tunnckocore","email":"mameto_100@mail.bg"}],"directories":{},"readme":"# [relike][author-www-url] [![npmjs.com][npmjs-img]][npmjs-url] [![The MIT License][license-img]][license-url] [![npm downloads][downloads-img]][downloads-url] \n\n> Simple promisify async or sync function with sane defaults. Lower level than `promisify` thing. Can be used to create `promisify` method.\n\n[![code climate][codeclimate-img]][codeclimate-url] [![standard code style][standard-img]][standard-url] [![travis build status][travis-img]][travis-url] [![coverage status][coveralls-img]][coveralls-url] [![dependency status][david-img]][david-url]\n\nYou might also be interested in [hybridify][], [hybridify-all][], [relike-all][], [letta][]\n\n## Install\n```\nnpm i relike --save\n```\n\n## Usage\n> For more use-cases see the [tests](./test.js)\n\n```js\nconst relike = require('relike')\n```\n\n**Note:** It treat functions as asynchronous, based on [is-async-function][].  \n\nWhy you should be aware of that? Because if you give async function which don't have last argument called with some of the [common-callback-names][] it will treat that function as synchronous and things may not work as expected.\n\nIt's not a problem for most of the cases and for node's native packages, because that's a convention.\nSo, the [relike-all][] package successfuly can promisifies all of the `fs` functions for example, except `fs.createReadStream` and `fs.createWriteStream` which is normal.\n\n### [relike](index.js#L42)\n> Runs `fn` in native Promise if available, or another provided in `relike.Promise`. If not given and not support for native Promise, it will use [bluebird][] promise, but only on that enviroments that don't have support.\n\n**Params**\n\n* `<fn>` **{Function}**: Some async or synchronous function.    \n* `[...args]` **{Mixed}**: Any number of any type of arguments, they are passed to `fn`.    \n* `returns` **{Promise}**: Always native Promise if supported on enviroment.  \n\n**Example**\n\n```js\nconst fs = require('fs')\nconst request = require('request')\nconst relike = require('relike')\n\nrelike(fs.readFile, 'package.json', 'utf-8').then(data => {\n  console.log(JSON.parse(data).name) // => 'relike'\n})\n\n// handles multiple arguments by default (comes from `request`)\nrelike(request, 'http://www.tunnckocore.tk/').then(result => {\n  const [httpResponse, body] = result\n})\n```\n\n### [.promisify](index.js#L110)\n> Thin wrapper function around `relike()`. It **accepts a function** and **returns a function**, which when is invoked returns a `Promise`. Just like any other `.promisify` method, for example `Bluebird.promisify`.\n\n**Params**\n\n* `fn` **{Function}**: Some sync or async function to promisify.    \n* `[Promize]` **{Function}**: Promise constructor to be used on enviroment where no support for native.    \n* `returns` **{Function}**: Promisified function, which always return a Promise.  \n\n**Example**\n\n```js\nvar fs = require('fs')\nvar relike = require('relike')\nvar readFile = relike.promisify(fs.readFile)\n\nreadFile('package.json', 'utf8')\n  .then(JSON.parse)\n  .then(data => {\n    console.log(data.name) // => 'relike'\n  })\n\n// also can promisify sync function\nvar statFile = relike.promisify(fs.statSync)\nstatFile('package.json')\n  .then(function (stats) {\n    console.log(stats.mtime)\n  })\n```\n\n### .Promise\n\nWhile `relike` always trying to use native Promise if available in the enviroment, you can\ngive a Promise constructor to be used on enviroment where there's no support - for example, old\nbroswers or node's 0.10 version. By default, `relike` will use and include [bluebird][] on old enviroments,\nas it is the fastest implementation of Promises. So, you are able to give Promise constructor, but\nit won't be used in modern enviroments - it always will use native Promise, you can't trick that. You\ncan't give custom promise implementation to be used in any enviroment.\n\n**Example**\n\n```js\nvar fs = require('fs')\nvar relike = require('relike')\n\nrelike.promisify.Promise = require('q') // using `Q` promise on node 0.10\nvar readFile = relike.promisify(fs.readFile)\n\nreadFile('package.json', 'utf8')\n  .then(console.log, console.error)\n```\n\nOne way to pass a custom Promise constructor is as shown above. But the other way is passing it to `.Promise` of the promisified function, like that\n\n```js\nvar fs = require('fs')\nvar relike = require('relike')\nvar statFile = relike.promisify(fs.stat)\n\nstatFile.Promise = require('when') // using `when` promise on node 0.10\nstatFile('package.json').then(console.log, console.error)\n```\n\nOne more thing, is that you can access the used Promise and can detect what promise is used. It is easy, just as `promise.Promise` and you'll get it.\nOr look for `promise.___bluebirdPromise` and `promise.___customPromise` properties. `.___bluebirdPromise` (yea, with three underscores in front) will be true if enviroment is old and you didn't provide promise constructor to `.Promise`.  \nSo, when you give constructor `.__customPromise` will be true and `.___bluebirdPromise` will be false.\n\n```js\nvar fs = require('fs')\nvar relike = require('relike')\n\nvar promise = relike(fs.readFile, 'package.json', 'utf8')\npromise.then(JSON.parse).then(function (val) {\n  console.log(val.name) // => 'relike'\n}, console.error)\n\nconsole.log(promise.Promise) // => used Promise constructor\nconsole.log(promise.___bluebirdPromise) // => `true` on old env, falsey otherwise\nconsole.log(promise.___customPromise) // => `true` when pass `.Promise`, falsey otherwise\n```\n\nOr finally, you can pass Promise constructor as second argument to `.promisify` method. Like that\n\n```js\nconst fs = require('fs')\nconst relike = require('relike')\nconst readFile = relike.promisify(fs.readFile, require('when'))\n\nconst promise = readFile('index.js')\n\nconsole.log(promise.Promise) // => The `when` promise constructor, on old enviroments\nconsole.log(promise.___customPromise) // => `true` on old environments\n```\n\n## Related\n* [callback2stream](https://www.npmjs.com/package/callback2stream): Transform sync, async or generator function to Stream. Correctly handle errors. [homepage](https://github.com/hybridables/callback2stream)\n* [hybridify](https://www.npmjs.com/package/hybridify): Create sync or async function to support both promise and callback-style APIs… [more](https://www.npmjs.com/package/hybridify) | [homepage](https://github.com/hybridables/hybridify)\n* [letta](https://www.npmjs.com/package/letta): Promisify sync, async or generator function, using [relike][]. Kind of promisify, but… [more](https://www.npmjs.com/package/letta) | [homepage](https://github.com/hybridables/letta)\n* [limon](https://www.npmjs.com/package/limon): The pluggable JavaScript lexer. Limon = Lemon. | [homepage](https://github.com/limonjs/limon)\n* [promise2stream](https://www.npmjs.com/package/promise2stream): Transform ES2015 Promise to Stream - specifically, Transform Stream using… [more](https://www.npmjs.com/package/promise2stream) | [homepage](https://github.com/hybridables/promise2stream)\n* [relike-all](https://www.npmjs.com/package/relike-all): Promisify all functions in an object, using `relike`. | [homepage](https://github.com/hybridables/relike-all)\n* [use-ware](https://www.npmjs.com/package/use-ware): Adds sync plugin support to your application. Kinda fork of [use][] -… [more](https://www.npmjs.com/package/use-ware) | [homepage](https://github.com/tunnckocore/use-ware)\n* [use](https://www.npmjs.com/package/use): Easily add plugin support to your node.js application. | [homepage](https://github.com/jonschlinkert/use)\n* [value2stream](https://www.npmjs.com/package/value2stream): Transform any value to stream. Create a stream from any value -… [more](https://www.npmjs.com/package/value2stream) | [homepage](https://github.com/hybridables/value2stream)\n\n## Contributing\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/hybridables/relike/issues/new).  \nBut before doing anything, please read the [CONTRIBUTING.md](./CONTRIBUTING.md) guidelines.\n\n## [Charlike Make Reagent](http://j.mp/1stW47C) [![new message to charlike][new-message-img]][new-message-url] [![freenode #charlike][freenode-img]][freenode-url]\n\n[![tunnckoCore.tk][author-www-img]][author-www-url] [![keybase tunnckoCore][keybase-img]][keybase-url] [![tunnckoCore npm][author-npm-img]][author-npm-url] [![tunnckoCore twitter][author-twitter-img]][author-twitter-url] [![tunnckoCore github][author-github-img]][author-github-url]\n\n[hybridify]: https://github.com/hybridables/hybridify\n[hybridify-all]: https://github.com/hybridables/hybridify-all\n[bluebird]: https://github.com/petkaantonov/bluebird\n[common-callback-names]: https://github.com/tunnckocore/common-callback-names\n[is-async-function]: https://github.com/tunnckocore/is-async-function\n[letta]: https://github.com/hybridables/letta\n[relike]: https://github.com/hybridables/relike\n[relike-all]: https://github.com/hybridables/relike-all\n[through2]: https://github.com/rvagg/through2\n[use]: https://github.com/jonschlinkert/use\n\n[npmjs-url]: https://www.npmjs.com/package/relike\n[npmjs-img]: https://img.shields.io/npm/v/relike.svg?label=relike\n\n[license-url]: https://github.com/hybridables/relike/blob/master/LICENSE\n[license-img]: https://img.shields.io/npm/l/relike.svg\n\n[downloads-url]: https://www.npmjs.com/package/relike\n[downloads-img]: https://img.shields.io/npm/dm/relike.svg\n\n[codeclimate-url]: https://codeclimate.com/github/hybridables/relike\n[codeclimate-img]: https://img.shields.io/codeclimate/github/hybridables/relike.svg\n\n[travis-url]: https://travis-ci.org/hybridables/relike\n[travis-img]: https://img.shields.io/travis/hybridables/relike/master.svg\n\n[coveralls-url]: https://coveralls.io/r/hybridables/relike\n[coveralls-img]: https://img.shields.io/coveralls/hybridables/relike.svg\n\n[david-url]: https://david-dm.org/hybridables/relike\n[david-img]: https://img.shields.io/david/hybridables/relike.svg\n\n[standard-url]: https://github.com/feross/standard\n[standard-img]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg\n\n[author-www-url]: http://www.tunnckocore.tk\n[author-www-img]: https://img.shields.io/badge/www-tunnckocore.tk-fe7d37.svg\n\n[keybase-url]: https://keybase.io/tunnckocore\n[keybase-img]: https://img.shields.io/badge/keybase-tunnckocore-8a7967.svg\n\n[author-npm-url]: https://www.npmjs.com/~tunnckocore\n[author-npm-img]: https://img.shields.io/badge/npm-~tunnckocore-cb3837.svg\n\n[author-twitter-url]: https://twitter.com/tunnckoCore\n[author-twitter-img]: https://img.shields.io/badge/twitter-@tunnckoCore-55acee.svg\n\n[author-github-url]: https://github.com/tunnckoCore\n[author-github-img]: https://img.shields.io/badge/github-@tunnckoCore-4183c4.svg\n\n[freenode-url]: http://webchat.freenode.net/?channels=charlike\n[freenode-img]: https://img.shields.io/badge/freenode-%23charlike-5654a4.svg\n\n[new-message-url]: https://github.com/tunnckoCore/ama\n[new-message-img]: https://img.shields.io/badge/ask%20me-anything-green.svg","publish_time":1453781451830,"_cnpm_publish_time":1453781451830,"dist-tags":{"latest":"1.1.5"}}