-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat: add sort
shorthand for sorting by property name
#36
base: main
Are you sure you want to change the base?
Conversation
bfb2542
to
cbb3fab
Compare
cbb3fab
to
67a6fc2
Compare
|
||
export type Comparable = | ||
| number | ||
| string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if leftValue > rightValue ? 1 : leftValue < rightValue ? -1 : 0
is a good comparator for strings. We can use localCompare
or not provide a default comparator for strings at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default comparator is intended to be both minimal and flexible (support comparing any two Comparable
values). If only strings are being compared, the caller can opt-in to localeCompare
like alphabetical
is doing.
I suppose we could include a warning about this behavior in the function's description.
: by !== undefined | ||
? (arg: T) => arg[by as keyof T] as U | ||
: (arg: T) => arg as unknown as U |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible to use undefined
as an object key. Yes, such code is very weird, but it's still possible. So returning identity function here could be a surprising behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we could document this behavior.
Property names are assumed to be strings, numbers, or symbols.
35fc67a
to
04bad7b
Compare
2154f96
to
6a4b4f6
Compare
Tip
The owner of this PR can publish a preview release by commenting
/publish
in this PR. Afterwards, anyone can try it out by runningpnpm add radashi@pr<PR_NUMBER>
.Description
The property name may be a string, number, or symbol.
This PR will affect the following functions:
sort
alphabetical
min
max
Depends on #34, #35, #43
Checklist
/docs
directory) has been updatedResolves