mirror of
https://github.com/serverless/serverless.git
synced 2025-12-08 19:46:03 +00:00
20 lines
418 B
JavaScript
20 lines
418 B
JavaScript
import _ from 'lodash'
|
|
|
|
const deepSortObjectByKey = (obj) => {
|
|
if (Array.isArray(obj)) {
|
|
return obj.map(deepSortObjectByKey)
|
|
}
|
|
|
|
if (_.isPlainObject(obj)) {
|
|
return Object.fromEntries(
|
|
Object.entries(obj)
|
|
.sort(([key], [otherKey]) => key.localeCompare(otherKey))
|
|
.map(([key, value]) => [key, deepSortObjectByKey(value)]),
|
|
)
|
|
}
|
|
|
|
return obj
|
|
}
|
|
|
|
export default deepSortObjectByKey
|