github-pages-deploy-action/node_modules/locate-path/readme.md

100 lines
1.5 KiB
Markdown
Raw Normal View History

2020-01-28 13:07:56 +08:00
# 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
```
2020-03-22 05:13:25 +08:00
$ npm install --save locate-path
2020-01-28 13:07:56 +08:00
```
## Usage
Here we find the first file that exists on disk, in array order.
```js
const locatePath = require('locate-path');
const files = [
'unicorn.png',
2020-03-22 05:13:25 +08:00
'rainbow.png', // only this one actually exists on disk
2020-01-28 13:07:56 +08:00
'pony.png'
];
2020-03-22 05:13:25 +08:00
locatePath(files).then(foundPath => {
console.log(foundPath);
2020-01-28 13:07:56 +08:00
//=> 'rainbow'
2020-03-22 05:13:25 +08:00
});
2020-01-28 13:07:56 +08:00
```
## API
2020-03-22 05:13:25 +08:00
### locatePath(input, [options])
2020-01-28 13:07:56 +08:00
2020-03-22 05:13:25 +08:00
Returns a `Promise` for the first path that exists or `undefined` if none exists.
2020-01-28 13:07:56 +08:00
2020-03-22 05:13:25 +08:00
#### input
2020-01-28 13:07:56 +08:00
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`
2020-03-22 05:13:25 +08:00
Preserve `input` order when searching.
2020-01-28 13:07:56 +08:00
Disable this to improve performance if you don't care about the order.
##### cwd
Type: `string`<br>
Default: `process.cwd()`
Current working directory.
2020-03-22 05:13:25 +08:00
### locatePath.sync(input, [options])
2020-01-28 13:07:56 +08:00
Returns the first path that exists or `undefined` if none exists.
2020-03-22 05:13:25 +08:00
#### input
2020-01-28 13:07:56 +08:00
Type: `Iterable<string>`
Paths to check.
#### options
Type: `Object`
##### cwd
Same as above.
## Related
- [path-exists](https://github.com/sindresorhus/path-exists) - Check if a path exists
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)