• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# locate-path [![Build Status](https://travis-ci.org/sindresorhus/locate-path.svg?branch=master)](https://travis-ci.org/sindresorhus/locate-path)
2
3> Get the first path that exists on disk of multiple paths
4
5
6## Install
7
8```
9$ npm install locate-path
10```
11
12
13## Usage
14
15Here we find the first file that exists on disk, in array order.
16
17```js
18const locatePath = require('locate-path');
19
20const files = [
21	'unicorn.png',
22	'rainbow.png', // Only this one actually exists on disk
23	'pony.png'
24];
25
26(async () => {
27	console(await locatePath(files));
28	//=> 'rainbow'
29})();
30```
31
32
33## API
34
35### locatePath(input, [options])
36
37Returns a `Promise` for the first path that exists or `undefined` if none exists.
38
39#### input
40
41Type: `Iterable<string>`
42
43Paths to check.
44
45#### options
46
47Type: `Object`
48
49##### concurrency
50
51Type: `number`<br>
52Default: `Infinity`<br>
53Minimum: `1`
54
55Number of concurrently pending promises.
56
57##### preserveOrder
58
59Type: `boolean`<br>
60Default: `true`
61
62Preserve `input` order when searching.
63
64Disable this to improve performance if you don't care about the order.
65
66##### cwd
67
68Type: `string`<br>
69Default: `process.cwd()`
70
71Current working directory.
72
73### locatePath.sync(input, [options])
74
75Returns the first path that exists or `undefined` if none exists.
76
77#### input
78
79Type: `Iterable<string>`
80
81Paths to check.
82
83#### options
84
85Type: `Object`
86
87##### cwd
88
89Same as above.
90
91
92## Related
93
94- [path-exists](https://github.com/sindresorhus/path-exists) - Check if a path exists
95
96
97## License
98
99MIT © [Sindre Sorhus](https://sindresorhus.com)
100