diff options
Diffstat (limited to 'node_modules/locate-path')
-rw-r--r-- | node_modules/locate-path/index.d.ts | 83 | ||||
-rw-r--r-- | node_modules/locate-path/index.js | 65 | ||||
-rw-r--r-- | node_modules/locate-path/license | 9 | ||||
-rw-r--r-- | node_modules/locate-path/package.json | 45 | ||||
-rw-r--r-- | node_modules/locate-path/readme.md | 122 |
5 files changed, 324 insertions, 0 deletions
diff --git a/node_modules/locate-path/index.d.ts b/node_modules/locate-path/index.d.ts new file mode 100644 index 0000000..fbde526 --- /dev/null +++ b/node_modules/locate-path/index.d.ts @@ -0,0 +1,83 @@ +declare namespace locatePath { + interface Options { + /** + Current working directory. + + @default process.cwd() + */ + readonly cwd?: string; + + /** + Type of path to match. + + @default 'file' + */ + readonly type?: 'file' | 'directory'; + + /** + Allow symbolic links to match if they point to the requested path type. + + @default true + */ + readonly allowSymlinks?: boolean; + } + + interface AsyncOptions extends Options { + /** + Number of concurrently pending promises. Minimum: `1`. + + @default Infinity + */ + readonly concurrency?: number; + + /** + Preserve `paths` order when searching. + + Disable this to improve performance if you don't care about the order. + + @default true + */ + readonly preserveOrder?: boolean; + } +} + +declare const locatePath: { + /** + Get the first path that exists on disk of multiple paths. + + @param paths - Paths to check. + @returns The first path that exists or `undefined` if none exists. + + @example + ``` + import locatePath = require('locate-path'); + + const files = [ + 'unicorn.png', + 'rainbow.png', // Only this one actually exists on disk + 'pony.png' + ]; + + (async () => { + console(await locatePath(files)); + //=> 'rainbow' + })(); + ``` + */ + (paths: Iterable<string>, options?: locatePath.AsyncOptions): Promise< + string | undefined + >; + + /** + Synchronously get the first path that exists on disk of multiple paths. + + @param paths - Paths to check. + @returns The first path that exists or `undefined` if none exists. + */ + sync( + paths: Iterable<string>, + options?: locatePath.Options + ): string | undefined; +}; + +export = locatePath; diff --git a/node_modules/locate-path/index.js b/node_modules/locate-path/index.js new file mode 100644 index 0000000..4604bbf --- /dev/null +++ b/node_modules/locate-path/index.js @@ -0,0 +1,65 @@ +'use strict'; +const path = require('path'); +const fs = require('fs'); +const {promisify} = require('util'); +const pLocate = require('p-locate'); + +const fsStat = promisify(fs.stat); +const fsLStat = promisify(fs.lstat); + +const typeMappings = { + directory: 'isDirectory', + file: 'isFile' +}; + +function checkType({type}) { + if (type in typeMappings) { + return; + } + + throw new Error(`Invalid type specified: ${type}`); +} + +const matchType = (type, stat) => type === undefined || stat[typeMappings[type]](); + +module.exports = async (paths, options) => { + options = { + cwd: process.cwd(), + type: 'file', + allowSymlinks: true, + ...options + }; + checkType(options); + const statFn = options.allowSymlinks ? fsStat : fsLStat; + + return pLocate(paths, async path_ => { + try { + const stat = await statFn(path.resolve(options.cwd, path_)); + return matchType(options.type, stat); + } catch (_) { + return false; + } + }, options); +}; + +module.exports.sync = (paths, options) => { + options = { + cwd: process.cwd(), + allowSymlinks: true, + type: 'file', + ...options + }; + checkType(options); + const statFn = options.allowSymlinks ? fs.statSync : fs.lstatSync; + + for (const path_ of paths) { + try { + const stat = statFn(path.resolve(options.cwd, path_)); + + if (matchType(options.type, stat)) { + return path_; + } + } catch (_) { + } + } +}; diff --git a/node_modules/locate-path/license b/node_modules/locate-path/license new file mode 100644 index 0000000..e7af2f7 --- /dev/null +++ b/node_modules/locate-path/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/locate-path/package.json b/node_modules/locate-path/package.json new file mode 100644 index 0000000..063b290 --- /dev/null +++ b/node_modules/locate-path/package.json @@ -0,0 +1,45 @@ +{ + "name": "locate-path", + "version": "5.0.0", + "description": "Get the first path that exists on disk of multiple paths", + "license": "MIT", + "repository": "sindresorhus/locate-path", + "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": [ + "locate", + "path", + "paths", + "file", + "files", + "exists", + "find", + "finder", + "search", + "searcher", + "array", + "iterable", + "iterator" + ], + "dependencies": { + "p-locate": "^4.1.0" + }, + "devDependencies": { + "ava": "^1.4.1", + "tsd": "^0.7.2", + "xo": "^0.24.0" + } +} diff --git a/node_modules/locate-path/readme.md b/node_modules/locate-path/readme.md new file mode 100644 index 0000000..2184c6f --- /dev/null +++ b/node_modules/locate-path/readme.md @@ -0,0 +1,122 @@ +# locate-path [![Build Status](https://travis-ci.org/sindresorhus/locate-path.svg?branch=master)](https://travis-ci.org/sindresorhus/locate-path) + +> Get the first path that exists on disk of multiple paths + + +## Install + +``` +$ npm install locate-path +``` + + +## Usage + +Here we find the first file that exists on disk, in array order. + +```js +const locatePath = require('locate-path'); + +const files = [ + 'unicorn.png', + 'rainbow.png', // Only this one actually exists on disk + 'pony.png' +]; + +(async () => { + console(await locatePath(files)); + //=> 'rainbow' +})(); +``` + + +## API + +### locatePath(paths, [options]) + +Returns a `Promise<string>` for the first path that exists or `undefined` if none exists. + +#### paths + +Type: `Iterable<string>` + +Paths to check. + +#### options + +Type: `Object` + +##### concurrency + +Type: `number`<br> +Default: `Infinity`<br> +Minimum: `1` + +Number of concurrently pending promises. + +##### preserveOrder + +Type: `boolean`<br> +Default: `true` + +Preserve `paths` order when searching. + +Disable this to improve performance if you don't care about the order. + +##### cwd + +Type: `string`<br> +Default: `process.cwd()` + +Current working directory. + +##### 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. + +### locatePath.sync(paths, [options]) + +Returns the first path that exists or `undefined` if none exists. + +#### paths + +Type: `Iterable<string>` + +Paths to check. + +#### options + +Type: `Object` + +##### cwd + +Same as above. + +##### type + +Same as above. + +##### allowSymlinks + +Same as above. + + +## Related + +- [path-exists](https://github.com/sindresorhus/path-exists) - Check if a path exists + + +## License + +MIT © [Sindre Sorhus](https://sindresorhus.com) |