The input value type
Sorted/normalized copy of the input
const obj = {
z: { nested: true, another: false },
a: [3, 1, 2],
date: new Date('2024-01-01')
};
const sorted = toSorted(obj);
// {
// a: [3, 1, 2],
// date: '2024-01-01T00:00:00.000Z',
// z: { another: false, nested: true }
// }
// Track value types
const types: string[] = [];
toSorted(obj, (value, type) => types.push(type));
// types: ['Key', 'Array', 'Number', ..., 'Date', ...]
Recursively sorts object keys and normalizes values for deterministic serialization.
Deep sorts all object keys alphabetically, converts Dates to ISO strings, symbols to strings, and recursively processes nested structures. Handles circular references by returning undefined for cycles. Optional callback tracks all values encountered during traversal.