Package Exports
- native-or-another
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 (native-or-another) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
native-or-another

Always will expose native
Promise
if available, otherwiseBluebird
but only if you don't give another promise module likeq
orpromise
or what you want.
Heads up: v4 is there! See the CHANGELOG.md
Install
npm i native-or-another --save
Usage
For more use-cases see the tests
const getPromise = require('native-or-another')
nativeOrAnother
Always will expose native
Promise
if available. Otherwise given promise module or Bluebird if installed, otherwise throws with message.
[Promize]
{Function} custom promise modulereturns
{Function} native Promise or anotherthrows
{Error} possible when- no native Promise support AND
- no
Promize
implementation (constructor) were given AND - no
bluebird
were not found/installed (as devDependency is enough)
Example
const fs = require('fs')
const NativeOrBluebird = getPromise()
// => `bluebird` promise, but only if installed,
// throws otherwise
const NativeOrPromise = getPromise(require('promise'))
const NativeOrPinkie = getPromise(require('pinkie'))
const NativeOrQ = getPromise(require('q'))
const promise = new NativeOrBluebird((resolve, reject) => {
fs.readFile('package.json', 'utf-8', (err, res) => {
if (err) return reject(err)
resolve(res)
})
})
promise.then(data => {
console.log(JSON.parse(data).name)
//=> 'native-or-another'
})
Related
- always-done: Handles completion and errors of anything!
- always-promise: Promisify basically everything.
- always-thunk: Create thunk from anything, works like
thunkify
. Transforms anything (callbacks, streams, promises, observables, child processes, sync and generator functions) to thunk. - redolent: Simple promisify a callback-style function with sane defaults.
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.