export function formatDateDisplay(d: Date, options = undefined): string { let opt: any = { year: 'numeric', month: 'short', day: '2-digit', }; if (options) { opt = options; } return d.toLocaleDateString('en-US', opt); } /** * Format the provided value as US style number. * @param value */ export function formatValue( value: number, denominator = 1, options = {} ): string { let valueFormatted; if (value !== undefined && value !== null) { valueFormatted = (Math.abs(value) / denominator).toLocaleString( 'en-US', options ); if (value < 0) { valueFormatted = `(${valueFormatted})`; } } return valueFormatted; } /** * Format the provided value as USD currency. * @param value */ export function formatCurrency(value: number, denominator = 1): string { return formatValue(value, denominator, { style: 'currency', currency: 'USD', }); } export function capitalizeText(text: string) { let capText; if (text.length > 0) { capText = text.charAt(0).toUpperCase(); if (text.length > 1) { capText = capText + text.slice(1).toLowerCase(); } } return capText; } export function capitalizeWords(str) { let i, words = str.split(' '); for (i = 0; i < words.length; i++) { words[i] = capitalizeText(words[i]); } return words.join(' '); }