/* eslint-disable @typescript-eslint/no-magic-numbers */ import { sortByMultiple } from "./sortByMultiple.js"; /** * Returns a function that can be used as a callback to `.sort()` method. Returned function will sort array by given * property. * * @param propertyName - name of the property to sort by * @param asc - should sort be ascending? * @param defaultValue - value to use when property is not defined in one of the objects */ const sortBy = >( // eslint-disable-line @typescript-eslint/no-explicit-any propertyName: keyof T, asc = true, defaultValue: unknown = null, ) => (a: T, b: T): -1 | 0 | 1 => { // eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any return sortByMultiple([propertyName], asc, { [propertyName]: defaultValue } as Partial>)(a, b); }; export { sortBy, };