MCPcopy Create free account
hub / github.com/DTStack/molecule / flatObject

Function flatObject

src/common/utils.ts:56–73  ·  view source on GitHub ↗
(target: object)

Source from the content-addressed store, hash-verified

54 * @param target flat target
55 */
56export function flatObject(target: object): object {
57 const flatted = {};
58 const recurse = (parent: string, target: object) => {
59 for (const prop in target) {
60 if (prop) {
61 const value = target[prop];
62 const path = parent ? `${parent}.${prop}` : prop;
63 if (typeof value === 'object') {
64 recurse(path, value);
65 } else {
66 flatted[path] = value;
67 }
68 }
69 }
70 };
71 recurse('', target);
72 return flatted;
73}
74
75/**
76 * It's converts a flatted object to a normal object,

Callers 1

flatObjectMethod · 0.90

Calls 1

recurseFunction · 0.85

Tested by

no test coverage detected