fix(core): update
This commit is contained in:
18
ts/tools/toFlatObject.ts
Normal file
18
ts/tools/toFlatObject.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export const toFlatObject = (objectArg: object) => {
|
||||
const returnObject: {[key: string]: any} = {};
|
||||
const extractLayer = (subObject: {[key: string]: any}, pathArg: string, loopProtection: object[]) => {
|
||||
if (subObject)
|
||||
for (const key of Object.keys(subObject)) {
|
||||
let localPathArg = pathArg;
|
||||
if (typeof subObject[ key ] === 'object') {
|
||||
const newLoopbackArray = loopProtection.slice();
|
||||
newLoopbackArray.push(subObject);
|
||||
extractLayer(subObject[ key ], localPathArg ? localPathArg += `.${key}` : key, newLoopbackArray);
|
||||
} else {
|
||||
returnObject[localPathArg ? localPathArg += `.${key}` : key] = subObject[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
extractLayer(objectArg, '', []);
|
||||
return returnObject;
|
||||
}
|
||||
Reference in New Issue
Block a user