/** * Collection CLASS */ export declare enum CONSTANT_OPTIONS { ck_diacritical = 1, ck_descending = 2, ck_ascending = 3, ck_keep_null = 4 } declare type TEvery = { (methodName: Function, ...params: any[]): boolean; (startFrom: number, methodName: Function, ...params: any[]): boolean; }; declare type TFind = { (methodName: Function, ...params: any[]): boolean; (startFrom: number, methodName: Function, ...params: any[]): boolean; }; declare type TFindIndex = { (methodName: Function, ...params: any[]): number; (startFrom: number, methodName: Function, ...params: any[]): number; }; declare type TOrderBy = string | Collection | number; declare class Collection { collection: Array; constructor(...params: undefined[]); /** * init the collection based on constructor params */ init: (params: any[]) => void; /** * Add list of element to the collection. * @param {...any} params */ push: (...params: (any | null)[]) => this; /** * calculate the arithmetic mean of the collection, Only numerical elements are taken into account for the calculation * @returns number */ average: () => number; /** * clear the collection */ clear: () => this; /** * Inserts col2 elements at the end or at the specified index position in the collection instance and returns the edited collection. */ combine: (col: any, index?: any) => any[]; /** * contcat param(s) elements to the collection. * @param {...any} params */ concat: (...params: any[]) => any[]; /** * return a deep compy of the collection. */ copy: () => any[]; /** * Returns the number of non-null elements in the collection. * @returns number */ count: () => number; /** * * @param {*} value * @param {*} startFrom * @param {*} end * @returns */ fill: (value: any, startFrom?: number | undefined, end?: number | undefined) => any[]; /** * Return the length of the collection. * @returns Array */ get length(): number; map: (cbMap: (arg0: { value: any; stop: boolean; result: null; }, arg1: any[]) => void, ...params: any[]) => Collection; getOptionHandler: (option: CONSTANT_OPTIONS) => ((sObject: any, sOther: any) => boolean) | null; /** * Test if two collection are equal * @param {*} col * @param {*} option * @returns */ equal: (col: any, option?: any) => boolean; /** * Search a element in a collection. * @param {*} toSearch * @param {*} startFrom * @returns */ indexOf: (toSearch: any, startFrom?: any) => any; /** * get collection[index] * @param {*} index * @returns */ getElement: (index: number) => any; setElement: (index: number, value: any) => any[]; /** * The .pop() function removes the last element from the collection and returns it as the function result. */ pop: () => any; /** * The .sum() function returns the sum for all values in the collection instance. * Only numerical elements are taken into account for the calculation (other element types are ignored). * If the collection contains objects, pass the propertyPath parameter to indicate the object property to take into account. */ sum: (propertyPath?: string | undefined) => number; /** * The .slice() function returns a portion of a collection into a new collection, * selected from startFrom index to end index (end not included). * This function returns a shallow copy of the collection. If the original collection is a shared collection, the returned collection is also a shared collection. */ slice: (startFrom: number, end: number) => Collection | undefined; countValues: (value: any, propertyPath?: string | undefined) => number; /**col=[{firstName:"omar"},{firstName:"omar"}] * * @param option - diacritical option OR path for a attribute (propertyPath) */ distinct: (option?: string | number | undefined) => Collection; /** * The .extract() function creates and returns a new collection containing propertyPath values extracted from the original collection of objects. * * @param propertyPath - path to extract a value from Object * @param option * @returns */ extract: (propertyPath: string, option?: CONSTANT_OPTIONS | undefined) => Collection; /** * The .every() function returns true if all elements in the collection successfully passed a test implemented in the provided methodName method. * @param param1 * @param param2 * @param param3 * @returns */ every: TEvery; /** * The .filter() function returns a new collection containing all elements of the original collection for which methodName method result is true. * @param methodName - methode to use as comparator * @param params : params to passe to methodeName * @returns */ filter: (methodName: Function, ...params: any[]) => Collection; /** * The .find() function returns the first value in the collection for which methodName, applied on each element, returns true. */ find: TFind; /** * The .findIndex() function returns the index, in the collection, of the first value for which methodName, applied on each element, returns true. */ findIndex: TFindIndex; /** * The .insert() function inserts element at the specified index position in the collection instance and returns the edited collection. * @param index - index where you want to add your element * @param element - the element that you want to add. * @returns */ insert: (index: number, element: any) => Collection; /** * The .remove() function removes one or more element(s) from the specified index position in the collection and returns the edited collection. * @param index - Element at which to start removal * @param howMany - Number of elements to remove, or 1 element if omitted */ remove: (index: number, howMany?: number | undefined) => Collection; /** * The .resize() function sets the collection length to the specified new size and returns the resized collection. * @param size New size of the collection * @param defaultValue defaultValue to fill the collection. */ resize: (size: number, defaultValue?: any) => Collection; /** * The .reverse() function returns a deep copy of the collection with all its elements in reverse order. */ reverse: () => Collection; /** * The .shift() function removes the first element of the collection and returns it as the function result. */ shift: () => any; /** * The .unshift() function inserts the given value(s) at the beginning of the collection and returns the modified collection. * @param values - list of values to add. */ unshift: (...values: any[]) => this; /** * return the collection content * @returns array */ getCollection: () => any[]; /** * The query function searches for entities that meet the search criteria specified in queryString * @param queryString * @param rest * @returns */ query: (queryString: string, ...rest: any[]) => Collection; /** * The orderBy function returns a new collection containing all elements of the collection in the specified order. * @param path * @returns */ orderBy: (path?: TOrderBy | undefined) => Collection; /** * The .indices() function works exactly the same as the .query() function but returns indexes, * @param param - QuertString or a value * @returns */ indices: (param: string | any) => Collection; /** * The .join() function converts all elements of the collection to strings and concatenates them using the specified delimiter string as separator. * @param delimiter - string * @param options - * @returns */ join: (delimiter: string, options?: number | undefined) => string; max: (propertyPath?: string | undefined) => any; /** * The .min() function returns the element with the smallest value in the collection * @param propertyPath - string * @returns */ min: (propertyPath?: string | undefined) => any; /** * The .lastIndexOf() function searches the toSearch expression among collection elements and returns the index of the last occurrence, or -1 if it was not found. * @param toSearch * @param startFrom * @returns */ lastIndexOf: (toSearch: any, startFrom?: number | undefined) => number; /** * The .some() function returns true if at least one element in the collection match the comparator callback * @param startOrComparator - startFrom or Comparator * @param comparator - Comparator * @param params - Options to passe to the comparator */ some: (startOrComparator: number | Function, comparator?: ((e: any, param: any) => boolean) | undefined, params?: object | undefined) => boolean; /** * The .sort() function sorts the elements of the original collection and also returns the sorted collection . * @param comparator * @param extraParam * @returns */ sort: (comparator: (a: any, b: any, options?: object | undefined) => boolean, extraParam?: object | undefined) => Collection; /** * The .orderByMethod() function returns a new collection containing all elements of the collection in the order defined through the comparator callback * @param comparator * @param extraParams * @returns */ orderByMethod: (comparator: (a: any, b: any, options?: object | undefined) => boolean, extraParams?: any) => Collection; /** * The .reduce() function applies the comparator callback against an accumulator and each element in the collection (from left to right) to reduce it to a single value. * @param comparator - callback * @param initValue - initial value * @param params - parameters to passe to comparator callback * @returns */ reduce: (comparator: ($1: { accumulator: any; value: any; options?: object; }) => any, initValue?: any, params?: any) => any; toJSON(): any[]; } export default Collection;