basant307/AI_Governance_Project
048
1# find-up [](https://travis-ci.com/github/sindresorhus/find-up)2 3> Find a file or directory by walking up parent directories4 5## Install6 7```8$ npm install find-up9```10 11## Usage12 13```14/15└── Users16 └── sindresorhus17 ├── unicorn.png18 └── foo19 └── bar20 ├── baz21 └── example.js22```23 24`example.js`25 26```js27const 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## API46 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#### name66 67Type: `string`68 69Name of the file or directory to find.70 71#### matcher72 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#### options80 81Type: `object`82 83##### cwd84 85Type: `string`\86Default: `process.cwd()`87 88Directory to start from.89 90##### type91 92Type: `string`\93Default: `'file'`\94Values: `'file'` `'directory'`95 96The type of paths that can match.97 98##### allowSymlinks99 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#### path114 115Type: `string`116 117Path to a file or directory.118 119### findUp.stop120 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```js124const 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## Related135 136- [find-up-cli](https://github.com/sindresorhus/find-up-cli) - CLI for this module137- [pkg-up](https://github.com/sindresorhus/pkg-up) - Find the closest package.json file138- [pkg-dir](https://github.com/sindresorhus/pkg-dir) - Find the root directory of an npm package139- [resolve-from](https://github.com/sindresorhus/resolve-from) - Resolve the path of a module like `require.resolve()` but from a given path140 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>152 