Last change
on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.8 KB
|
Line | |
---|
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 |
|
---|
15 | Here we find the first file that exists on disk, in array order.
|
---|
16 |
|
---|
17 | ```js
|
---|
18 | const locatePath = require('locate-path');
|
---|
19 |
|
---|
20 | const 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(paths, [options])
|
---|
36 |
|
---|
37 | Returns a `Promise<string>` for the first path that exists or `undefined` if none exists.
|
---|
38 |
|
---|
39 | #### paths
|
---|
40 |
|
---|
41 | Type: `Iterable<string>`
|
---|
42 |
|
---|
43 | Paths to check.
|
---|
44 |
|
---|
45 | #### options
|
---|
46 |
|
---|
47 | Type: `Object`
|
---|
48 |
|
---|
49 | ##### concurrency
|
---|
50 |
|
---|
51 | Type: `number`<br>
|
---|
52 | Default: `Infinity`<br>
|
---|
53 | Minimum: `1`
|
---|
54 |
|
---|
55 | Number of concurrently pending promises.
|
---|
56 |
|
---|
57 | ##### preserveOrder
|
---|
58 |
|
---|
59 | Type: `boolean`<br>
|
---|
60 | Default: `true`
|
---|
61 |
|
---|
62 | Preserve `paths` order when searching.
|
---|
63 |
|
---|
64 | Disable this to improve performance if you don't care about the order.
|
---|
65 |
|
---|
66 | ##### cwd
|
---|
67 |
|
---|
68 | Type: `string`<br>
|
---|
69 | Default: `process.cwd()`
|
---|
70 |
|
---|
71 | Current working directory.
|
---|
72 |
|
---|
73 | ##### type
|
---|
74 |
|
---|
75 | Type: `string`<br>
|
---|
76 | Default: `file`<br>
|
---|
77 | Values: `file` `directory`
|
---|
78 |
|
---|
79 | The type of paths that can match.
|
---|
80 |
|
---|
81 | ##### allowSymlinks
|
---|
82 |
|
---|
83 | Type: `boolean`<br>
|
---|
84 | Default: `true`
|
---|
85 |
|
---|
86 | Allow symbolic links to match if they point to the chosen path type.
|
---|
87 |
|
---|
88 | ### locatePath.sync(paths, [options])
|
---|
89 |
|
---|
90 | Returns the first path that exists or `undefined` if none exists.
|
---|
91 |
|
---|
92 | #### paths
|
---|
93 |
|
---|
94 | Type: `Iterable<string>`
|
---|
95 |
|
---|
96 | Paths to check.
|
---|
97 |
|
---|
98 | #### options
|
---|
99 |
|
---|
100 | Type: `Object`
|
---|
101 |
|
---|
102 | ##### cwd
|
---|
103 |
|
---|
104 | Same as above.
|
---|
105 |
|
---|
106 | ##### type
|
---|
107 |
|
---|
108 | Same as above.
|
---|
109 |
|
---|
110 | ##### allowSymlinks
|
---|
111 |
|
---|
112 | Same as above.
|
---|
113 |
|
---|
114 |
|
---|
115 | ## Related
|
---|
116 |
|
---|
117 | - [path-exists](https://github.com/sindresorhus/path-exists) - Check if a path exists
|
---|
118 |
|
---|
119 |
|
---|
120 | ## License
|
---|
121 |
|
---|
122 | MIT © [Sindre Sorhus](https://sindresorhus.com)
|
---|
Note:
See
TracBrowser
for help on using the repository browser.