export function getNestedProperty ( obj , accessor , defaultValue ? ) { const accessorKeys = accessor . split ( '.' ) ; let o = obj ; for ( let i = 0 ; i < accessorKeys . length ; i ++ ) { const keyPart = accessorKeys [ i ] ; o = o ?. [ keyPart ] ; if ( Array . isArray ( o ) ) { o = o . map ( ( v ) => typeof v === 'object' ? getNestedProperty ( v , accessorKeys . slice ( i + 1 , accessorKeys . length ) . join ( '.' ) ) : v ) ; break ; } } if ( o === undefined ) return defaultValue ; return o ; } export const setNestedProperty = ( obj , accessor , value ) => { let ref = obj ; const accessors = accessor . split ( '.' ) ; const len = accessors . length ; for ( let i = 0 ; i < len - 1 ; i ++ ) { const attribute = accessors [ i ] ; if ( ref [ attribute ] === undefined ) { ref [ attribute ] = { } ; } ref = ref [ attribute ] ; } ref [ accessors [ len - 1 ] ] = value ; return obj ; } ;