{"id":13396775,"url":"https://github.com/sindresorhus/find-up","last_synced_at":"2025-05-13T16:11:10.336Z","repository":{"id":1212517,"uuid":"41723004","full_name":"sindresorhus/find-up","owner":"sindresorhus","description":"Find a file or directory by walking up parent directories","archived":false,"fork":false,"pushed_at":"2025-03-21T07:34:30.000Z","size":73,"stargazers_count":604,"open_issues_count":4,"forks_count":44,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-04-23T20:59:07.282Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2015-09-01T07:12:57.000Z","updated_at":"2025-04-18T17:58:19.000Z","dependencies_parsed_at":"2024-11-05T21:02:28.941Z","dependency_job_id":"87bc2e0f-ffa9-4101-a9e8-c5dcc8c6a574","html_url":"https://github.com/sindresorhus/find-up","commit_stats":{"total_commits":68,"total_committers":16,"mean_commits":4.25,"dds":"0.32352941176470584","last_synced_commit":"b733bb70d3aa21b22fa011be8089110d467c317f"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Ffind-up","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Ffind-up/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Ffind-up/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Ffind-up/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/find-up/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250514767,"owners_count":21443208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T18:01:02.748Z","updated_at":"2025-04-23T20:59:11.914Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["文件","Packages","Repository","JavaScript","包","目录","Filesystem","Uncategorized"],"sub_categories":["Filesystem","文件系统","Uncategorized"],"readme":"# find-up\n\n\u003e Find a file or directory by walking up parent 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 {findUp, pathExists} from 'find-up';\n\nconsole.log(await findUp('unicorn.png'));\n//=\u003e '/Users/sindresorhus/unicorn.png'\n\nconsole.log(await findUp(['rainbow.png', 'unicorn.png']));\n//=\u003e '/Users/sindresorhus/unicorn.png'\n\nconsole.log(await findUp(async directory =\u003e {\n\tconst hasUnicorns = await pathExists(path.join(directory, 'unicorn.png'));\n\treturn hasUnicorns \u0026\u0026 directory;\n}, {type: 'directory'}));\n//=\u003e '/Users/sindresorhus'\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 the array) 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 paths or an empty array if none could be found.\n\n### findUpMultiple([...name], options?)\n\nReturns a `Promise` for either an array of the first paths found (by respecting the order of the array) or an empty array if none could be found.\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 the array) or `undefined` if none could be found.\n\n### findUpMultipleSync(name, options?)\n### findUpMultipleSync(matcher, options?)\n\nReturns an array of paths or an empty array if none could be found.\n\n### findUpMultipleSync([...name], options?)\n\nReturns an array of the first paths found (by respecting the order of the array) or an empty array if none could be found.\n\n#### name\n\nType: `string`\n\nThe name of the file or directory to find.\n\n#### matcher\n\nType: `Function`\n\nA 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.\n\nWhen using async mode, the `matcher` may optionally be an async or promise-returning function that returns the path.\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'`\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\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### pathExists(path)\n\nReturns a `Promise\u003cboolean\u003e` of whether the path exists.\n\n### pathExistsSync(path)\n\nReturns a `boolean` of whether the path exists.\n\n#### path\n\nType: `string`\n\nThe path to a file or directory.\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 =\u003e {\n\treturn path.basename(directory) === 'work' ? findUpStop : 'logo.png';\n});\n```\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- [pkg-dir](https://github.com/sindresorhus/pkg-dir) - 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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Ffind-up","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Ffind-up","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Ffind-up/lists"}