app-framework icon indicating copy to clipboard operation
app-framework copied to clipboard

window.sortObject() does not work in 1.19.4

Open scriptPilot opened this issue 7 years ago • 1 comments
trafficstars

scriptPilot avatar Jan 02 '18 18:01 scriptPilot

  /* Workaround for sortObject */

  import _toPairs from 'lodash/toPairs'
  import _sortBy from 'lodash/sortBy'
  import _fromPairs from 'lodash/fromPairs'
  sortObject = (obj, key, desc) => {
    desc = desc === true || desc === 'desc' || desc === 'DESC' ? true : false;
    const sortedArray = _sortBy(_toPairs(obj), el => el[1][key])
    if (desc) sortedArray.reverse()
    return _fromPairs(sortedArray)
  }

scriptPilot avatar Jan 02 '18 19:01 scriptPilot