Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
deep-sort-object: preserve array order in package.json
Browse files Browse the repository at this point in the history
Fixes: #10063
PR-URL: #10185
Credit: @substack
Reviewed-By: @iarna
  • Loading branch information
James Halliday authored and iarna committed Jan 27, 2016
1 parent 82be147 commit bbdc700
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/utils/deep-sort-object.js
Expand Up @@ -3,7 +3,11 @@ var sortedObject = require('sorted-object')

module.exports = function deepSortObject (obj, sortBy) {
if (obj == null || typeof obj !== 'object') return obj
if (obj instanceof Array) return obj.sort(sortBy)
if (obj instanceof Array) {
return obj.map(function (x) {
return deepSortObject(x, sortBy)
})
}
obj = sortedObject(obj)
Object.keys(obj).forEach(function (key) {
obj[key] = deepSortObject(obj[key], sortBy)
Expand Down

0 comments on commit bbdc700

Please sign in to comment.