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

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

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

\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_gh_pages_node_modules_pify_readme_autotoc_md11296}{}\doxysection{API}\label{md_sfcode_node_modules_gh_pages_node_modules_pify_readme_autotoc_md11296}
\hypertarget{md_sfcode_node_modules_gh_pages_node_modules_pify_readme_autotoc_md11297}{}\doxysubsection{pify(input, \mbox{[}promise\+Module\mbox{]}, \mbox{[}options\mbox{]})}\label{md_sfcode_node_modules_gh_pages_node_modules_pify_readme_autotoc_md11297}
Returns a promise wrapped version of the supplied function or module.\hypertarget{md_sfcode_node_modules_gh_pages_node_modules_pify_readme_autotoc_md11298}{}\doxysubsubsection{input}\label{md_sfcode_node_modules_gh_pages_node_modules_pify_readme_autotoc_md11298}
Type\+: {\ttfamily function}, {\ttfamily object}

Callback-\/style function or module whose methods you want to promisify.\hypertarget{md_sfcode_node_modules_gh_pages_node_modules_pify_readme_autotoc_md11299}{}\doxysubsubsection{promise\+Module}\label{md_sfcode_node_modules_gh_pages_node_modules_pify_readme_autotoc_md11299}
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_gh_pages_node_modules_pify_readme_autotoc_md11300}{}\doxysubsubsection{options}\label{md_sfcode_node_modules_gh_pages_node_modules_pify_readme_autotoc_md11300}
\hypertarget{md_sfcode_node_modules_gh_pages_node_modules_pify_readme_autotoc_md11301}{}\doxyparagraph{multi\+Args}\label{md_sfcode_node_modules_gh_pages_node_modules_pify_readme_autotoc_md11301}
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_gh_pages_node_modules_pify_readme_autotoc_md11302}{}\doxyparagraph{include}\label{md_sfcode_node_modules_gh_pages_node_modules_pify_readme_autotoc_md11302}
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_gh_pages_node_modules_pify_readme_autotoc_md11303}{}\doxyparagraph{exclude}\label{md_sfcode_node_modules_gh_pages_node_modules_pify_readme_autotoc_md11303}
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_gh_pages_node_modules_pify_readme_autotoc_md11304}{}\doxyparagraph{exclude\+Main}\label{md_sfcode_node_modules_gh_pages_node_modules_pify_readme_autotoc_md11304}
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_gh_pages_node_modules_pify_readme_autotoc_md11305}{}\doxysection{License}\label{md_sfcode_node_modules_gh_pages_node_modules_pify_readme_autotoc_md11305}
MIT © \href{http://sindresorhus.com}{\texttt{ Sindre Sorhus}} 