\begin{quote}
Get the first fulfilled promise that satisfies the provided testing function \end{quote}
Think of it like an async version of \href{https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/find}{\texttt{ {\ttfamily Array\#find}}}.\hypertarget{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15126}{}\doxysection{Install}\label{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15126}

\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install p-\/locate }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15127}{}\doxysection{Usage}\label{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15127}
Here we find the first file that exists on disk, in array order.


\begin{DoxyCode}{0}
\DoxyCodeLine{const pathExists = require('path-\/exists');}
\DoxyCodeLine{const pLocate = require('p-\/locate');}
\DoxyCodeLine{}
\DoxyCodeLine{const files = [}
\DoxyCodeLine{    'unicorn.png',}
\DoxyCodeLine{    'rainbow.png', // Only this one actually exists on disk}
\DoxyCodeLine{    'pony.png'}
\DoxyCodeLine{];}
\DoxyCodeLine{}
\DoxyCodeLine{(async () => \{}
\DoxyCodeLine{    const foundPath = await pLocate(files, file => pathExists(file));}
\DoxyCodeLine{}
\DoxyCodeLine{    console.log(foundPath);}
\DoxyCodeLine{    //=> 'rainbow'}
\DoxyCodeLine{\})(); }

\end{DoxyCode}


$\ast$\+The above is just an example. Use \href{https://github.com/sindresorhus/locate-path}{\texttt{ {\ttfamily locate-\/path}}} if you need this.$\ast$\hypertarget{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15128}{}\doxysection{API}\label{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15128}
\hypertarget{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15129}{}\doxysubsection{p\+Locate(input, tester, \mbox{[}options\mbox{]})}\label{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15129}
Returns a {\ttfamily Promise} that is fulfilled when {\ttfamily tester} resolves to {\ttfamily true} or the iterable is done, or rejects if any of the promises reject. The fulfilled value is the current iterable value or {\ttfamily undefined} if {\ttfamily tester} never resolved to {\ttfamily true}.\hypertarget{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15130}{}\doxysubsubsection{input}\label{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15130}
Type\+: {\ttfamily Iterable$<$Promise $\vert$ unknown$>$}

An iterable of promises/values to test.\hypertarget{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15131}{}\doxysubsubsection{tester(element)}\label{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15131}
Type\+: {\ttfamily Function}

This function will receive resolved values from {\ttfamily input} and is expected to return a {\ttfamily Promise$<$boolean$>$} or {\ttfamily boolean}.\hypertarget{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15132}{}\doxysubsubsection{options}\label{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15132}
Type\+: {\ttfamily Object}\hypertarget{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15133}{}\doxyparagraph{concurrency}\label{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15133}
Type\+: {\ttfamily number}~\newline
 Default\+: {\ttfamily Infinity}~\newline
 Minimum\+: {\ttfamily 1}

Number of concurrently pending promises returned by {\ttfamily tester}.\hypertarget{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15134}{}\doxyparagraph{preserve\+Order}\label{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15134}
Type\+: {\ttfamily boolean}~\newline
 Default\+: {\ttfamily true}

Preserve {\ttfamily input} order when searching.

Disable this to improve performance if you don\textquotesingle{}t care about the order.\hypertarget{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15135}{}\doxysection{Related}\label{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15135}

\begin{DoxyItemize}
\item \href{https://github.com/sindresorhus/p-map}{\texttt{ p-\/map}} -\/ Map over promises concurrently
\item \href{https://github.com/sindresorhus/p-filter}{\texttt{ p-\/filter}} -\/ Filter promises concurrently
\item \href{https://github.com/sindresorhus/p-any}{\texttt{ p-\/any}} -\/ Wait for any promise to be fulfilled
\item \href{https://github.com/sindresorhus/promise-fun}{\texttt{ More…}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15136}{}\doxysection{License}\label{md_sfcode_node_modules_karma_node_modules_p_locate_readme_autotoc_md15136}
MIT © \href{https://sindresorhus.com}{\texttt{ Sindre Sorhus}} 