UNPKG

@bitbite/filtered-list

Version:

filter a list of items

46 lines (37 loc) 1.31 kB
type Assertion<T> = (item: T) => boolean type Operator = <T>(...assertions: Assertion<T>[]) => Assertion<T> declare module '@bitbite/filtered-list' { /** * Filtered list constructor */ export class FilteredList<T> { public filtered: Array<T> constructor(list: Array<T>); /** * Assertions can be optionally combined with logical operator * @param assertions an assertion function to find a match */ assert(...assertions: Assertion<T>[]): Array<T> } /** * Memoize a function to improve performance * @param fn a function to be memoized * @param onMemoized a function to be called on memoized value */ export function Memoized(fn: Function, onMemoized?: Function): Function /** * And logical operator * Will return true if all assertions is true */ export function And<T>(...assertions: Assertion<T>[]): Assertion<T> /** * Or logical operator * Will return true if one of the assertions is true */ export function Or<T>(...assertions: Assertion<T>[]): Assertion<T> /** * Not logical opertator * Will return true if all of the assertions is false */ export function Not<T>(...assertions: Assertion<T>[]): Assertion<T> }