From 7c1605eccf11ba575753cc7a5e06bf8baacf79b8 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Thu, 6 Jul 2017 15:00:13 +0200 Subject: [PATCH] update README and add docs --- README.md | 5 ---- docs/index.md | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 docs/index.md diff --git a/README.md b/README.md index 192ddd1..4466251 100644 --- a/README.md +++ b/README.md @@ -74,11 +74,6 @@ myPromisedFunction('helloThere', 2).then(x => { ``` -## Dependency Credits: -who | made what --- | -- -[notenoughneon](https://www.npmjs.com/~notenoughneon) | [typed-promisify](https://www.npmjs.com/package/typed-promisify) - For further information read the linked docs at the top of this README. > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..4466251 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,81 @@ +# smartq +dropin replacement for q + +## Availabililty +[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartq) +[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartq) +[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartq) +[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartq/) + +## Status for master +[![build status](https://GitLab.com/pushrocks/smartq/badges/master/build.svg)](https://GitLab.com/pushrocks/smartq/commits/master) +[![coverage report](https://GitLab.com/pushrocks/smartq/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartq/commits/master) +[![npm downloads per month](https://img.shields.io/npm/dm/smartq.svg)](https://www.npmjs.com/package/smartq) +[![Dependency Status](https://david-dm.org/pushrocks/smartq.svg)](https://david-dm.org/pushrocks/smartq) +[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartq/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartq/master/dependencies/npm) +[![bitHound Code](https://www.bithound.io/github/pushrocks/smartq/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartq) +[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/) +[![node](https://img.shields.io/badge/node->=%208.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/) +[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) + +## Usage +Use TypeScript for best in class instellisense. + +> Note: smartq uses native ES6 promises +> smartq does not repeat any native functions, so for things like .all() simply use Promise.all() + +```javascript +import * as q from 'smartq' + +// Deferred +// ----------------------------------------------- +let myAsyncFunction = (): Promise => { + let done = q.defer() // returns your typical Deferred object + setTimeout(() => { + done.resolve('hi') // will throw type error for other types than string as argument ;) + },6000) + return done.promise +} + +let myAsyncFunction2 = async () => { + let aString = await myAsyncFunction() + console.log(aString) // will log 'hi' to console +} + +myAsyncFunction2(); + + +// Resolved and Rejected promises +// ------------------------------------------------ +q.resolvedPromise(`I'll get logged to console soon`) + .then(x => { + console.log(x) + }) + +q.rejectedPromise(`what a lovely error message`) + .then(() => { + console.log('This never makes it to console') + }/*, alternatively put a reject function here */) + .catch(err => { + console.log(err) + }) + +// Promisify (typed) +// ------------------------------------------------ + +let myCallbackedFunction = (someString: string, someNumber: number, cb) => { + cb(null, someString) +} + +let myPromisedFunction = q.promisify(myCallbackFunction) +myPromisedFunction('helloThere', 2).then(x => { + console.log(x) // will log 'helloThere' to console +}) + +``` + +For further information read the linked docs at the top of this README. + +> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) + +[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)