mirror of
https://github.com/nodejs/node.git
synced 2025-05-13 19:50:17 +00:00

PR-URL: https://github.com/nodejs/node/pull/5369 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
17 lines
424 B
JavaScript
17 lines
424 B
JavaScript
'use strict'
|
|
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.map(function (x) {
|
|
return deepSortObject(x, sortBy)
|
|
})
|
|
}
|
|
obj = sortedObject(obj)
|
|
Object.keys(obj).forEach(function (key) {
|
|
obj[key] = deepSortObject(obj[key], sortBy)
|
|
})
|
|
return obj
|
|
}
|