File tree Expand file tree Collapse file tree 1 file changed +4
-11
lines changed
Expand file tree Collapse file tree 1 file changed +4
-11
lines changed Original file line number Diff line number Diff line change @@ -10,24 +10,17 @@ const logger: Logger = new Logger(`json.utils:`, config.logLevel);
1010 * Flattens objects with nested properties for data view display.
1111 * @param obj Object to flatten.
1212 * @param preservePath Optional flag for generating key path.
13- * @param parentPath Parent key path.
1413 * @returns Flat Object.
1514 */
16- export function flattenObject ( obj : any , preservePath : boolean = false , parentPath : string = '' ) : any {
15+ export function flattenObject ( obj : any , preservePath : boolean = false ) : any {
1716 const flatObject : any = { } ;
1817 Object . keys ( obj ) . forEach ( ( key ) => {
19- if ( preservePath ) {
20- if ( parentPath . length > 0 ) {
21- parentPath = `${ parentPath } .${ key } ` ;
22- } else {
23- parentPath = key ;
24- }
25- }
2618 if ( typeof obj [ key ] === 'object' && obj [ key ] !== null ) {
2719 let children : any = { } ;
28- Object . assign ( children , this . flattenObject ( obj [ key ] , preservePath , parentPath ) ) ;
20+ Object . assign ( children , this . flattenObject ( obj [ key ] , preservePath ) ) ;
2921 Object . keys ( children ) . forEach ( childKey => {
30- flatObject [ `${ parentPath } .${ childKey } ` ] = children [ childKey ] ;
22+ const propertyName : string = ( preservePath ) ? `${ key } .${ childKey } ` : childKey ;
23+ flatObject [ propertyName ] = children [ childKey ] ;
3124 } ) ;
3225 }
3326 else if ( Array . isArray ( obj [ key ] ) ) {
You can’t perform that action at this time.
0 commit comments