* Deterministic JSON serialization following cross-language standards. * - Recursively sorts object keys lexicographically * - Compact output (no spaces) * - Handles special values (NaN, Infinity) by converting them to null * - UTF-8 encoding (default in JavaScript)
(dic: AppCompose)
| 89 | * - UTF-8 encoding (default in JavaScript) |
| 90 | */ |
| 91 | function toDeterministicJson(dic: AppCompose): string { |
| 92 | const ordered = sortObject(dic); |
| 93 | return JSON.stringify(ordered, (key, value) => { |
| 94 | // Convert NaN and Infinity to null for deterministic output |
| 95 | if (typeof value === 'number' && (isNaN(value) || !isFinite(value))) { |
| 96 | return null; |
| 97 | } |
| 98 | return value; |
| 99 | }); // Omit the 'space' argument for compact output |
| 100 | } |
| 101 | |
| 102 | export function getComposeHash(app_compose: AppCompose, normalize: boolean = false): string { |
| 103 | if (normalize) { |
no test coverage detected