UNPKG

@stnekroman/tstools

Version:

Set of handy tools for TypeScript development

25 lines (24 loc) 1.11 kB
import { Functions } from './Functions'; import { Types } from './Types'; export type SortableType = string | number | Date | boolean; export declare class Sorter<T> { static readonly COMPARATORS: { readonly number: (a: number, b: number) => number; readonly string: (a: string, b: string, stringCompareOptions?: Intl.CollatorOptions) => number; readonly boolean: (a: boolean, b: boolean) => 0 | 1 | -1; readonly Date: (a: Date, b: Date) => number; readonly null: (a: SortableType, b: SortableType) => 0 | 1 | -1; }; private _nullsLast; private _stringCollatorOptions?; private _inverse; private readonly extractor; static byField<T>(fieldname: keyof T & Types.KeysWithValsOfType<T, SortableType>): Sorter<T>; static byExtractor<T>(extractor: Functions.MapFunction<T, SortableType>): Sorter<T>; private constructor(); nullsLast(value: boolean): this; inverse(): this; stringCollatorOptions(value: Intl.CollatorOptions): this; build(nextSort?: Functions.Comparator<T>): Functions.Comparator<T>; private compareValues; }