@utilityjs/comparator
v1.0.1
Published
A utility class that compares its comparable arguments.
Downloads
3
Maintainers
Readme
A utility class that compares its comparable arguments.
npm i @utilityjs/comparator | yarn add @utilityjs/comparator
Usage
interface Item {
type: string;
value: number;
}
const comparator = new Comparator((a, b) => {
if (a.value === b.value) return 0;
return a.value < b.value ? -1 : 1;
});
// TRUE
comparator.isEqual({ type: "a", value: 0}, { type: "b", value: 0});
API
Comparator(compareFunction?)
declare type CompareFunction<T> = (a: T, b: T) => -1 | 0 | 1;
declare class Comparator<T> {
private compare;
static defaultComparatorFunction: <U>(a: U, b: U) => -1 | 0 | 1;
constructor(compareFunction?: CompareFunction<T>);
isEqual(a: T, b: T): boolean;
isLessThan(a: T, b: T): boolean;
isLessThanOrEqual(a: T, b: T): boolean;
isGreaterThan(a: T, b: T): boolean;
isGreaterThanOrEqual(a: T, b: T): boolean;
}