traefik/server/lib/sortedJson.mjs

23 lines
495 B
JavaScript
Raw Normal View History

2023-06-16 14:11:54 +00:00
export const stringify = (value, space = 0) => {
return JSON.stringify(value, replacer, space);
};
const replacer = (key, value) => {
if (
typeof value === 'object' &&
value !== null &&
!(value instanceof Array)
) {
return sortObject(value);
}
return value;
};
export const sortObject = (object) => {
const sortedObject = {};
for (const key of Object.keys(object).sort()) {
sortedObject[key] = object[key];
}
return sortedObject;
};