import get from 'lodash.get' ; import set from 'lodash.set' ; export function withDocumentDatesParsed < Data extends object > ( data , parseDates ? ) { const doc = { ... data } ; parseDates ?. forEach ( dateField => { if ( typeof dateField !== 'string' ) return ; const unparsedDate = get ( doc , dateField ) ; if ( unparsedDate ) { const parsedDate = unparsedDate . toDate ?. ( ) ; if ( parsedDate ) { set ( doc , dateField , parsedDate ) ; } } } ) ; return doc ; }