The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | function isRecord(value: unknown): value is Record<string, unknown> { |
| 2 | return typeof value === "object" && value !== null && !Array.isArray(value); |
| 3 | } |
| 4 | |
| 5 | export function stableStringify(value: unknown): string { |
| 6 | if (Array.isArray(value)) { |
| 7 | return `[${value.map(stableStringify).join(",")}]`; |
| 8 | } |
| 9 | if (isRecord(value)) { |
| 10 | return `{${Object.entries(value) |
| 11 | .filter(([, entryValue]) => entryValue !== undefined) |
| 12 | // Code-unit order, not localeCompare: signatures and RFC 7638 thumbprints |
| 13 | // must match across machines whatever their OS locale. |
| 14 | .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0)) |
| 15 | .map(([key, entryValue]) => `${JSON.stringify(key)}:${stableStringify(entryValue)}`) |
| 16 | .join(",")}}`; |
| 17 | } |
| 18 | return JSON.stringify(value) ?? "null"; |
| 19 | } |