source: imaps-frontend/node_modules/find-up/readme.md@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 3.9 KB
Line 
1# find-up [![Build Status](https://travis-ci.com/sindresorhus/find-up.svg?branch=master)](https://travis-ci.com/github/sindresorhus/find-up)
2
3> Find a file or directory by walking up parent directories
4
5## Install
6
7```
8$ npm install find-up
9```
10
11## Usage
12
13```
14/
15└── Users
16 └── sindresorhus
17 ├── unicorn.png
18 └── foo
19 └── bar
20 ├── baz
21 └── example.js
22```
23
24`example.js`
25
26```js
27const path = require('path');
28const findUp = require('find-up');
29
30(async () => {
31 console.log(await findUp('unicorn.png'));
32 //=> '/Users/sindresorhus/unicorn.png'
33
34 console.log(await findUp(['rainbow.png', 'unicorn.png']));
35 //=> '/Users/sindresorhus/unicorn.png'
36
37 console.log(await findUp(async directory => {
38 const hasUnicorns = await findUp.exists(path.join(directory, 'unicorn.png'));
39 return hasUnicorns && directory;
40 }, {type: 'directory'}));
41 //=> '/Users/sindresorhus'
42})();
43```
44
45## API
46
47### findUp(name, options?)
48### findUp(matcher, options?)
49
50Returns a `Promise` for either the path or `undefined` if it couldn't be found.
51
52### findUp([...name], options?)
53
54Returns a `Promise` for either the first path found (by respecting the order of the array) or `undefined` if none could be found.
55
56### findUp.sync(name, options?)
57### findUp.sync(matcher, options?)
58
59Returns a path or `undefined` if it couldn't be found.
60
61### findUp.sync([...name], options?)
62
63Returns the first path found (by respecting the order of the array) or `undefined` if none could be found.
64
65#### name
66
67Type: `string`
68
69Name of the file or directory to find.
70
71#### matcher
72
73Type: `Function`
74
75A function that will be called with each directory until it returns a `string` with the path, which stops the search, or the root directory has been reached and nothing was found. Useful if you want to match files with certain patterns, set of permissions, or other advanced use-cases.
76
77When using async mode, the `matcher` may optionally be an async or promise-returning function that returns the path.
78
79#### options
80
81Type: `object`
82
83##### cwd
84
85Type: `string`\
86Default: `process.cwd()`
87
88Directory to start from.
89
90##### type
91
92Type: `string`\
93Default: `'file'`\
94Values: `'file'` `'directory'`
95
96The type of paths that can match.
97
98##### allowSymlinks
99
100Type: `boolean`\
101Default: `true`
102
103Allow symbolic links to match if they point to the chosen path type.
104
105### findUp.exists(path)
106
107Returns a `Promise<boolean>` of whether the path exists.
108
109### findUp.sync.exists(path)
110
111Returns a `boolean` of whether the path exists.
112
113#### path
114
115Type: `string`
116
117Path to a file or directory.
118
119### findUp.stop
120
121A [`Symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) that can be returned by a `matcher` function to stop the search and cause `findUp` to immediately return `undefined`. Useful as a performance optimization in case the current working directory is deeply nested in the filesystem.
122
123```js
124const path = require('path');
125const findUp = require('find-up');
126
127(async () => {
128 await findUp(directory => {
129 return path.basename(directory) === 'work' ? findUp.stop : 'logo.png';
130 });
131})();
132```
133
134## Related
135
136- [find-up-cli](https://github.com/sindresorhus/find-up-cli) - CLI for this module
137- [pkg-up](https://github.com/sindresorhus/pkg-up) - Find the closest package.json file
138- [pkg-dir](https://github.com/sindresorhus/pkg-dir) - Find the root directory of an npm package
139- [resolve-from](https://github.com/sindresorhus/resolve-from) - Resolve the path of a module like `require.resolve()` but from a given path
140
141---
142
143<div align="center">
144 <b>
145 <a href="https://tidelift.com/subscription/pkg/npm-find-up?utm_source=npm-find-up&utm_medium=referral&utm_campaign=readme">Get professional support for 'find-up' with a Tidelift subscription</a>
146 </b>
147 <br>
148 <sub>
149 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
150 </sub>
151</div>
Note: See TracBrowser for help on using the repository browser.