{"name":"find-up","version":"8.0.0","description":"Find a file or directory by walking up parent directories","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/find-up.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=20"},"scripts":{"test":"xo && ava test/findup.js test/finddown.js && tsd"},"keywords":["find","up","find-up","findup","look-up","look","file","search","match","package","resolve","parent","parents","folder","directory","walk","walking","path"],"dependencies":{"locate-path":"^8.0.0","unicorn-magic":"^0.3.0"},"devDependencies":{"ava":"^6.4.1","is-path-inside":"^4.0.0","tempy":"^3.1.0","tsd":"^0.33.0","xo":"^1.2.2"},"xo":{"ignores":["fixture/**"],"rules":{"ava/no-import-test-files":"off","max-params":["warn",5],"unicorn/no-empty-file":"off"}},"_id":"find-up@8.0.0","gitHead":"5a009c227a484e503b78566412b1c0fd3dab3c27","types":"./index.d.ts","bugs":{"url":"https://github.com/sindresorhus/find-up/issues"},"homepage":"https://github.com/sindresorhus/find-up#readme","_nodeVersion":"20.19.5","_npmVersion":"10.9.2","dist":{"integrity":"sha512-JGG8pvDi2C+JxidYdIwQDyS/CgcrIdh18cvgxcBge3wSHRQOrooMD3GlFBcmMJAN9M42SAZjDp5zv1dglJjwww==","shasum":"9e4663f9605eeb615edd7399f376a01b1de312fe","tarball":"http://registry-npm.ywwl.com/find-up/download/find-up-8.0.0.tgz","fileCount":5,"unpackedSize":24521,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCAXSMYBXxW3ZWOm1zCcB7ySte1HLOAK+Zwj58aTLoYcgIhAP9UCFZj+L+QJQyHSWs2cba8H6glbYt4zj2cA4ifHioO"}],"size":5086,"noattachment":false,"key":"/find-up/-/find-up-8.0.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/find-up_8.0.0_1757985236922_0.8223885572987311"},"_hasShrinkwrap":false,"readme":"# find-up\n\n> Find a file or directory by walking up parent directories or down descendant directories\n\n## Install\n\n```sh\nnpm install find-up\n```\n\n## Usage\n\n```\n/\n└── Users\n    └── sindresorhus\n        ├── unicorn.png\n        └── foo\n            └── bar\n                ├── baz\n                └── example.js\n```\n\n`example.js`\n\n```js\nimport path from 'node:path';\nimport {pathExists} from 'path-exists';\nimport {findUp, findDown} from 'find-up';\n\nconsole.log(await findUp('unicorn.png'));\n//=> '/Users/sindresorhus/unicorn.png'\n\nconsole.log(await findUp(['rainbow.png', 'unicorn.png']));\n//=> '/Users/sindresorhus/unicorn.png'\n\nconsole.log(await findUp(async directory => {\n\tconst hasUnicorn = await pathExists(path.join(directory, 'unicorn.png'));\n\treturn hasUnicorn && directory;\n}, {type: 'directory'}));\n//=> '/Users/sindresorhus'\n\n// Find .git (could be a file or directory, common in submodules)\nconsole.log(await findUp('.git', {type: 'both'}));\n//=> '/Users/sindresorhus/.git'\n```\n\n## API\n\n### findUp(name, options?)\n### findUp(matcher, options?)\n\nReturns a `Promise` for either the path or `undefined` if it could not be found.\n\n### findUp([...name], options?)\n\nReturns a `Promise` for either the first path found (by respecting the order of names) or `undefined` if none could be found.\n\n### findUpMultiple(name, options?)\n### findUpMultiple(matcher, options?)\n\nReturns a `Promise` for either an array of all paths found or an empty array if none could be found.\n\n**Note:** You can limit the number of matches by setting the `limit` option.\n\n### findUpMultiple([...name], options?)\n\nReturns a `Promise` for either an array of all paths found (by respecting the order of names) or an empty array if none could be found.\n\n**Note:** You can limit the number of matches by setting the `limit` option.\n\n### findUpSync(name, options?)\n### findUpSync(matcher, options?)\n\nReturns a path or `undefined` if it could not be found.\n\n### findUpSync([...name], options?)\n\nReturns the first path found (by respecting the order of names) or `undefined` if none could be found.\n\n### findUpMultipleSync(name, options?)\n### findUpMultipleSync(matcher, options?)\n\nReturns an array of all paths found or an empty array if none could be found.\n\n### findUpMultipleSync([...name], options?)\n\nReturns an array of all paths found (by respecting the order of names) or an empty array if none could be found.\n\n**Note:** You can limit the number of matches by setting the `limit` option.\n\n### findDown(name, options?)\n### findDown([...name], options?)\n\nFind a file or directory by walking down descendant directories from `cwd`.\n\nReturns a `Promise` for either the path or `undefined` if it could not be found.\n\n```js\nimport {findUp, findDown} from 'find-up';\n\n// Find the nearest parent directory that contains a specific file\n// in its direct children (useful for monorepo roots)\nconsole.log(await findUp(async directory => {\n\treturn findDown('example.js', {cwd: directory, depth: 1});\n}));\n//=> '/Users/sindresorhus/foo'\n```\n\n### findDownSync(name, options?)\n### findDownSync([...name], options?)\n\nSynchronous version of `findDown`.\n\nReturns the path or `undefined` if it could not be found.\n\n#### name\n\nType: `string`\n\nThe name of the file or directory to find. Can be an array of names to search for multiple files.\n\n#### matcher\n\nType: `Function`\n\nCalled for each directory in the search. Return a path or `findUpStop` to stop the search. Useful if you want to match files with certain patterns, set of permissions, or other advanced use-cases.\n\n#### options\n\nType: `object`\n\n##### cwd\n\nType: `URL | string`\\\nDefault: `process.cwd()`\n\nThe directory to start from.\n\n##### type\n\nType: `string`\\\nDefault: `'file'`\\\nValues: `'file' | 'directory' | 'both'`\n\nThe type of path to match.\n\n##### allowSymlinks\n\nType: `boolean`\\\nDefault: `true`\n\nAllow symbolic links to match if they point to the chosen path type.\n\n##### stopAt\n\n*Only for `findUp` functions*\n\nType: `URL | string`\\\nDefault: Root directory\n\nA directory path where the search halts if no matches are found before reaching this point.\n\n##### limit\n\n*Only for `findUpMultiple` and `findUpMultipleSync`*\n\nType: `number`\\\nDefault: `Infinity`\n\nThe maximum number of matches to return. Useful for limiting results when searching for multiple files.\n\n### findUpStop\n\nA [`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.\n\n```js\nimport path from 'node:path';\nimport {findUp, findUpStop} from 'find-up';\n\nawait findUp(directory => {\n\t// Stop searching if we've reached a 'work' directory\n\tif (path.basename(directory) === 'work') {\n\t\treturn findUpStop;\n\t}\n\n\t// Look for package.json in this directory\n\treturn 'package.json';\n});\n```\n\n### findDown options\n\nType: `object`\n\n##### cwd\n\nType: `URL | string`\\\nDefault: `process.cwd()`\n\nThe directory to start from.\n\n##### depth\n\nType: `number`\\\nDefault: `1`\n\nMaximum number of directory levels to traverse below `cwd`.\n\n##### type\n\nType: `string`\\\nDefault: `'file'`\\\nValues: `'file' | 'directory' | 'both'`\n\nThe type of path to match.\n\n##### allowSymlinks\n\nType: `boolean`\\\nDefault: `true`\n\nAllow symbolic links to match if they point to the chosen path type.\n\n##### strategy\n\nType: `string`\\\nDefault: `'breadth'`\\\nValues: `'breadth' | 'depth'`\n\nSearch strategy to use:\n- `'breadth'`: Breadth-first search, finds shallower matches first.\n- `'depth'`: Depth-first search, fully explores each branch before moving to the next.\n\n## Related\n\n- [find-up-cli](https://github.com/sindresorhus/find-up-cli) - CLI for this module\n- [package-up](https://github.com/sindresorhus/package-up) - Find the closest package.json file\n- [package-directory](https://github.com/sindresorhus/package-directory) - Find the root directory of an npm package\n- [resolve-from](https://github.com/sindresorhus/resolve-from) - Resolve the path of a module like `require.resolve()` but from a given path\n","publish_time":1757985237112,"_cnpm_publish_time":1757985237112,"dist-tags":{"latest":"8.0.0"}}