forto-sorter
Version:
Fast and powerful array sorting. Sort by any property in any direction with easy to read syntax.
107 lines (106 loc) • 3.27 kB
TypeScript
import { ISortBy } from './types/sortBy';
import { ISortByObjectSorter } from './types/sortByObjectSorter';
import { ISortInstanceOptions } from './interfaces/sortInstanceOptions';
export declare const createNewSortInstance: (opts: ISortInstanceOptions) => <T>(_ctx: T[]) => {
/**
* Sort array in ascending order.
* @example
* sort([3, 1, 4]).asc();
* sort(users).asc(u => u.firstName);
* sort(users).asc([
* U => u.firstName
* u => u.lastName,
* ]);
*/
asc(sortBy?: ISortBy<T> | ISortBy<T>[]): T[];
/**
* Sort array in descending order.
* @example
* sort([3, 1, 4]).desc();
* sort(users).desc(u => u.firstName);
* sort(users).desc([
* U => u.firstName
* u => u.lastName,
* ]);
*/
desc(sortBy?: ISortBy<T> | ISortBy<T>[]): T[];
/**
* Sort array in ascending or descending order. It allows sorting on multiple props
* in different order for each of them.
* @example
* sort(users).by([
* { asc: u => u.score }
* { desc: u => u.age }
* ]);
*/
by(sortBy: ISortByObjectSorter<T> | ISortByObjectSorter<T>[]): T[];
};
export declare const sort: <T>(_ctx: T[]) => {
/**
* Sort array in ascending order.
* @example
* sort([3, 1, 4]).asc();
* sort(users).asc(u => u.firstName);
* sort(users).asc([
* U => u.firstName
* u => u.lastName,
* ]);
*/
asc(sortBy?: ISortBy<T> | ISortBy<T>[]): T[];
/**
* Sort array in descending order.
* @example
* sort([3, 1, 4]).desc();
* sort(users).desc(u => u.firstName);
* sort(users).desc([
* U => u.firstName
* u => u.lastName,
* ]);
*/
desc(sortBy?: ISortBy<T> | ISortBy<T>[]): T[];
/**
* Sort array in ascending or descending order. It allows sorting on multiple props
* in different order for each of them.
* @example
* sort(users).by([
* { asc: u => u.score }
* { desc: u => u.age }
* ]);
*/
by(sortBy: ISortByObjectSorter<T> | ISortByObjectSorter<T>[]): T[];
};
export declare const inPlaceSort: <T>(_ctx: T[]) => {
/**
* Sort array in ascending order.
* @example
* sort([3, 1, 4]).asc();
* sort(users).asc(u => u.firstName);
* sort(users).asc([
* U => u.firstName
* u => u.lastName,
* ]);
*/
asc(sortBy?: ISortBy<T> | ISortBy<T>[]): T[];
/**
* Sort array in descending order.
* @example
* sort([3, 1, 4]).desc();
* sort(users).desc(u => u.firstName);
* sort(users).desc([
* U => u.firstName
* u => u.lastName,
* ]);
*/
desc(sortBy?: ISortBy<T> | ISortBy<T>[]): T[];
/**
* Sort array in ascending or descending order. It allows sorting on multiple props
* in different order for each of them.
* @example
* sort(users).by([
* { asc: u => u.score }
* { desc: u => u.age }
* ]);
*/
by(sortBy: ISortByObjectSorter<T> | ISortByObjectSorter<T>[]): T[];
};
export declare const sortByAlgorithm: (algorithmName: any, list: any, compare: any) => void;