\href{https://travis-ci.org/RyanZim/universalify}{\texttt{ }}   

Make a callback-\/ or promise-\/based function support both promises and callbacks.

Uses the native promise implementation.\hypertarget{md_sfcode_node_modules_universalify_README_autotoc_md31480}{}\doxysection{Installation}\label{md_sfcode_node_modules_universalify_README_autotoc_md31480}

\begin{DoxyCode}{0}
\DoxyCodeLine{npm install universalify }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_universalify_README_autotoc_md31481}{}\doxysection{API}\label{md_sfcode_node_modules_universalify_README_autotoc_md31481}
\hypertarget{md_sfcode_node_modules_universalify_README_autotoc_md31482}{}\doxysubsection{$<$tt$>$universalify.\+from\+Callback(fn)$<$/tt$>$}\label{md_sfcode_node_modules_universalify_README_autotoc_md31482}
Takes a callback-\/based function to universalify, and returns the universalified function.

Function must take a callback as the last parameter that will be called with the signature {\ttfamily (error, result)}. {\ttfamily universalify} does not support calling the callback with more than three arguments, and does not ensure that the callback is only called once.


\begin{DoxyCode}{0}
\DoxyCodeLine{function callbackFn (n, cb) \{}
\DoxyCodeLine{  setTimeout(() => cb(null, n), 15)}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{const fn = universalify.fromCallback(callbackFn)}
\DoxyCodeLine{}
\DoxyCodeLine{// Works with Promises:}
\DoxyCodeLine{fn('Hello World!')}
\DoxyCodeLine{.then(result => console.log(result)) // -\/> Hello World!}
\DoxyCodeLine{.catch(error => console.error(error))}
\DoxyCodeLine{}
\DoxyCodeLine{// Works with Callbacks:}
\DoxyCodeLine{fn('Hi!', (error, result) => \{}
\DoxyCodeLine{  if (error) return console.error(error)}
\DoxyCodeLine{  console.log(result)}
\DoxyCodeLine{  // -\/> Hi!}
\DoxyCodeLine{\}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_universalify_README_autotoc_md31483}{}\doxysubsection{$<$tt$>$universalify.\+from\+Promise(fn)$<$/tt$>$}\label{md_sfcode_node_modules_universalify_README_autotoc_md31483}
Takes a promise-\/based function to universalify, and returns the universalified function.

Function must return a valid JS promise. {\ttfamily universalify} does not ensure that a valid promise is returned.


\begin{DoxyCode}{0}
\DoxyCodeLine{function promiseFn (n) \{}
\DoxyCodeLine{  return new Promise(resolve => \{}
\DoxyCodeLine{    setTimeout(() => resolve(n), 15)}
\DoxyCodeLine{  \})}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{const fn = universalify.fromPromise(promiseFn)}
\DoxyCodeLine{}
\DoxyCodeLine{// Works with Promises:}
\DoxyCodeLine{fn('Hello World!')}
\DoxyCodeLine{.then(result => console.log(result)) // -\/> Hello World!}
\DoxyCodeLine{.catch(error => console.error(error))}
\DoxyCodeLine{}
\DoxyCodeLine{// Works with Callbacks:}
\DoxyCodeLine{fn('Hi!', (error, result) => \{}
\DoxyCodeLine{  if (error) return console.error(error)}
\DoxyCodeLine{  console.log(result)}
\DoxyCodeLine{  // -\/> Hi!}
\DoxyCodeLine{\}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_universalify_README_autotoc_md31484}{}\doxysection{License}\label{md_sfcode_node_modules_universalify_README_autotoc_md31484}
MIT 