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

fix: use Intl.Collator for string sorting when available #3809

Merged
merged 1 commit into from
Sep 28, 2021

Conversation

isaacs
Copy link
Contributor

@isaacs isaacs commented Sep 28, 2021

The npm/cli form of npm/arborist#324

Required adding options support to package used for this.

References

@isaacs isaacs requested a review from wraithgar September 28, 2021 18:18
@isaacs isaacs requested a review from a team as a code owner September 28, 2021 18:18
@isaacs isaacs force-pushed the isaacs/string-locale-compare branch from 0c7fb02 to 1578490 Compare September 28, 2021 18:20
lib/outdated.js Outdated
@@ -85,7 +86,7 @@ class Outdated extends ArboristWorkspaceCmd {
}))

// sorts list alphabetically
const outdated = this.list.sort((a, b) => a.name.localeCompare(b.name, 'en'))
const outdated = this.list.sort(({ name: a }, { name: b }) => localeCompare(a, b)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const outdated = this.list.sort(({ name: a }, { name: b }) => localeCompare(a, b)
const outdated = this.list.sort(({ name: a }, { name: b }) => localeCompare(a, b))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha, fixed that one locally, but neglected to add it to my amended commit. Thanks.

@isaacs isaacs force-pushed the isaacs/string-locale-compare branch 2 times, most recently from 351b2fb to 7b0cd12 Compare September 28, 2021 18:42
@@ -15,8 +16,7 @@ const installedDeep = async (npm) => {
return i
})
.filter(i => (i.depth - 1) <= depth)
.sort((a, b) => a.depth - b.depth)
.sort((a, b) => a.depth === b.depth ? a.name.localeCompare(b.name, 'en') : 0)
.sort((a, b) => (a.depth - b.depth) || localeCompare(a.name, b.name))
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

@wraithgar wraithgar left a comment

Choose a reason for hiding this comment

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

Bonus! Lots of little improvements to all these sort functions.

The npm/cli form of npm/arborist#324

Required adding options support to package used for this.

PR-URL: #3809
Credit: @isaacs
Close: #3809
Reviewed-by: @wraithgar
@isaacs isaacs force-pushed the isaacs/string-locale-compare branch from 7b0cd12 to dbb90f7 Compare September 28, 2021 18:52
@isaacs isaacs merged commit dbb90f7 into release-next Sep 28, 2021
@isaacs
Copy link
Contributor Author

isaacs commented Sep 28, 2021

Bonus! Lots of little improvements to all these sort functions.

Yeah, that double-sort on installedDeep was a bit of a head-scratcher.

This was referenced Sep 30, 2021
@nlf nlf deleted the isaacs/string-locale-compare branch March 28, 2022 17:02
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.

2 participants