MSP-3203 create objectUtils

This commit is contained in:
veselovnk committed 2024-05-08 12:22:11 +03:00
1 parent 3ed8626c81
commit a8fb23b3d1
1 file changed
+19
+19
View File
@@ -0,0 +1,19 @@
const sortObject = (obj: any): any => {
if (typeof obj !== 'object' || obj === null) {
return obj
}
if (Array.isArray(obj)) {
return obj.map(sortObject)
}
const sorted: any = {}
Object.keys(obj)
.sort()
.forEach((key) => {
sorted[key] = sortObject(obj[key])
})
return sorted
}
export { sortObject }