/** * 啟用 Array.prototype 的 Lodash 擴充方法 * 讓陣列可以直接使用 lodash 方法,如 `users._sortBy('age')._take(5)` * * 注意:此擴充只包含原生 Array 沒有的方法,避免重複: * - 原生已有:filter, map, find, findIndex, reverse, flat, flatMap, includes, every, some, reduce, reduceRight, forEach, slice, concat, join * - 此擴充提供:_sortBy, _orderBy, _uniq, _uniqBy, _groupBy, _keyBy, _take, _drop, _chunk, _compact, _flatten, _flattenDeep, _shuffle, _sampleSize, _difference, _intersection, _union, _pluck, _findLast, _sumBy, _meanBy, _maxBy, _minBy, _countBy, _partition, _first, _last, _nth, _sample * * @example * ```typescript * import { enableArrayExpand } from '@uofx/core'; * * // 在 app 初始化時呼叫一次 * enableArrayExpand(); * * // 之後可直接使用 * const result = [1, 2, 3, 4, 5] * .filter(x => x > 2) // 原生 filter * .map(x => x * 2) // 原生 map * ._take(2); // lodash take * * // 物件陣列 * const names = users * ._sortBy('age') * .filter(u => u.active) * ._pluck('name'); * ``` */ export declare function enableArrayExpand(): void; declare global { interface Array { /** Lodash sortBy - 排序 */ _sortBy(iteratees: ((value: T) => K) | keyof T | Array<((value: T) => K) | keyof T>): T[]; /** Lodash orderBy - 多欄位排序 */ _orderBy(iteratees: Array<((value: T) => K) | keyof T>, orders?: Array<'asc' | 'desc'>): T[]; /** Lodash uniq - 去除重複元素 */ _uniq(): T[]; /** Lodash uniqBy - 根據迭代器去除重複元素 */ _uniqBy(iteratee: ((value: T) => K) | keyof T): T[]; /** Lodash groupBy - 分組 */ _groupBy(iteratee: ((value: T) => K) | keyof T): Record; /** Lodash keyBy - 建立鍵值對物件 */ _keyBy(iteratee: ((value: T) => K) | keyof T): Record; /** Lodash take - 取得前 n 個元素 */ _take(n: number): T[]; /** Lodash takeRight - 取得後 n 個元素 */ _takeRight(n: number): T[]; /** Lodash drop - 跳過前 n 個元素 */ _drop(n: number): T[]; /** Lodash dropRight - 跳過後 n 個元素 */ _dropRight(n: number): T[]; /** Lodash chunk - 分割成指定大小的區塊 */ _chunk(size: number): T[][]; /** Lodash compact - 移除 falsy 值 */ _compact(): NonNullable[]; /** Lodash flatten - 攤平陣列一層 */ _flatten(): U[]; /** Lodash flattenDeep - 深度攤平陣列 */ _flattenDeep(): U[]; /** Lodash shuffle - 隨機打亂陣列 */ _shuffle(): T[]; /** Lodash sampleSize - 隨機取樣多個 */ _sampleSize(n: number): T[]; /** Lodash difference - 差集 */ _difference(...arrays: T[][]): T[]; /** Lodash differenceBy - 根據迭代器計算差集 */ _differenceBy(array: T[], iteratee: ((value: T) => K) | keyof T): T[]; /** Lodash intersection - 交集 */ _intersection(...arrays: T[][]): T[]; /** Lodash union - 聯集 */ _union(...arrays: T[][]): T[]; /** 根據屬性路徑提取值 */ _pluck(key: K): T[K][]; /** Lodash findLast - 尋找符合條件的最後一個元素 */ _findLast(predicate: (value: T, index: number, array: T[]) => boolean): T | undefined; /** Lodash sumBy - 根據迭代器計算總和 */ _sumBy(iteratee: ((value: T) => number) | keyof T): number; /** Lodash meanBy - 根據迭代器計算平均值 */ _meanBy(iteratee: ((value: T) => number) | keyof T): number; /** Lodash maxBy - 根據迭代器取得最大值 */ _maxBy(iteratee: ((value: T) => number) | keyof T): T | undefined; /** Lodash minBy - 根據迭代器取得最小值 */ _minBy(iteratee: ((value: T) => number) | keyof T): T | undefined; /** Lodash countBy - 計數 */ _countBy(iteratee?: ((value: T) => K) | keyof T): Record; /** Lodash partition - 根據條件分割成兩組 */ _partition(predicate: (value: T, index: number, array: T[]) => boolean): [T[], T[]]; /** Lodash first - 取得第一個元素 */ _first(): T | undefined; /** Lodash last - 取得最後一個元素 */ _last(): T | undefined; /** Lodash nth - 取得第 n 個元素 */ _nth(n: number): T | undefined; /** Lodash sample - 隨機取樣 */ _sample(): T | undefined; } }