UNPKG

@promises/to-callback

Version:

To Callback is package from Promises library

125 lines (98 loc) 2.81 kB
# @promises/to-callback [![Source Code](https://img.shields.io/badge/%3C%2F%3E-source_code-blue.svg)](https://github.com/yisraelx/promises/blob/master/modules/to-callback) [![Version](https://img.shields.io/npm/v/@promises/to-callback.svg)](https://www.npmjs.com/package/@promises/to-callback) [![MIT License](https://img.shields.io/npm/l/@promises/to-callback.svg)](https://github.com/yisraelx/promises/blob/master/LICENSE) [![Bundle Size](https://img.shields.io/bundlephobia/min/@promises/to-callback.svg)](https://bundlephobia.com/result?p=@promises/to-callback) **To Callback is package from Promises library** ## Use **Module** ```sh $ npm install --save @promises/to-callback ``` ```typescript import { default as toCallback } from '@promises/to-callback'; ``` **Browser** ```html <script src="https://unpkg.com/@promises/to-callback/bundle.umd.min.js"></script> ``` ```typescript let { toCallback } = P; ``` **Examples** ```typescript let promise: Promise<string> = Promise.resolve<string>('foo'); toCallback(promise, (error: any, result: string) => { console.log(error); // error => null console.log(result); // result => 'foo' }); ``` ### Functional programming **Module** ```sh $ npm install --save @promises/to-callback ``` ```typescript import { __, default as toCallback } from '@promises/to-callback/fp'; ``` **Browser** ```html <script src="https://unpkg.com/@promises/to-callback/fp/bundle.umd.min.js"></script> ``` ```typescript let { __, toCallback } = PF; ``` **Examples** ```typescript let promise: Promise<string> = Promise.resolve<string>('foo'); toCallback((error: any, result: string) => { console.log(error); // error => null console.log(result); // result => 'foo' })(promise); ``` ### Wrapper **Module** ```sh $ npm install --save @promises/to-callback ``` ```typescript import Promises from '@promises/core'; import '@promises/to-callback/add'; ``` *Or* ```typescript import Promises from '@promises/to-callback/add'; ``` **Browser** ```html <script src="https://unpkg.com/@promises/core/bundle.umd.min.js"></script> <script src="https://unpkg.com/@promises/to-callback/add/bundle.umd.min.js"></script> ``` ```typescript let { Promises } = P; ``` **Examples** ```typescript let promises: Promises<string> = Promises.resolve<string>('foo'); promises.toCallback((error: any, result: string) => { console.log(error); // error => null console.log(result); // result => 'foo' }); ``` ## Compatibility These modules are written in typescript and available in ES5 and ES6 standard, the requirements are a global __Promise__ (native or polyfill). ## License Copyright © 2017 [Yisrael Eliav](https://github.com/yisraelx), Licensed under the [MIT license](https://github.com/yisraelx/promises/blob/master/LICENSE).