/** * This is a function for use with JSON.stringify(input, sortedObjectKeys, number) * that ensures that object keys are sorted in alphanumerical order. */ export function sortedObjectKeys(_, data) { // Ignore primitives. if (data === null) return null; if (typeof data !== "object") return data; // Also ignore iterables, which are type "object" but should not be sorted. if (data.__proto__[Symbol.iterator]) return data; // Then sort the object keys and yield a new object with that // ordering enforced by key insertion. return Object.fromEntries(Object.entries(data).sort()); }