import { formatDistanceToNow } from 'date-fns' ; import { brokerages } from '../brokerages' ; export function formatString ( thing ) { if ( thing === null ) { return 'null' ; } if ( thing === undefined ) { return 'undefined' ; } return thing . toString ( ) . trim ( ) ; } export function formatLanguage ( language ) { switch ( language ) { case 'Py' : return 'Python' ; case 'Ja' : return 'Java' ; case 'VB' : return 'Visual Basic' ; default : return language ; } } export function formatLiveAlgorithmStatus ( status ) { switch ( status ) { case 'DeployError' : return 'Deploy Error' ; case 'InQueue' : return 'In Queue' ; case 'RuntimeError' : return 'Runtime Error' ; case 'LoggingIn' : return 'Logging In' ; default : return status ; } } export function formatProjectName ( name ) { return name . replace ( /^\/+/g , '' ) ; } export function formatBrokerage ( id ) { return brokerages . find ( brokerage => brokerage . id === id ) . name ; } export function formatDate ( date ) { return formatDistanceToNow ( date , { addSuffix : true } ) ; } export function formatNumber ( num , fractionDigits = 0 ) { return num . toFixed ( fractionDigits ) . replace ( /\B(?=(\d{3})+(?!\d))/g , ',' ) ; } export function pluralize ( amount , single , multiple = single + 's' ) { return amount === 1 ? single : multiple ; } export function formatAmount ( amount , single , multiple ? ) { return `${ formatNumber ( amount ) } ${ pluralize ( amount , single , multiple ) }` ; } export function toUnixTimestamp ( date ) { return Math . floor ( date . getTime ( ) / 1000 ) ; }