sls3-legacy
Version:
SLS3 Legacy - A fork of Serverless Framework v3
22 lines (16 loc) • 466 B
JavaScript
;
const _ = require('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;
};
module.exports = deepSortObjectByKey;