@datx/utils
Version:
DatX lib utils for mixins
46 lines (45 loc) • 2.42 kB
TypeScript
import { IResponseHeaders } from './interfaces/IResponseHeaders';
export declare function isArrayLike(value: any): value is Array<any>;
export declare function reducePrototypeChain<T, U>(obj: U, reduceFn: (state: T, item: U) => T, initialValue: T): T;
/**
* Map a single item or an array of items
*
* @export
* @template T
* @template U
* @param {(T|Array<T>)} data Data to iterate over
* @param {(item: T) => U} fn Function called for every data item
* @returns {(U|Array<U>|null)} Return value of the callback function
*/
export declare function mapItems<T, U>(data: Array<T>, fn: (item: T) => U): Array<U>;
export declare function mapItems<T, U>(data: T, fn: (item: T) => U): U | null;
export declare function getMetaObj(obj: Record<string, any>): Record<string, any>;
export declare function setMeta<T = any>(obj: Record<string, any>, key: string, value: T): void;
export declare function getMeta<T = any>(obj: Record<string, any>, key: string, defaultValue: T, includeChain?: boolean, mergeChain?: boolean): T;
export declare function getMeta<T = any>(obj: Record<string, any>, key: string, defaultValue?: T, includeChain?: boolean, mergeChain?: boolean): T | undefined;
export declare function mergeMeta(obj: Record<string, any>, newMeta: Record<string, any>): Record<string, any>;
declare type Getter<T> = () => T;
declare type Setter<T> = (value: T) => void;
/**
* Add a computed property to an object
*
* @export
* @param {Record<string, any>} obj object
* @param {string} key Property to add
* @param {() => any} getter Getter function
* @param {(value: any) => void} [setter] Setter function
*/
export declare function assignComputed<T = any>(obj: Record<string, any>, key: string, getter?: Getter<T>, setter?: Setter<T>): void;
export declare function error(...args: Array<any>): void;
export declare function warn(...args: Array<any>): void;
export declare function deprecated(...args: Array<any>): void;
export declare function info(...args: Array<any>): void;
export declare function replaceInArray<T = any>(arr: Array<T>, data: Array<T>): Array<T>;
export declare function removeFromArray<T = any>(arr: Array<T>, item: T): Array<T>;
export declare class Headers implements IResponseHeaders {
private readonly headers;
constructor(headers: Array<[string, string]>);
get(name: string): string | null;
forEach(cb: (value: string, key: string) => void): void;
}
export {};