* Recursively sorts object keys lexicographically. * This is crucial for deterministic JSON.stringify in JavaScript. * @param obj The object to sort. * @returns A new object with sorted keys, or the original value if not an object.
(obj: SortableValue)
| 17 | * @returns A new object with sorted keys, or the original value if not an object. |
| 18 | */ |
| 19 | function sortObject(obj: SortableValue): SortableValue { |
| 20 | if (obj === undefined || obj === null) { |
| 21 | return obj; |
| 22 | } |
| 23 | if (Array.isArray(obj)) { |
| 24 | return obj.map(sortObject); |
| 25 | } else if (obj && typeof obj === "object" && obj.constructor === Object) { |
| 26 | return Object.keys(obj) |
| 27 | .sort() |
| 28 | .reduce((result: SortableObject, key) => { |
| 29 | const value = (obj as SortableObject)[key]; |
| 30 | result[key] = sortObject(value); |
| 31 | return result; |
| 32 | }, {}); |
| 33 | } |
| 34 | return obj; |
| 35 | } |
| 36 | |
| 37 | export type KeyProviderKind = "none" | "kms" | "local" | "tpm"; |
| 38 |
no outgoing calls
no test coverage detected