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

Some functions from Lodash can be replaced with native ones #2848

Closed
live627 opened this issue Sep 27, 2021 · 2 comments · Fixed by #2851
Closed

Some functions from Lodash can be replaced with native ones #2848

live627 opened this issue Sep 27, 2021 · 2 comments · Fixed by #2851

Comments

@live627
Copy link
Contributor

live627 commented Sep 27, 2021

For example, lodash/flatten can be replaced with Array.prototype.flat() and even combined with Array.prototype.map() by using Array.prototype.flatMap().

Example:

ava/lib/line-numbers.js

Lines 52 to 58 in e8a4976

export function getApplicableLineNumbers(normalizedFilePath, filter) {
return sortNumbersAscending(distinctArray(flatten(
filter
.filter(({pattern, lineNumbers}) => lineNumbers && picomatch.isMatch(normalizedFilePath, pattern))
.map(({lineNumbers}) => lineNumbers),
)));
}

 export function getApplicableLineNumbers(normalizedFilePath, filter) {
-	return sortNumbersAscending(distinctArray(flatten(
+	return sortNumbersAscending(distinctArray(
 		filter
 			.filter(({pattern, lineNumbers}) => lineNumbers && picomatch.isMatch(normalizedFilePath, pattern))
-			.map(({lineNumbers}) => lineNumbers),
-	)));
+			.flatMap(({lineNumbers}) => lineNumbers),
+	));
 }

Would this be something that is of interest? Eventually being able to remove Lodash would save ~1.3 MB (over 2.2 MB on my disk)

Here's a good resource

@novemberborn
Copy link
Member

Yes that'd be great.

@live627
Copy link
Contributor Author

live627 commented Sep 28, 2021

That's good to hear . I wasn't sure of the reaction especially after seeing this comment and how it was closed for being "too controversial", whatever that means. Maybe it was the aggressive attitude. Anyway, I agree with the sentiment that this packages should have a smaller footprint and less dependencies if at all possible.

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 a pull request may close this issue.

2 participants