UNPKG

@serverless-rewrite/serverless

Version:

Serverless Framework - Build web, mobile and IoT applications with serverless architectures using AWS Lambda, Azure Functions, Google CloudFunctions & more

22 lines (16 loc) 438 B
'use strict'; const _ = require('lodash'); const deepSortObjectByKey = (obj) => { if (Array.isArray(obj)) { return obj.map(deepSortObjectByKey); } if (_.isPlainObject(obj)) { return _.fromPairs( Object.entries(obj) .sort(([key], [otherKey]) => key.localeCompare(otherKey)) .map(([key, value]) => [key, deepSortObjectByKey(value)]) ); } return obj; }; module.exports = deepSortObjectByKey;