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

feat(castComparator): accept an array of mapping values for fallback comparisons #151

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

aleclarson
Copy link
Member

@aleclarson aleclarson commented Aug 1, 2024

Tip

The owner of this PR can publish a preview release by commenting /publish in this PR. Afterwards, anyone can try it out by running pnpm add radashi@pr<PR_NUMBER>.

Summary

Allow castComparator to receive an array of mapping values.

/**
 * Example usage of castComparator with an array of mappings for fallback comparisons
 */
const sortPeople = castComparator([
  'lastName',
  'firstName',
  person => person.birthDate.getTime()
]);

const people = [
  { firstName: 'John', lastName: 'Doe', birthDate: new Date(1990, 5, 15) },
  { firstName: 'Jane', lastName: 'Doe', birthDate: new Date(1992, 8, 20) },
  { firstName: 'Alice', lastName: 'Smith', birthDate: new Date(1985, 2, 10) }
];

const sortedPeople = people.sort(sortPeople);
// Result:
// [
//   { firstName: 'Jane', lastName: 'Doe', birthDate: Date(1992-09-20) },
//   { firstName: 'John', lastName: 'Doe', birthDate: Date(1990-06-15) },
//   { firstName: 'Alice', lastName: 'Smith', birthDate: Date(1985-03-10) }
// ]

Related issue, if any:

For any code change,

  • Related documentation has been updated, if needed
  • Related tests have been added or updated, if needed
  • Related benchmarks have been added or updated, if needed

Does this PR introduce a breaking change?

No

Bundle impact

Status File Size Difference (%)
M src/function/castComparator.ts 463 1 +237 (+104%)

Footnotes

  1. Function size includes the import dependencies of the function.

@aleclarson aleclarson added the new feature This PR adds a new function or extends an existing one label Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature This PR adds a new function or extends an existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant