export const share = ( e ) => { const shareUrl = location . href ; const title = document . title ; switch ( e . currentTarget . getAttribute ( 'share' ) ) { case 'facebook' : { openFacebook ( { title , shareUrl } ) ; break ; } case 'twitter' : { openTwitter ( { title , shareUrl } ) ; break ; } default : throw new Error ( 'Unknown share target' ) ; } } ; const features = ( { height } ) : string => { return [ [ 'menubar' , 'no' ] , [ 'toolbar' , 'no' ] , [ 'resizable' , 'yes' ] , [ 'scrollbars' , 'yes' ] , [ 'width' , 600 ] , [ 'height' , height ] , ] . map ( ( feature ) => feature . join ( '=' ) ) . join ( ',' ) ; } ; const openTwitter = ( { title , shareUrl } ) => { const text = `Check out ${ title } at #{$ hashtag $}: ${ shareUrl }` ; const url = `https://twitter.com/intent/tweet?text=${ encodeURIComponent ( text ) }` ; window . open ( url , 'share' , features ( { height : 275 } ) ) ; } ; const openFacebook = ( { title , shareUrl } ) => { const url = `https://www.facebook.com/sharer.php?u=${ encodeURIComponent ( shareUrl ) }&t=${ encodeURIComponent ( title ) }` ; window . open ( url , 'share' , features ( { height : 775 } ) ) ; } ;