UNPKG

2.06 kBMarkdownView Raw
1# locate-path
2
3> Get the first path that exists on disk of multiple paths
4
5## Install
6
7```
8$ npm install locate-path
9```
10
11## Usage
12
13Here we find the first file that exists on disk, in array order.
14
15```js
16import {locatePath} from 'locate-path';
17
18const files = [
19 'unicorn.png',
20 'rainbow.png', // Only this one actually exists on disk
21 'pony.png'
22];
23
24console(await locatePath(files));
25//=> 'rainbow'
26```
27
28## API
29
30### locatePath(paths, options?)
31
32Returns a `Promise<string>` for the first path that exists or `undefined` if none exists.
33
34#### paths
35
36Type: `Iterable<string>`
37
38The paths to check.
39
40#### options
41
42Type: `object`
43
44##### concurrency
45
46Type: `number`\
47Default: `Infinity`\
48Minimum: `1`
49
50The number of concurrently pending promises.
51
52##### preserveOrder
53
54Type: `boolean`\
55Default: `true`
56
57Preserve `paths` order when searching.
58
59Disable this to improve performance if you don't care about the order.
60
61##### cwd
62
63Type: `string`\
64Default: `process.cwd()`
65
66The current working directory.
67
68##### type
69
70Type: `string`\
71Default: `'file'`\
72Values: `'file' | 'directory'`
73
74The type of paths that can match.
75
76##### allowSymlinks
77
78Type: `boolean`\
79Default: `true`
80
81Allow symbolic links to match if they point to the chosen path type.
82
83### locatePath.sync(paths, options?)
84
85Returns the first path that exists or `undefined` if none exists.
86
87#### paths
88
89Type: `Iterable<string>`
90
91The paths to check.
92
93#### options
94
95Type: `object`
96
97##### cwd
98
99Same as above.
100
101##### type
102
103Same as above.
104
105##### allowSymlinks
106
107Same as above.
108
109## Related
110
111- [path-exists](https://github.com/sindresorhus/path-exists) - Check if a path exists
112
113---
114
115<div align="center">
116 <b>
117 <a href="https://tidelift.com/subscription/pkg/npm-locate-path?utm_source=npm-locate-path&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
118 </b>
119 <br>
120 <sub>
121 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
122 </sub>
123</div>