UNPKG

@arrows/array

Version:
47 lines (46 loc) 1.79 kB
declare type CompareFn<V> = (a: V, b: V) => number; declare type MappingFn<T, V> = (element: T) => V; declare type Curry1<T> = (arr: T[]) => T[]; declare type Curry2<T, V> = { (mappingFn: MappingFn<T, V>): Curry1<T>; (mappingFn: MappingFn<T, V>, arr: T[]): T[]; }; declare type Curry3 = { <T, V>(compareFn: CompareFn<V>): Curry2<T, V>; <T, V>(compareFn: CompareFn<V>, mappingFn: MappingFn<T, V>): Curry1<T>; }; declare type _SortBy_ = <T, V>(compareFn: CompareFn<V>, mappingFn: MappingFn<T, V>, arr: T[]) => T[]; declare type CurriedSortBy_ = _SortBy_ & Curry3; declare type PartiallyApplied = { <T, V>(mappingFn: MappingFn<T, V>): Curry1<T>; <T, V>(mappingFn: MappingFn<T, V>, arr: T[]): T[]; }; declare type SortBy_ = CurriedSortBy_ & { num: PartiallyApplied; numDesc: PartiallyApplied; str: PartiallyApplied; strDesc: PartiallyApplied; locale: PartiallyApplied; localeDesc: PartiallyApplied; }; /** * Creates a new, sorted array. * Accepts mapping function that maps values before comparing * (mapping does not affect actual values of the array). * Have built-in methods for sorting numerical and alphabetical sorting. * * @param compareFn Compare function * @param mappingFn Mapping function * @param arr Initial array * @returns New array * * @method num Sorts numerical arrays in an ascending order * @method numDesc Sorts numerical arrays in a descending order * @method str Sorts string arrays in an ascending order * @method strDesc Sorts string arrays in a descending order * @method locale Sorts string arrays in an ascending order using localeCompare * @method localeDesc Sorts string arrays in a descending order using localeCompare */ declare const sortBy_: SortBy_; export { sortBy_ }; export default sortBy_;