├── .flowconfig ├── .gitignore ├── LICENSE ├── README.md ├── index.js ├── package.json └── yarn.lock /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | 3 | [include] 4 | 5 | [libs] 6 | 7 | [options] 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-present James Kyle 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # typeable-promisify 2 | 3 | - Wrap any node-style callback function with a promise. 4 | - Allows you to specify your own type annotations. 5 | - Strongly typed. 6 | 7 | ```js 8 | // @flow 9 | import promisify from 'typeable-promisify'; 10 | 11 | let writeFileAsync = (filePath: string, fileContents: string): Promise => { 12 | return promisify(cb => writeFile(filePath, fileContents, cb)); 13 | }; 14 | 15 | writeFileAsync('fileName', 'fileContents').then(() => {}); 16 | ``` 17 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | 3 | var AnyPromise = require('any-promise'); 4 | 5 | /*:: 6 | type Promisify = (( 7 | & ((mixed) => void) 8 | & ((null, T) => void) 9 | ) => mixed) => Promise; 10 | */ 11 | 12 | var promisify /*: Promisify */ = fn => new AnyPromise((resolve, reject) => { 13 | fn((err, res) => { 14 | if (err) { 15 | reject(err); 16 | } else { 17 | resolve(res); 18 | } 19 | }); 20 | }); 21 | 22 | module.exports = promisify; 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "typeable-promisify", 3 | "description": "Wrap any node-style callback function with a promise.", 4 | "version": "2.0.1", 5 | "main": "index.js", 6 | "author": "James Kyle ", 7 | "license": "MIT", 8 | "dependencies": { 9 | "any-promise": "^1.3.0" 10 | }, 11 | "devDependencies": { 12 | "flow-bin": "^0.46.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | any-promise@^1.3.0: 6 | version "1.3.0" 7 | resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f" 8 | 9 | flow-bin@^0.46.0: 10 | version "0.46.0" 11 | resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.46.0.tgz#06ad7fe19dddb1042264438064a2a32fee12b872" 12 | --------------------------------------------------------------------------------