aboutsummaryrefslogtreecommitdiff
path: root/node_modules/universalify/README.md
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2019-10-06 21:37:45 +0200
committerDimitri Staessens <dimitri@ouroboros.rocks>2019-10-06 21:37:45 +0200
commit3c51c3be85bb0d1bdb87ea0d6632f1c256912f27 (patch)
treec7ccc8279b12c4f7bdbbb4270d617e48f51722e4 /node_modules/universalify/README.md
parent412c104bebc507bea9c94fd53b5bdc4b64cbfe31 (diff)
downloadwebsite-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.tar.gz
website-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.zip
build: Add some required modules for node
Diffstat (limited to 'node_modules/universalify/README.md')
-rw-r--r--node_modules/universalify/README.md76
1 files changed, 76 insertions, 0 deletions
diff --git a/node_modules/universalify/README.md b/node_modules/universalify/README.md
new file mode 100644
index 0000000..487067b
--- /dev/null
+++ b/node_modules/universalify/README.md
@@ -0,0 +1,76 @@
+# universalify
+
+[![Travis branch](https://img.shields.io/travis/RyanZim/universalify/master.svg)](https://travis-ci.org/RyanZim/universalify)
+![Coveralls github branch](https://img.shields.io/coveralls/github/RyanZim/universalify/master.svg)
+![npm](https://img.shields.io/npm/dm/universalify.svg)
+![npm](https://img.shields.io/npm/l/universalify.svg)
+
+Make a callback- or promise-based function support both promises and callbacks.
+
+Uses the native promise implementation.
+
+## Installation
+
+```bash
+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 more than three arguments, and does not ensure that the callback is only called once.
+
+```js
+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.
+
+```js
+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