Skip to content

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

Merged
isaacs merged 1 commit intorelease-nextfrom
isaacs/string-locale-compare
Sep 28, 2021
Merged

fix: use Intl.Collator for string sorting when available#3809
isaacs merged 1 commit intorelease-nextfrom
isaacs/string-locale-compare

Conversation

@isaacs
Copy link
Copy Markdown
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
Comment thread lib/outdated.js Outdated

// 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
Copy Markdown
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
Copy Markdown
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
.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
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

Copy link
Copy Markdown
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
Copy Markdown
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