collection/sortBy.js

  1. import { sortBy as _sortBy } from 'lodash'
  2. import { convert } from 'immutadot'
  3. /**
  4. * Replaces by an array of sorted by <code>iteratees</code>.
  5. * @function
  6. * @memberof collection
  7. * @param {Object} object The object to modify.
  8. * @param {Array|string} path The path of the property to set.
  9. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[{@link https://lodash.com/docs#identity|lodash.identity}]] The iteratees to sort by.
  10. * @return {Object} Returns the updated object.
  11. * @see {@link https://lodash.com/docs#sortBy|lodash.sortBy} for more information.
  12. * @example
  13. * sortBy({ nested: { prop: [{ name: 'Yvo', age: 2 }, { name: 'Nico', age: 666 }, { name: 'Nico', age: 30 }] } }, 'nested.prop', ['name', 'age'])
  14. * // => { nested: { prop: [{ name: 'Nico', age: 30 }, { name: 'Nico', age: 666 }, { name: 'Yvo', age: 2 }] } }
  15. * @since 1.0.0
  16. */
  17. const sortBy = convert(_sortBy)
  18. export { sortBy }