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 |
|
13 | Here we find the first file that exists on disk, in array order.
|
14 |
|
15 | ```js
|
16 | import {locatePath} from 'locate-path';
|
17 |
|
18 | const files = [
|
19 | 'unicorn.png',
|
20 | 'rainbow.png', // Only this one actually exists on disk
|
21 | 'pony.png'
|
22 | ];
|
23 |
|
24 | console(await locatePath(files));
|
25 | //=> 'rainbow'
|
26 | ```
|
27 |
|
28 | ## API
|
29 |
|
30 | ### locatePath(paths, options?)
|
31 |
|
32 | Returns a `Promise<string>` for the first path that exists or `undefined` if none exists.
|
33 |
|
34 | #### paths
|
35 |
|
36 | Type: `Iterable<string>`
|
37 |
|
38 | The paths to check.
|
39 |
|
40 | #### options
|
41 |
|
42 | Type: `object`
|
43 |
|
44 | ##### concurrency
|
45 |
|
46 | Type: `number`\
|
47 | Default: `Infinity`\
|
48 | Minimum: `1`
|
49 |
|
50 | The number of concurrently pending promises.
|
51 |
|
52 | ##### preserveOrder
|
53 |
|
54 | Type: `boolean`\
|
55 | Default: `true`
|
56 |
|
57 | Preserve `paths` order when searching.
|
58 |
|
59 | Disable this to improve performance if you don't care about the order.
|
60 |
|
61 | ##### cwd
|
62 |
|
63 | Type: `string`\
|
64 | Default: `process.cwd()`
|
65 |
|
66 | The current working directory.
|
67 |
|
68 | ##### type
|
69 |
|
70 | Type: `string`\
|
71 | Default: `'file'`\
|
72 | Values: `'file' | 'directory'`
|
73 |
|
74 | The type of paths that can match.
|
75 |
|
76 | ##### allowSymlinks
|
77 |
|
78 | Type: `boolean`\
|
79 | Default: `true`
|
80 |
|
81 | Allow symbolic links to match if they point to the chosen path type.
|
82 |
|
83 | ### locatePath.sync(paths, options?)
|
84 |
|
85 | Returns the first path that exists or `undefined` if none exists.
|
86 |
|
87 | #### paths
|
88 |
|
89 | Type: `Iterable<string>`
|
90 |
|
91 | The paths to check.
|
92 |
|
93 | #### options
|
94 |
|
95 | Type: `object`
|
96 |
|
97 | ##### cwd
|
98 |
|
99 | Same as above.
|
100 |
|
101 | ##### type
|
102 |
|
103 | Same as above.
|
104 |
|
105 | ##### allowSymlinks
|
106 |
|
107 | Same 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>
|