declare let TweenMax ; declare let Power2 ; export const simplifyCaseOfAction = ( caseOfAction ) => { return caseOfAction . replace ( /^.+?，/ , '' ) . replace ( /[，。]?爰(.+)$/ , '。' ) ; } ; export const scrollBody = ( dom , duration = 0.5 , gap = 10 ) => { const { clientHeight : headerHeight } = document . querySelector ( 'header' ) as HTMLDivElement ; const targetDOM = document . querySelector ( dom ) as HTMLDivElement ; const { top : targetRectTop } = targetDOM . getBoundingClientRect ( ) ; const scrollToY = window . scrollY + targetRectTop - gap - headerHeight ; return TweenMax . to ( window , duration , { scrollTo : { y : scrollToY , autoKill : false } , ease : Power2 . easeOut } ) ; } ; export const billNoToDate = ( billNo ) => { const year = parseInt ( billNo . substr ( 0 , 3 ) ) + 1911 ; const month = billNo . substr ( 3 , 2 ) ; const day = billNo . substr ( 5 , 2 ) ; return `${ year }-${ month }-${ day }` ; } ; param initialValue { any } param fns { Function [ ] } returns { any } export const pipe = ( initialValue , ... fns ) => { return fns . reduce ( ( prev , currentFun ) => currentFun ( prev ) , initialValue ) ; } ; param value { string | number } returns { string } export const numberWithCommas = ( value ) : string => { if ( ! value ) { return '--' ; } const parts = value . toString ( ) . split ( '.' ) ; parts [ 0 ] = parts [ 0 ] . replace ( /\B(?=(\d{3})+(?!\d))/g , ',' ) ; return parts . join ( '.' ) ; } ; param category param action param label export const gaEvent = ( category , action , label ) => { ( window as any ) [ 'gtag' ] ( 'event' , action , { event_category : category , event_label : label } ) ; if ( process . env . NODE_ENV === 'development' ) { console . log ( `%cgaEvent ${ category }, ${ action }, ${ label }` , 'background: #3199BA; color: white' ) ; } } ; export const registerGAEvent = ( ) => { window . addEventListener ( 'click' , ( e ) => { const dom = e . target as HTMLElement ; const category = dom . getAttribute ( 'data-category' ) || '' ; const action = dom . getAttribute ( 'data-action' ) || '' ; const label = dom . getAttribute ( 'data-label' ) || '' ; if ( category && action && label ) { gaEvent ( category , action , label ) ; } } ) ; } ;