declarative-js
Version:
_declarative-js_ is modern JavaScript library, that helps to: - tackle array transformation with built in JavaScript array api (e.g. `array.filter(toBe.unique())`), - provide a type-level solution for representing optional values instead of null referen
107 lines (106 loc) • 4.83 kB
TypeScript
import { Getter, Predicate } from '../types';
/**
* Functions to be used in {@link Array.prototype.filter} as a callback.
* @see https://pavel-surinin.github.io/declarativejs/#/?id=filters
*/
export declare namespace toBe {
/**
* Function to be used in {@link Array.prototype.filter} as a callback.
* Filters out items that are not present ({@code undefined} and {@code null}) in array
*
* @returns {boolean}
* @see https://pavel-surinin.github.io/declarativejs/#/?id=tobepresent
*/
function present<T>(value: T): boolean;
/**
* Function to be used in {@link Array.prototype.filter} as a callback.
* Filters out items that are empty
*
* @returns {boolean}
* @see https://pavel-surinin.github.io/declarativejs/#/?id=tobenotempty
*/
function notEmpty<T>(value: T): boolean;
/**
* Function to be used in {@link Array.prototype.filter} as a callback.
* Filters out items, that are not equal to provided item in parameters.
* Objects are compared to be deep equal.
*
* @returns {function}
* @see https://pavel-surinin.github.io/declarativejs/#/?id=tobeequal
*/
function equal<T>(valueToMatch: T): (value: T) => boolean;
/**
* Function to be used in {@link Array.prototype.filter} as a callback.
* Filters out items, that are equal to provided item in parameters.
* Objects are compared to be deep equal.
*
* @returns {function}
* @see https://pavel-surinin.github.io/declarativejs/#/?id=tobenotequal
*/
function notEqual<T>(valueToMatch: T): (value: T) => boolean;
/**
* Function to be used in {@link Array.prototype.filter} as a callback.
* Determines uniqueness of an objects in array. Be aware that if value
* is not primitive, deep object equality will be checked to determine
* uniqueness.
*
* @returns () => {boolean}
* @see https://pavel-surinin.github.io/declarativejs/#/?id=tobeunique
*/
function unique(): <T>(value: T) => boolean;
/**
* Function to be used in {@link Array.prototype.filter} as a callback.
* Determines uniqueness by value from callback. This value must be
* comparable with strict equals
* @param { Function } getValue callback to resolve comparable value
* @see https://pavel-surinin.github.io/declarativejs/#/?id=tobeuniqueby
*/
function uniqueBy<T, R>(getValue: Getter<T, R>): (value: T, index: number, arr: T[]) => boolean;
/**
* Function to be used in {@link Array} filter function as a callback.
* Determines uniqueness by value resolved by objects key. This value must be
* comparable with strict equals
*
* @param { string } key objects key to resolve comparable value
* @see https://pavel-surinin.github.io/declarativejs/#/?id=tobeuniqueby
*/
function uniqueBy<T, K extends keyof T>(key: K): (value: T, index: number, arr: T[]) => boolean;
/**
* @deprecated use Filter object
*/
function takeWhile<T>(predicate: Predicate<T>): (value: T, index: number) => boolean;
}
/**
* Functions to be used in {@link Array.prototype.filter} as a callback.
* @see https://pavel-surinin.github.io/declarativejs/#/?id=filters
*/
export declare namespace Filter {
/**
* Function to be used in {@link Array} filter function as a callback.
* It will pass items from array, while predicate matches. When predicate
* returns {@code false} none of the items will pass.
*
* @param {function} predicate callback function that returns boolean
* @see https://pavel-surinin.github.io/declarativejs/#/?id=takewhile
* @deprecated use Filters object
*/
function takeWhile<T>(predicate: Predicate<T>): (value: T, index: number) => boolean;
/**
* Function to be used in {@link Array} filter function as a callback.
* It will skip items from array, while predicate matches. When predicate
* returns {@code false}, other items will be returned form that point.
*
* @param {function} predicate callback function that returns boolean
* @see https://pavel-surinin.github.io/declarativejs/#/?id=skipwhile
*/
function skipWhile<T>(predicate: Predicate<T>): (value: T, index: number) => boolean;
/**
* Skips an element, if predicate is resolving to false or
* an error occurred, predicate will also resolve to false.
* Error will be catched
* @param {function} predicate to filter elements
* @param {function} onError callback to be called on error occurred
* @see https://pavel-surinin.github.io/declarativejs/#/?id=skiponerror
*/
function skipOnError<T>(predicate: Predicate<T>, onError?: (error: Error, element: T, index: number) => void): (value: T, index: number) => boolean;
}