import { CompareOrder } from './internals/compare'; import { ArrayLikeIterator, CollectionList, CollectionObject, Many, ObjectIterator, PropertyName } from './internals/types'; interface OrderBy { (collection: CollectionList, iteratee?: Many | keyof T>, orders?: Many): T[]; (collection: CollectionList, iteratee?: Many | PropertyName>, orders?: Many): T[]; (collection: CollectionObject, iteratee?: Many | keyof T>, orders?: Many): V[]; (collection: CollectionObject, iteratee?: Many, orders?: Many): V[]; } /** * 创建一个元素数组,以迭代函数处理的结果排序。如果没有指定排序,默认为升序排序。 * * `asc` 升序, `desc` 降序,默认执行稳定排序,也就是说相同元素会保持原始排序。 * * `iteratee` 调用时会传入三个参数 `value` `index|key` `collection`。 * * @function * @alias module:Collection.orderBy * @since 1.0.0 * @requires module:Collection.forEach * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/sort sort} * @param {ArrayLike | Object} collection 一个用来迭代的集合。 * @param {Function | string | number | Symbol | Array} [iteratees] 排序的迭代函数。 * @param {'asc' | 'desc' | Array} [orders] 迭代函数的排序顺序。 * @returns {Array} 排序后的新数组。 * @example * * const array = [2, 1, 3, 5, 4]; * * orderBy(array);; // [1, 2, 3, 4, 5] * * orderBy(array, item=>item, 'desc');; // [5, 4, 3, 2, 1] * * const objects = [ * { a: 'x', b: 3 }, * { a: 'y', b: 4 }, * { a: 'x', b: 1 }, * { a: 'y', b: 2 } * ]; * * orderBy(objects, 'b'); * // [{ a: 'x', b: 1 },{ a: 'y', b: 2 },{ a: 'x', b: 3 },{ a: 'y', b: 4 }] * * // 迭代函数可以直接写入属性。 * orderBy(objects, ['a', 'b'], ['asc', 'desc']); * // [{ a: 'x', b: 3 },{ a: 'x', b: 1 },{ a: 'y', b: 4 },{ a: 'y', b: 2 }] * */ declare const orderBy: OrderBy; export default orderBy;