

\href{https://gulpjs.com}{\texttt{  }} \hypertarget{md_sfcode_node_modules_glob_parent_README_autotoc_md11366}{}\doxysection{glob-\/parent}\label{md_sfcode_node_modules_glob_parent_README_autotoc_md11366}
\href{https://www.npmjs.com/package/glob-parent}{\texttt{ }} \href{https://www.npmjs.com/package/glob-parent}{\texttt{ }} \href{https://dev.azure.com/gulpjs/gulp/_build/latest?definitionId=2&branchName=master}{\texttt{ }} \href{https://travis-ci.org/gulpjs/glob-parent}{\texttt{ }} \href{https://ci.appveyor.com/project/gulpjs/glob-parent}{\texttt{ }} \href{https://coveralls.io/r/gulpjs/glob-parent}{\texttt{ }} \href{https://gitter.im/gulpjs/gulp}{\texttt{ }}

Extract the non-\/magic parent path from a glob string.\hypertarget{md_sfcode_node_modules_glob_parent_README_autotoc_md11367}{}\doxysubsection{Usage}\label{md_sfcode_node_modules_glob_parent_README_autotoc_md11367}

\begin{DoxyCode}{0}
\DoxyCodeLine{var globParent = require('glob-\/parent');}
\DoxyCodeLine{}
\DoxyCodeLine{globParent('path/to/*.js'); // 'path/to'}
\DoxyCodeLine{globParent('/root/path/to/*.js'); // '/root/path/to'}
\DoxyCodeLine{globParent('/*.js'); // '/'}
\DoxyCodeLine{globParent('*.js'); // '.'}
\DoxyCodeLine{globParent('**/*.js'); // '.'}
\DoxyCodeLine{globParent('path/\{to,from\}'); // 'path'}
\DoxyCodeLine{globParent('path/!(to|from)'); // 'path'}
\DoxyCodeLine{globParent('path/?(to|from)'); // 'path'}
\DoxyCodeLine{globParent('path/+(to|from)'); // 'path'}
\DoxyCodeLine{globParent('path/*(to|from)'); // 'path'}
\DoxyCodeLine{globParent('path/@(to|from)'); // 'path'}
\DoxyCodeLine{globParent('path/**/*'); // 'path'}
\DoxyCodeLine{}
\DoxyCodeLine{// if provided a non-\/glob path, returns the nearest dir}
\DoxyCodeLine{globParent('path/foo/bar.js'); // 'path/foo'}
\DoxyCodeLine{globParent('path/foo/'); // 'path/foo'}
\DoxyCodeLine{globParent('path/foo'); // 'path' (see issue \#3 for details) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_glob_parent_README_autotoc_md11368}{}\doxysubsection{API}\label{md_sfcode_node_modules_glob_parent_README_autotoc_md11368}
\hypertarget{md_sfcode_node_modules_glob_parent_README_autotoc_md11369}{}\doxysubsubsection{$<$tt$>$glob\+Parent(maybe\+Glob\+String, \mbox{[}options\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_glob_parent_README_autotoc_md11369}
Takes a string and returns the part of the path before the glob begins. Be aware of Escaping rules and Limitations below.\hypertarget{md_sfcode_node_modules_glob_parent_README_autotoc_md11370}{}\doxyparagraph{options}\label{md_sfcode_node_modules_glob_parent_README_autotoc_md11370}

\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  // Disables the automatic conversion of slashes for Windows}
\DoxyCodeLine{  flipBackslashes: true}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_glob_parent_README_autotoc_md11371}{}\doxysubsection{Escaping}\label{md_sfcode_node_modules_glob_parent_README_autotoc_md11371}
The following characters have special significance in glob patterns and must be escaped if you want them to be treated as regular path characters\+:


\begin{DoxyItemize}
\item {\ttfamily ?} (question mark) unless used as a path segment alone
\item {\ttfamily $\ast$} (asterisk)
\item {\ttfamily $\vert$} (pipe)
\item {\ttfamily (} (opening parenthesis)
\item {\ttfamily )} (closing parenthesis)
\item {\ttfamily \{} (opening curly brace)
\item {\ttfamily \}} (closing curly brace)
\item {\ttfamily \mbox{[}} (opening bracket)
\item {\ttfamily \mbox{]}} (closing bracket)
\end{DoxyItemize}

{\bfseries{Example}}


\begin{DoxyCode}{0}
\DoxyCodeLine{globParent('foo/[bar]/') // 'foo'}
\DoxyCodeLine{globParent('foo/\(\backslash\)\(\backslash\)[bar]/') // 'foo/[bar]' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_glob_parent_README_autotoc_md11372}{}\doxysubsection{Limitations}\label{md_sfcode_node_modules_glob_parent_README_autotoc_md11372}
\hypertarget{md_sfcode_node_modules_glob_parent_README_autotoc_md11373}{}\doxysubsubsection{Braces \& Brackets}\label{md_sfcode_node_modules_glob_parent_README_autotoc_md11373}
This library attempts a quick and imperfect method of determining which path parts have glob magic without fully parsing/lexing the pattern. There are some advanced use cases that can trip it up, such as nested braces where the outer pair is escaped and the inner one contains a path separator. If you find yourself in the unlikely circumstance of being affected by this or need to ensure higher-\/fidelity glob handling in your library, it is recommended that you pre-\/process your input with \href{https://github.com/jonschlinkert/expand-braces}{\texttt{ expand-\/braces}} and/or \href{https://github.com/jonschlinkert/expand-brackets}{\texttt{ expand-\/brackets}}.\hypertarget{md_sfcode_node_modules_glob_parent_README_autotoc_md11374}{}\doxysubsubsection{Windows}\label{md_sfcode_node_modules_glob_parent_README_autotoc_md11374}
Backslashes are not valid path separators for globs. If a path with backslashes is provided anyway, for simple cases, glob-\/parent will replace the path separator for you and return the non-\/glob parent path (now with forward-\/slashes, which are still valid as Windows path separators).

This cannot be used in conjunction with escape characters.


\begin{DoxyCode}{0}
\DoxyCodeLine{// BAD}
\DoxyCodeLine{globParent('C:\(\backslash\)\(\backslash\)Program Files \(\backslash\)\(\backslash\)(x86\(\backslash\)\(\backslash\))\(\backslash\)\(\backslash\)*.ext') // 'C:/Program Files /(x86/)'}
\DoxyCodeLine{}
\DoxyCodeLine{// GOOD}
\DoxyCodeLine{globParent('C:/Program Files\(\backslash\)\(\backslash\)(x86\(\backslash\)\(\backslash\))/*.ext') // 'C:/Program Files (x86)' }

\end{DoxyCode}


If you are using escape characters for a pattern without path parts (i.\+e. relative to {\ttfamily cwd}), prefix with {\ttfamily ./} to avoid confusing glob-\/parent.


\begin{DoxyCode}{0}
\DoxyCodeLine{// BAD}
\DoxyCodeLine{globParent('foo \(\backslash\)\(\backslash\)[bar]') // 'foo '}
\DoxyCodeLine{globParent('foo \(\backslash\)\(\backslash\)[bar]*') // 'foo '}
\DoxyCodeLine{}
\DoxyCodeLine{// GOOD}
\DoxyCodeLine{globParent('./foo \(\backslash\)\(\backslash\)[bar]') // 'foo [bar]'}
\DoxyCodeLine{globParent('./foo \(\backslash\)\(\backslash\)[bar]*') // '.' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_glob_parent_README_autotoc_md11375}{}\doxysubsection{License}\label{md_sfcode_node_modules_glob_parent_README_autotoc_md11375}
ISC 