universalify

WebJar for universalify

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

universalify
Last Version

Last Version

2.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

universalify
WebJar for universalify
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/RyanZim/universalify

Download universalify

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/universalify/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>universalify</artifactId>
    <version>2.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/universalify/
implementation 'org.webjars.npm:universalify:2.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/universalify/
implementation ("org.webjars.npm:universalify:2.0.0")
'org.webjars.npm:universalify:jar:2.0.0'
<dependency org="org.webjars.npm" name="universalify" rev="2.0.0">
  <artifact name="universalify" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='universalify', version='2.0.0')
)
libraryDependencies += "org.webjars.npm" % "universalify" % "2.0.0"
[org.webjars.npm/universalify "2.0.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

universalify

Travis branch Coveralls github branch npm npm

Make a callback- or promise-based function support both promises and callbacks.

Uses the native promise implementation.

Installation

npm install universalify

API

universalify.fromCallback(fn)

Takes a callback-based function to universalify, and returns the universalified function.

Function must take a callback as the last parameter that will be called with the signature (error, result). universalify does not support calling the callback with three or more arguments, and does not ensure that the callback is only called once.

function callbackFn (n, cb) {
  setTimeout(() => cb(null, n), 15)
}

const fn = universalify.fromCallback(callbackFn)

// Works with Promises:
fn('Hello World!')
.then(result => console.log(result)) // -> Hello World!
.catch(error => console.error(error))

// Works with Callbacks:
fn('Hi!', (error, result) => {
  if (error) return console.error(error)
  console.log(result)
  // -> Hi!
})

universalify.fromPromise(fn)

Takes a promise-based function to universalify, and returns the universalified function.

Function must return a valid JS promise. universalify does not ensure that a valid promise is returned.

function promiseFn (n) {
  return new Promise(resolve => {
    setTimeout(() => resolve(n), 15)
  })
}

const fn = universalify.fromPromise(promiseFn)

// Works with Promises:
fn('Hello World!')
.then(result => console.log(result)) // -> Hello World!
.catch(error => console.error(error))

// Works with Callbacks:
fn('Hi!', (error, result) => {
  if (error) return console.error(error)
  console.log(result)
  // -> Hi!
})

License

MIT

Versions

Version
2.0.0
1.0.0
0.1.2
0.1.1