MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / sortObjectKeys

Function sortObjectKeys

sdk/js/src/get-compose-hash.browser.ts:18–28  ·  view source on GitHub ↗

* Recursively sorts object keys lexicographically. * @param obj - The object to sort * @returns A new object with sorted keys

(obj: SortableValue)

Source from the content-addressed store, hash-verified

16 * @returns A new object with sorted keys
17 */
18function sortObjectKeys(obj: SortableValue): SortableValue {
19 if (obj === null || obj === undefined) return obj;
20 if (typeof obj !== 'object') return obj;
21 if (Array.isArray(obj)) return obj.map(sortObjectKeys);
22
23 const sortedObj: SortableObject = {};
24 Object.keys(obj).sort().forEach(key => {
25 sortedObj[key] = sortObjectKeys((obj as SortableObject)[key]);
26 });
27 return sortedObj;
28}
29
30/**
31 * Browser-compatible SHA-256 hash using crypto-browserify

Callers 1

getComposeHashFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected