import { GQLHumanName , GQLComment } from '@opencrvs/gateway/src/graphql/schema' ; interface INamesMap { [ key ] : string ; } export const createNamesMap = ( names ) : INamesMap => names . filter ( Boolean ) . reduce ( ( prevNamesMap , name ) => { if ( ! name . use ) { prevNamesMap [ 'default' ] = `${ name . firstNames || '' } ${ name . familyName || '' }` . trim ( ) ; return prevNamesMap ; } prevNamesMap [ name . use ] = `${ name . firstNames || '' } ${ name . familyName || '' }` . trim ( ) ; return prevNamesMap ; } , { } ) ; export const extractCommentFragmentValue = ( comments , fragmentItem ) : string => { let fragmentValue = '' ; for ( const comment of comments ) { if ( comment . comment ) { const commentFragments = comment . comment . split ( '&' ) ; for ( const fragment of commentFragments ) { if ( fragment . includes ( `${ fragmentItem }=` ) ) { fragmentValue = fragment . replace ( `${ fragmentItem }=` , '' ) ; break ; } } } if ( fragmentValue . length > 0 ) { break ; } } return fragmentValue ; } ; export const sentenceCase = ( str ) : string => str . replace ( /\w\S*/g , ( txt ) => { return txt . charAt ( 0 ) . toUpperCase ( ) + txt . substr ( 1 ) . toLowerCase ( ) ; } ) ;