aboutsummaryrefslogtreecommitdiff
path: root/node_modules/find-up
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/find-up')
-rw-r--r--node_modules/find-up/index.d.ts137
-rw-r--r--node_modules/find-up/index.js89
-rw-r--r--node_modules/find-up/license9
-rw-r--r--node_modules/find-up/package.json53
-rw-r--r--node_modules/find-up/readme.md156
5 files changed, 444 insertions, 0 deletions
diff --git a/node_modules/find-up/index.d.ts b/node_modules/find-up/index.d.ts
new file mode 100644
index 0000000..41e3192
--- /dev/null
+++ b/node_modules/find-up/index.d.ts
@@ -0,0 +1,137 @@
+import {Options as LocatePathOptions} from 'locate-path';
+
+declare const stop: unique symbol;
+
+declare namespace findUp {
+ interface Options extends LocatePathOptions {}
+
+ type StopSymbol = typeof stop;
+
+ type Match = string | StopSymbol | undefined;
+}
+
+declare const findUp: {
+ /**
+ Find a file or directory by walking up parent directories.
+
+ @param name - Name of the file or directory to find. Can be multiple.
+ @returns The first path found (by respecting the order of `name`s) or `undefined` if none could be found.
+
+ @example
+ ```
+ // /
+ // └── Users
+ // └── sindresorhus
+ // ├── unicorn.png
+ // └── foo
+ // └── bar
+ // ├── baz
+ // └── example.js
+
+ // example.js
+ import findUp = require('find-up');
+
+ (async () => {
+ console.log(await findUp('unicorn.png'));
+ //=> '/Users/sindresorhus/unicorn.png'
+
+ console.log(await findUp(['rainbow.png', 'unicorn.png']));
+ //=> '/Users/sindresorhus/unicorn.png'
+ })();
+ ```
+ */
+ (name: string | string[], options?: findUp.Options): Promise<string | undefined>;
+
+ /**
+ Find a file or directory by walking up parent directories.
+
+ @param matcher - Called for each directory in the search. Return a path or `findUp.stop` to stop the search.
+ @returns The first path found or `undefined` if none could be found.
+
+ @example
+ ```
+ import path = require('path');
+ import findUp = require('find-up');
+
+ (async () => {
+ console.log(await findUp(async directory => {
+ const hasUnicorns = await findUp.exists(path.join(directory, 'unicorn.png'));
+ return hasUnicorns && directory;
+ }, {type: 'directory'}));
+ //=> '/Users/sindresorhus'
+ })();
+ ```
+ */
+ (matcher: (directory: string) => (findUp.Match | Promise<findUp.Match>), options?: findUp.Options): Promise<string | undefined>;
+
+ sync: {
+ /**
+ Synchronously find a file or directory by walking up parent directories.
+
+ @param name - Name of the file or directory to find. Can be multiple.
+ @returns The first path found (by respecting the order of `name`s) or `undefined` if none could be found.
+ */
+ (name: string | string[], options?: findUp.Options): string | undefined;
+
+ /**
+ Synchronously find a file or directory by walking up parent directories.
+
+ @param matcher - Called for each directory in the search. Return a path or `findUp.stop` to stop the search.
+ @returns The first path found or `undefined` if none could be found.
+
+ @example
+ ```
+ import path = require('path');
+ import findUp = require('find-up');
+
+ console.log(findUp.sync(directory => {
+ const hasUnicorns = findUp.sync.exists(path.join(directory, 'unicorn.png'));
+ return hasUnicorns && directory;
+ }, {type: 'directory'}));
+ //=> '/Users/sindresorhus'
+ ```
+ */
+ (matcher: (directory: string) => findUp.Match, options?: findUp.Options): string | undefined;
+
+ /**
+ Synchronously check if a path exists.
+
+ @param path - Path to the file or directory.
+ @returns Whether the path exists.
+
+ @example
+ ```
+ import findUp = require('find-up');
+
+ console.log(findUp.sync.exists('/Users/sindresorhus/unicorn.png'));
+ //=> true
+ ```
+ */
+ exists(path: string): boolean;
+ }
+
+ /**
+ Check if a path exists.
+
+ @param path - Path to a file or directory.
+ @returns Whether the path exists.
+
+ @example
+ ```
+ import findUp = require('find-up');
+
+ (async () => {
+ console.log(await findUp.exists('/Users/sindresorhus/unicorn.png'));
+ //=> true
+ })();
+ ```
+ */
+ exists(path: string): Promise<boolean>;
+
+ /**
+ Return this in a `matcher` function to stop the search and force `findUp` to immediately return `undefined`.
+ */
+ readonly stop: findUp.StopSymbol;
+};
+
+export = findUp;
diff --git a/node_modules/find-up/index.js b/node_modules/find-up/index.js
new file mode 100644
index 0000000..ce564e5
--- /dev/null
+++ b/node_modules/find-up/index.js
@@ -0,0 +1,89 @@
+'use strict';
+const path = require('path');
+const locatePath = require('locate-path');
+const pathExists = require('path-exists');
+
+const stop = Symbol('findUp.stop');
+
+module.exports = async (name, options = {}) => {
+ let directory = path.resolve(options.cwd || '');
+ const {root} = path.parse(directory);
+ const paths = [].concat(name);
+
+ const runMatcher = async locateOptions => {
+ if (typeof name !== 'function') {
+ return locatePath(paths, locateOptions);
+ }
+
+ const foundPath = await name(locateOptions.cwd);
+ if (typeof foundPath === 'string') {
+ return locatePath([foundPath], locateOptions);
+ }
+
+ return foundPath;
+ };
+
+ // eslint-disable-next-line no-constant-condition
+ while (true) {
+ // eslint-disable-next-line no-await-in-loop
+ const foundPath = await runMatcher({...options, cwd: directory});
+
+ if (foundPath === stop) {
+ return;
+ }
+
+ if (foundPath) {
+ return path.resolve(directory, foundPath);
+ }
+
+ if (directory === root) {
+ return;
+ }
+
+ directory = path.dirname(directory);
+ }
+};
+
+module.exports.sync = (name, options = {}) => {
+ let directory = path.resolve(options.cwd || '');
+ const {root} = path.parse(directory);
+ const paths = [].concat(name);
+
+ const runMatcher = locateOptions => {
+ if (typeof name !== 'function') {
+ return locatePath.sync(paths, locateOptions);
+ }
+
+ const foundPath = name(locateOptions.cwd);
+ if (typeof foundPath === 'string') {
+ return locatePath.sync([foundPath], locateOptions);
+ }
+
+ return foundPath;
+ };
+
+ // eslint-disable-next-line no-constant-condition
+ while (true) {
+ const foundPath = runMatcher({...options, cwd: directory});
+
+ if (foundPath === stop) {
+ return;
+ }
+
+ if (foundPath) {
+ return path.resolve(directory, foundPath);
+ }
+
+ if (directory === root) {
+ return;
+ }
+
+ directory = path.dirname(directory);
+ }
+};
+
+module.exports.exists = pathExists;
+
+module.exports.sync.exists = pathExists.sync;
+
+module.exports.stop = stop;
diff --git a/node_modules/find-up/license b/node_modules/find-up/license
new file mode 100644
index 0000000..e7af2f7
--- /dev/null
+++ b/node_modules/find-up/license
@@ -0,0 +1,9 @@
+MIT License
+
+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/node_modules/find-up/package.json b/node_modules/find-up/package.json
new file mode 100644
index 0000000..cd50281
--- /dev/null
+++ b/node_modules/find-up/package.json
@@ -0,0 +1,53 @@
+{
+ "name": "find-up",
+ "version": "4.1.0",
+ "description": "Find a file or directory by walking up parent directories",
+ "license": "MIT",
+ "repository": "sindresorhus/find-up",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "sindresorhus.com"
+ },
+ "engines": {
+ "node": ">=8"
+ },
+ "scripts": {
+ "test": "xo && ava && tsd"
+ },
+ "files": [
+ "index.js",
+ "index.d.ts"
+ ],
+ "keywords": [
+ "find",
+ "up",
+ "find-up",
+ "findup",
+ "look-up",
+ "look",
+ "file",
+ "search",
+ "match",
+ "package",
+ "resolve",
+ "parent",
+ "parents",
+ "folder",
+ "directory",
+ "walk",
+ "walking",
+ "path"
+ ],
+ "dependencies": {
+ "locate-path": "^5.0.0",
+ "path-exists": "^4.0.0"
+ },
+ "devDependencies": {
+ "ava": "^2.1.0",
+ "is-path-inside": "^2.1.0",
+ "tempy": "^0.3.0",
+ "tsd": "^0.7.3",
+ "xo": "^0.24.0"
+ }
+}
diff --git a/node_modules/find-up/readme.md b/node_modules/find-up/readme.md
new file mode 100644
index 0000000..d6a21e5
--- /dev/null
+++ b/node_modules/find-up/readme.md
@@ -0,0 +1,156 @@
+# find-up [![Build Status](https://travis-ci.org/sindresorhus/find-up.svg?branch=master)](https://travis-ci.org/sindresorhus/find-up)
+
+> Find a file or directory by walking up parent directories
+
+
+## Install
+
+```
+$ npm install find-up
+```
+
+
+## Usage
+
+```
+/
+└── Users
+ └── sindresorhus
+ ├── unicorn.png
+ └── foo
+ └── bar
+ ├── baz
+ └── example.js
+```
+
+`example.js`
+
+```js
+const path = require('path');
+const findUp = require('find-up');
+
+(async () => {
+ console.log(await findUp('unicorn.png'));
+ //=> '/Users/sindresorhus/unicorn.png'
+
+ console.log(await findUp(['rainbow.png', 'unicorn.png']));
+ //=> '/Users/sindresorhus/unicorn.png'
+
+ console.log(await findUp(async directory => {
+ const hasUnicorns = await findUp.exists(path.join(directory, 'unicorn.png'));
+ return hasUnicorns && directory;
+ }, {type: 'directory'}));
+ //=> '/Users/sindresorhus'
+})();
+```
+
+
+## API
+
+### findUp(name, options?)
+### findUp(matcher, options?)
+
+Returns a `Promise` for either the path or `undefined` if it couldn't be found.
+
+### findUp([...name], options?)
+
+Returns a `Promise` for either the first path found (by respecting the order of the array) or `undefined` if none could be found.
+
+### findUp.sync(name, options?)
+### findUp.sync(matcher, options?)
+
+Returns a path or `undefined` if it couldn't be found.
+
+### findUp.sync([...name], options?)
+
+Returns the first path found (by respecting the order of the array) or `undefined` if none could be found.
+
+#### name
+
+Type: `string`
+
+Name of the file or directory to find.
+
+#### matcher
+
+Type: `Function`
+
+A function that will be called with each directory until it returns a `string` with the path, which stops the search, or the root directory has been reached and nothing was found. Useful if you want to match files with certain patterns, set of permissions, or other advanced use-cases.
+
+When using async mode, the `matcher` may optionally be an async or promise-returning function that returns the path.
+
+#### options
+
+Type: `object`
+
+##### cwd
+
+Type: `string`<br>
+Default: `process.cwd()`
+
+Directory to start from.
+
+##### type
+
+Type: `string`<br>
+Default: `'file'`<br>
+Values: `'file'` `'directory'`
+
+The type of paths that can match.
+
+##### allowSymlinks
+
+Type: `boolean`<br>
+Default: `true`
+
+Allow symbolic links to match if they point to the chosen path type.
+
+### findUp.exists(path)
+
+Returns a `Promise<boolean>` of whether the path exists.
+
+### findUp.sync.exists(path)
+
+Returns a `boolean` of whether the path exists.
+
+#### path
+
+Type: `string`
+
+Path to a file or directory.
+
+### findUp.stop
+
+A [`Symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) that can be returned by a `matcher` function to stop the search and cause `findUp` to immediately return `undefined`. Useful as a performance optimization in case the current working directory is deeply nested in the filesystem.
+
+```js
+const path = require('path');
+const findUp = require('find-up');
+
+(async () => {
+ await findUp(directory => {
+ return path.basename(directory) === 'work' ? findUp.stop : 'logo.png';
+ });
+})();
+```
+
+
+## Related
+
+- [find-up-cli](https://github.com/sindresorhus/find-up-cli) - CLI for this module
+- [pkg-up](https://github.com/sindresorhus/pkg-up) - Find the closest package.json file
+- [pkg-dir](https://github.com/sindresorhus/pkg-dir) - Find the root directory of an npm package
+- [resolve-from](https://github.com/sindresorhus/resolve-from) - Resolve the path of a module like `require.resolve()` but from a given path
+
+
+---
+
+<div align="center">
+ <b>
+ <a href="https://tidelift.com/subscription/pkg/npm-find-up?utm_source=npm-find-up&utm_medium=referral&utm_campaign=readme">Get professional support for 'find-up' with a Tidelift subscription</a>
+ </b>
+ <br>
+ <sub>
+ Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
+ </sub>
+</div>