import { PropertyName } from "../types/global.js"; //#region src/modules/array.d.ts /** * 函数“range”返回一个数字数组,该数组从给定的起始值开始,按给定的步长值递增,并以给定的结束值结束(可选)。 * @param start - start 参数是范围的起始值 * @param end - "end"参数是一个可选参数,用于指定范围的结束值。如果未提供,则范围将是\[0,start)。 * @param step - "step"参数是一个可选参数,用于指定范围内每个值之间的增量。如果未提供,则默认为 1。 * @returns \[start,end)范围的,按照step步长的整数组成的数组 * @example * ```ts * console.log(range(1,3)) * // print \[1,2\] * ``` * @public */ declare function range(start: number, end?: number, step?: number): number[]; /** * 函数“range”返回一个数字数组,该数组从给定的起始值开始,按给定的步长值递增,并以给定的结束值结束(可选)。 * @param start - start 参数是范围的起始值 * @param end - "end"参数是一个可选参数,用于指定范围的结束值。如果未提供,则范围将是\[0,start)。 * @param step - "step"参数是一个可选参数,用于指定范围内每个值之间的增量。如果未提供,则默认为 1。 * @returns \[start,end)范围的,按照step步长的整数生成器。 * @example * ```ts * for (const num of rangeIter(1,8))\{ * console.log(num) * \} * ``` * @public */ declare function rangeIter(start: number, end?: number, step?: number): Generator; /** * 过滤器函数类型 * @public */ type Filter = (item: T) => boolean; /** * @public */ declare class Query extends Array { private filters; private sortKeys; private groupByKey; constructor(list: T[]); where(filter: Filter): Query; sortBy(key: keyof T): Query; groupBy(key: keyof T): Query; execute(): any; } /** * @public */ declare function createQuery(list: T[]): Query; /** * @public */ type SortDirection = 'asc' | 'desc' | 'none'; /** * @public */ type CompareFunction = (a: T, b: T) => number; /** * sort策略是 a-b的逻辑,如果返回负数比如-1,说明递增,或者a\>b * @public */ declare const sortStrategies: { defaultAsc: (a: T, b: T) => number; defaultDesc: (a: T, b: T) => number; }; /** * 判断已排序数组的排序方向,必须传入排序好的数组 * @param sortedArr - 已排序的数组 * @param compareFn - 类似sort方法的参数,返回负数说明升序,即b\>a,返回0 b=a,返回正数说明降序,即a\>b * @returns 排序方向 * @public */ declare function getSortDirection(sortedArr: T[], compareFn?: CompareFunction): SortDirection; /** * Sort an array without modifying it and return * the newly sorted value. Allows for a string * sorting value. * @public */ declare const alphabetical: (array: readonly T[], getter: (item: T) => string, dir?: "asc" | "desc") => T[]; /** * Go through a list of items, starting with the first item, * and comparing with the second. Keep the one you want then * compare that to the next item in the list with the same * * Ex. const greatest = () =\> boil(numbers, (a, b) =\> a \> b) * @public */ declare const boil: (array: readonly T[], compareFunc: (a: T, b: T) => T) => T | null; /** * Splits a single list into many lists of the desired size. If * given a list of 10 items and a size of 2, it will return 5 * lists with 2 items each * @public */ declare const chunk: (list: readonly T[], size?: number) => T[][]; /** * 计数,根据生成的key值来统计 * @param list - 要统计的数组 * @param identity - 生成key的函数 * @returns 统计结果对象 * @public */ declare const countBy: (list: readonly T[], identity: (item: T) => TId) => Record; /** * Returns all items from the first list that * do not exist in the second list. * @public */ declare const diff: (root: readonly T[], other: readonly T[], identity?: (item: T) => string | number | symbol) => T[]; /** * Get the first item in an array or a default value * @public */ declare const first: (array: readonly T[], defaultValue?: T | null | undefined) => T | null | undefined; /** * Get the last item in an array or a default value * @public */ declare const last: (array: readonly T[], defaultValue?: T | null | undefined) => T | null | undefined; /** * Split an array into two array based on * a true/false condition function * @public */ declare const fork: (list: readonly T[], condition: (item: T) => boolean) => [T[], T[]]; /** * Given two arrays, returns true if any * elements intersect * @public */ declare const hasIntersects: (listA: readonly T[], listB: readonly T[], identity?: (t: T) => K) => boolean; /** * Max gets the greatest value from a list * * @example * max([ 2, 3, 5]) == 5 * max([\{ num: 1 \}, \{ num: 2 \}], x =\> x.num) == \{ num: 2 \} * @public */ declare function max(array: readonly [number, ...number[]]): number; /** * @public */ declare function max(array: readonly number[]): number | null; /** * @public */ declare function max(array: readonly T[], getter: (item: T) => number): T | null; /** * Min gets the smallest value from a list * * @example * min([1, 2, 3, 4]) == 1 * min([\{ num: 1 \}, \{ num: 2 \}], x =\> x.num) == \{ num: 1 \} * @public */ declare function min(array: readonly [number, ...number[]]): number; /** * @public */ declare function min(array: readonly number[]): number | null; /** * @public */ declare function min(array: readonly T[], getter: (item: T) => number): T | null; /** * If the item matching the condition already exists * in the list it will be removed. If it does not it * will be added. * @public */ declare const toggle: (list: readonly T[], item: T, /** * Converts an item of type T item into a value that * can be checked for equality */ toKey?: null | ((item: T, idx: number) => number | string | symbol), options?: { strategy?: "prepend" | "append"; }) => T[]; /** * Sum all numbers in an array. Optionally provide a function * to convert objects in the array to number values. * @public */ declare function sum(array: readonly T[]): number; /** * @public */ declare function sum(array: readonly T[], fn: (item: T) => number): number; /** * Creates an object mapping the specified keys to their corresponding values * * Ex. const zipped = zipToObject(['a', 'b'], [1, 2]) // \{ a: 1, b: 2 \} * Ex. const zipped = zipToObject(['a', 'b'], (k, i) =\> k + i) // \{ a: 'a0', b: 'b1' \} * Ex. const zipped = zipToObject(['a', 'b'], 1) // \{ a: 1, b: 1 \} * @public */ declare function zipObject(keys: K[], values: V | ((key: K, idx: number) => V) | V[]): Record; /** * Creates an array of grouped elements, the first of which contains the * first elements of the given arrays, the second of which contains the * second elements of the given arrays, and so on. * * Ex. const zipped = zip(['a', 'b'], [1, 2], [true, false]) // [['a', 1, true], ['b', 2, false]] * @public */ declare function zip(array1: T1[], array2: T2[], array3: T3[], array4: T4[], array5: T5[]): [T1, T2, T3, T4, T5][]; /** * @public */ declare function zip(array1: T1[], array2: T2[], array3: T3[], array4: T4[]): [T1, T2, T3, T4][]; /** * @public */ declare function zip(array1: T1[], array2: T2[], array3: T3[]): [T1, T2, T3][]; /** * @public */ declare function zip(array1: T1[], array2: T2[]): [T1, T2][]; /** * Given a list of items returns a new list with only * unique items. Accepts an optional identity function * to convert each item in the list to a comparable identity * value * @public */ declare const unique: (array: readonly T[], toKey?: (item: T) => K) => T[]; /** * Randomly shuffle an array * @public */ declare const shuffle: (array: readonly T[]) => T[]; /** * 根据条件决定是否包含某个值。 * 当 condition 为 true 时返回数组形式的值;当 condition 为 false 时返回空数组。 * 若传入的 value 已经是数组,则原样返回;否则会将单值包装为数组。 * @typeParam T - 值的元素类型 * @param condition - 条件布尔值,true 时包含,false 时返回空数组 * @param value - 单个值或值数组 * @returns 返回一个数组:满足条件则包含对应的值或数组,否则为空数组 * @example * ```ts * includeIf(true, 1) // [1] * includeIf(true, [1, 2]) // [1, 2] * includeIf(false, 1) // [] * ``` * @throws 不会抛出错误 * @public */ declare function includeIf(condition: boolean, value: T | T[]): T[]; //#endregion export { type CompareFunction, Filter, Query, type SortDirection, alphabetical, boil, chunk, countBy, createQuery, diff, first, fork, getSortDirection, hasIntersects, includeIf, last, max, min, range, rangeIter, shuffle, sortStrategies, sum, toggle, unique, zip, zipObject };