Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add findUpMultiple() method #56

Merged
merged 12 commits into from
Oct 7, 2021
Merged

Conversation

vast
Copy link
Contributor

@vast vast commented Sep 29, 2021

Fixes #27.

I'm a bit concerned about the amount of duplication in code: looks like findUp could be a decorated version of findUpMultiple. On the other hand, duplication is cheaper than wrong abstraction. What do you think?

P. S. PR looks huge. Let me know if that's a problem, I'll split it in multiple smaller PRs.


IssueHunt Summary

Referenced issues

This pull request has been submitted to:


@sindresorhus
Copy link
Owner

I would reduce the duplication.


For posterity, here's a diff:

Screen Shot 2021-10-04 at 15 25 19

@sindresorhus
Copy link
Owner

If findUpMultiple doesn't have any matches, it should return an empty array, not undefined.

index.d.ts Outdated

console.log(await findUpMultiple(async directory => {
const hasUnicorns = await pathExists(path.join(directory, 'unicorn.png'));
return hasUnicorns && directory;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use tab-indentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Fixed:
70242f5

@vast
Copy link
Contributor Author

vast commented Oct 5, 2021

If findUpMultiple doesn't have any matches, it should return an empty array, not undefined.

Thanks. Fixed:
1e4754e

@vast
Copy link
Contributor Author

vast commented Oct 5, 2021

I would reduce the duplication.

Done in:
1134d6d

I introduced limit parameter which is set to 1 ("stop when one path is found") in findUp and findUpSync.

What do you think?

index.d.ts Outdated
Find files or directories by walking up parent directories.

@param name - The name of the file or directory to find. Can be multiple.
@returns All paths found (by respecting the order of `name`s) or `undefined` if none could be found.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined is outdated.

index.js Outdated

export async function findUp(name, options = {}) {
const matches = await findUpMultiple(name, {...options, limit: 1});

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@vast vast requested a review from sindresorhus October 6, 2021 08:38
readme.md Outdated
### findUpMultiple(name, options?)
### findUpMultiple(matcher, options?)

Returns a `Promise` for either the array of paths or an empty array if it couldn't be found.
Copy link
Owner

@sindresorhus sindresorhus Oct 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "it" is correct here. This method is for finding multiple things. The index.d.ts description is correct though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Updated in:
6ee09a3

readme.md Outdated
### findUpMultiple(name, options?)
### findUpMultiple(matcher, options?)

Returns a `Promise` for either the array of paths or an empty array if it couldn't be found.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Returns a `Promise` for either the array of paths or an empty array if it couldn't be found.
Returns a `Promise` for either an array of paths or an empty array if it couldn't be found.

@vast vast requested a review from sindresorhus October 7, 2021 14:42
@sindresorhus sindresorhus changed the title Add findUpMultiple Add findUpMultiple() method Oct 7, 2021
@sindresorhus sindresorhus merged commit 8f80ac7 into sindresorhus:main Oct 7, 2021
@sindresorhus
Copy link
Owner

Thanks ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add findUpMultiple() method
2 participants