\begin{quote}
Promisify a callback-\/style function \end{quote}
\hypertarget{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22849}{}\doxysection{Install}\label{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22849}

\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install -\/-\/save pify }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22850}{}\doxysection{Usage}\label{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22850}

\begin{DoxyCode}{0}
\DoxyCodeLine{const fs = require('fs');}
\DoxyCodeLine{const pify = require('pify');}
\DoxyCodeLine{}
\DoxyCodeLine{// promisify a single function}
\DoxyCodeLine{}
\DoxyCodeLine{pify(fs.readFile)('package.json', 'utf8').then(data => \{}
\DoxyCodeLine{    console.log(JSON.parse(data).name);}
\DoxyCodeLine{    //=> 'pify'}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{// or promisify all methods in a module}
\DoxyCodeLine{}
\DoxyCodeLine{pify(fs).readFile('package.json', 'utf8').then(data => \{}
\DoxyCodeLine{    console.log(JSON.parse(data).name);}
\DoxyCodeLine{    //=> 'pify'}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22851}{}\doxysection{API}\label{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22851}
\hypertarget{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22852}{}\doxysubsection{pify(input, \mbox{[}promise\+Module\mbox{]}, \mbox{[}options\mbox{]})}\label{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22852}
Returns a promise wrapped version of the supplied function or module.\hypertarget{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22853}{}\doxysubsubsection{input}\label{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22853}
Type\+: {\ttfamily function}, {\ttfamily object}

Callback-\/style function or module whose methods you want to promisify.\hypertarget{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22854}{}\doxysubsubsection{promise\+Module}\label{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22854}
Type\+: {\ttfamily function}

Custom promise module to use instead of the native one.

Check out \href{https://github.com/floatdrop/pinkie-promise}{\texttt{ {\ttfamily pinkie-\/promise}}} if you need a tiny promise polyfill.\hypertarget{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22855}{}\doxysubsubsection{options}\label{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22855}
\hypertarget{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22856}{}\doxyparagraph{multi\+Args}\label{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22856}
Type\+: {\ttfamily boolean} ~\newline
 Default\+: {\ttfamily false}

By default, the promisified function will only return the second argument from the callback, which works fine for most APIs. This option can be useful for modules like {\ttfamily request} that return multiple arguments. Turning this on will make it return an array of all arguments from the callback, excluding the error argument, instead of just the second argument.


\begin{DoxyCode}{0}
\DoxyCodeLine{const request = require('request');}
\DoxyCodeLine{const pify = require('pify');}
\DoxyCodeLine{}
\DoxyCodeLine{pify(request, \{multiArgs: true\})('https://sindresorhus.com').then(result => \{}
\DoxyCodeLine{    const [httpResponse, body] = result;}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22857}{}\doxyparagraph{include}\label{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22857}
Type\+: {\ttfamily array} of ({\ttfamily string}$\vert${\ttfamily regex})

Methods in a module to promisify. Remaining methods will be left untouched.\hypertarget{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22858}{}\doxyparagraph{exclude}\label{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22858}
Type\+: {\ttfamily array} of ({\ttfamily string}$\vert${\ttfamily regex}) ~\newline
 Default\+: {\ttfamily \mbox{[}/.+Sync\$/\mbox{]}}

Methods in a module {\bfseries{not}} to promisify. Methods with names ending with `\textquotesingle{}Sync'\`{} are excluded by default.\hypertarget{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22859}{}\doxyparagraph{exclude\+Main}\label{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22859}
Type\+: {\ttfamily boolean} ~\newline
 Default\+: {\ttfamily false}

By default, if given module is a function itself, this function will be promisified. Turn this option on if you want to promisify only methods of the module.


\begin{DoxyCode}{0}
\DoxyCodeLine{const pify = require('pify');}
\DoxyCodeLine{}
\DoxyCodeLine{function fn() \{}
\DoxyCodeLine{    return true;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{fn.method = (data, callback) => \{}
\DoxyCodeLine{    setImmediate(() => \{}
\DoxyCodeLine{        callback(data, null);}
\DoxyCodeLine{    \});}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{// promisify methods but not fn()}
\DoxyCodeLine{const promiseFn = pify(fn, \{excludeMain: true\});}
\DoxyCodeLine{}
\DoxyCodeLine{if (promiseFn()) \{}
\DoxyCodeLine{    promiseFn.method('hi').then(data => \{}
\DoxyCodeLine{        console.log(data);}
\DoxyCodeLine{    \});}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22860}{}\doxysection{License}\label{md_sfcode_node_modules_protractor_node_modules_pify_readme_autotoc_md22860}
MIT © \href{http://sindresorhus.com}{\texttt{ Sindre Sorhus}} 