Type-safe comparator functions for Array.sort() operations with advanced
field access.
GaffComparator provides a collection of specialized comparator functions
designed to work seamlessly with Array.sort() and testing frameworks like
TestValidator.sort(). Each comparator supports both single values and arrays
of values, enabling complex multi-field sorting scenarios with lexicographic
ordering.
Key features:
Generic type safety for any object structure
Support for single values or arrays of values per field
Lexicographic comparison for multi-value scenarios
Locale-aware string comparison
Automatic type conversion for dates and numbers
The comparators follow the standard JavaScript sort contract:
Return < 0 if first element should come before second
Return > 0 if first element should come after second
// Basic usage with single fields users.sort(GaffComparator.strings(user=>user.name)); posts.sort(GaffComparator.dates(post=>post.createdAt)); products.sort(GaffComparator.numbers(product=>product.price));
Type-safe comparator functions for Array.sort() operations with advanced field access.
GaffComparator provides a collection of specialized comparator functions designed to work seamlessly with Array.sort() and testing frameworks like TestValidator.sort(). Each comparator supports both single values and arrays of values, enabling complex multi-field sorting scenarios with lexicographic ordering.
Key features:
The comparators follow the standard JavaScript sort contract:
Author
Jeongho Nam - https://github.com/samchon
Example