import CalendarAttendee from '../types/CalendarAttendee' ; const identity = ( str ) : string => str ; type Identity = ( str : string ) => string ; param { Record < string , string > } params param { string } delimiter param { Function } transformFn returns { string } const toParamString = ( params , delimiter = ';' , transformFn = identity ) : string => { const paramString = [ ] ; for ( const key in params ) { if ( params . hasOwnProperty ( key ) && params [ key ] !== undefined ) { paramString . push ( `${ key }=${ transformFn ( params [ key ] ) }` ) ; } } return paramString . join ( delimiter ) ; } ; param { Record < string , string | null > } params returns { string } const toQueryString = ( params ) : string => { const filteredParams = Object . keys ( params ) . filter ( p => params [ p ] !== null ) . reduce ( ( p , k ) => ( { ... p , [ k ] : params [ k ] as string } ) , { } ) ; return toParamString ( filteredParams , '&' , encodeURIComponent ) ; } ; param { Record < string , string > } params returns { string } const toIcsParamString = ( params ) : string => { return toParamString ( params , ';' ) ; } ; param { CalendarAttendee [ ] } attendees returns { string [ ] } const toMailtoList = ( attendees ) : string [ ] => { return attendees . map ( ( { email , name } ) => { return name ? `${ name } <${ email }>` : email ; } ) ; } ; param { string } s returns { string } const toProperCase = ( s ) : string => { return [ s [ 0 ] . toUpperCase ( ) , s . slice ( - s . length + 1 ) . toLowerCase ( ) ] . join ( '' ) ; } ; export default { toParamString , toQueryString , toIcsParamString , toMailtoList , toProperCase } ;