import dayjs , { Dayjs } from 'dayjs' ; export const noop = ( ) => ( void 0 ) ; export const base64Encode = ( str ) : string => { return Buffer . from ( str , 'utf-8' ) . toString ( 'base64' ) ; } ; export const base64Decode = ( str ) : string => { return Buffer . from ( str , 'base64' ) . toString ( 'utf-8' ) ; } ; export const computeWeekOf = ( date , unit ) : number => { const firstDayOfUnit = dayjs ( date ) . startOf ( unit ) ; const firstDayWeekday = firstDayOfUnit . day ( ) + 1 ; const firstWeekDays = ( 8 - firstDayWeekday ) % 7 ; const thisDay = dayjs ( date ) ; const daysDiff = thisDay . diff ( firstDayOfUnit , 'day' , false ) ; if ( daysDiff < firstWeekDays ) { return 0 ; } else { return Math . ceil ( ( daysDiff - firstWeekDays + 1 ) / 7 ) ; } } ; const hierarchicalNameSplitting = /[_.]/ ; const nonHierarchicalNameSplitting = /_/ ; export const againstSnakeCaseName = ( name , hierarchical = false ) => { return /^\d.*$/ . test ( name ) || name . split ( hierarchical ? hierarchicalNameSplitting : nonHierarchicalNameSplitting ) . some ( part => ! /^[A-Za-z0-9]+$/ . test ( part ) ) ; } ; export const isXaNumber = ( x , negative = true ) : boolean => { if ( x == null ) { return false ; } let testValue ; if ( x . toString && typeof x . toString === 'function' ) { testValue = x . toString ( ) ; } else { testValue = `${ x }` ; } if ( negative ) { return /^(-?)[0-9]+(.[0-9]*)?$/ . test ( testValue ) ; } else { return /^[0-9]+(.[0-9]*)?$/ . test ( testValue ) ; } } ; export const formatToKGB = ( x ) : string => { if ( x >= 1000000000 ) { return ( x / 1000000000 ) . toFixed ( 1 ) . replace ( /\.0$/ , '' ) + 'b' ; } if ( x >= 1000000 ) { return ( x / 1000000 ) . toFixed ( 1 ) . replace ( /\.0$/ , '' ) + 'm' ; } if ( x >= 1000 ) { return ( x / 1000 ) . toFixed ( 1 ) . replace ( /\.0$/ , '' ) + 'k' ; } return `${ x }` ; } ;