describe('NumberFormatter', () => { numeral.locale('en-gb') describe('formatMoney', () => { it('format numeric value to money', () => { expect(NumberFormatter.formatMoney(10.01)).to.eq('£10.01') }) }) })
import * as numeral from 'numeral' import 'numeral/locales/en-gb' numeral.locale('en-gb') export const NUMBER_FORMAT = '$0,0[.]00' export class NumberFormatter { static formatMoney (value: number): string { return numeral(value).format(NUMBER_FORMAT) } }
enableFor (app: express.Express) { app.set('view engine', 'njk') const nunjucksEnv = nunjucks.configure([ path.join(__dirname, '..', '..', 'views'), path.join(__dirname, '..', '..', 'common'), path.join(__dirname, '..', '..', 'features'), path.join(__dirname, '..', '..', 'views', 'macro'), path.join(__dirname, '..', '..', '..', '..', 'node_modules', '@hmcts', 'cmc-common-frontend', 'macros') ], { autoescape: true, throwOnUndefined: true, watch: this.developmentMode, express: app }) app.use((req, res, next) => { res.locals.pagePath = req.path next() }) require('numeral/locales/en-gb') numeral.locale('en-gb') numeral.defaultFormat(NUMBER_FORMAT) moment.locale('en-gb') nunjucksEnv.addGlobal('asset_paths', appAssetPaths) nunjucksEnv.addGlobal('serviceName', 'Money Claims') nunjucksEnv.addGlobal('supportEmailAddress', config.get('secrets.cmc.staff-email')) nunjucksEnv.addGlobal('development', this.developmentMode) nunjucksEnv.addGlobal('govuk_template_version', packageDotJson.dependencies.govuk_template_jinja) nunjucksEnv.addGlobal('gaTrackingId', config.get<string>('analytics.gaTrackingId')) nunjucksEnv.addGlobal('t', (key: string, options?: TranslationOptions): string => this.i18next.t(key, options)) nunjucksEnv.addFilter('date', dateFilter) nunjucksEnv.addFilter('inputDate', dateInputFilter) nunjucksEnv.addFilter('addDays', addDaysFilter) nunjucksEnv.addFilter('pennies2pounds', convertToPoundsFilter) nunjucksEnv.addFilter('monthIncrement', monthIncrementFilter) nunjucksEnv.addFilter('numeral', numeralFilter) nunjucksEnv.addFilter('yesNo', yesNoFilter) nunjucksEnv.addGlobal('isAfter4pm', isAfter4pm) nunjucksEnv.addGlobal('betaFeedbackSurveyUrl', config.get('feedback.feedbackSurvey.url')) nunjucksEnv.addGlobal('reportProblemSurveyUrl', config.get('feedback.reportProblemSurvey.url')) nunjucksEnv.addGlobal('customerSurveyUrl', config.get('feedback.serviceSurvey.url')) nunjucksEnv.addGlobal('featureToggles', this.convertPropertiesToBoolean(config.get('featureToggles'))) nunjucksEnv.addGlobal('RejectAllOfClaimOption', RejectAllOfClaimOption) nunjucksEnv.addGlobal('AlreadyPaid', AlreadyPaid) nunjucksEnv.addGlobal('DefendantPaymentType', DefendantPaymentType) nunjucksEnv.addGlobal('DefendantPaymentOption', DefendantPaymentOption) nunjucksEnv.addGlobal('PaymentType', PaymentType) nunjucksEnv.addGlobal('InterestRateOption', InterestRateOption) nunjucksEnv.addGlobal('SignatureType', SignatureType) nunjucksEnv.addGlobal('ResponseType', ResponseType) nunjucksEnv.addGlobal('MadeBy', MadeBy) nunjucksEnv.addGlobal('CountyCourtJudgmentType', CountyCourtJudgmentType) nunjucksEnv.addGlobal('YesNoOption', YesNoOption) nunjucksEnv.addGlobal('EvidenceType', EvidenceType) nunjucksEnv.addGlobal('StatementType', StatementType) nunjucksEnv.addGlobal('NotEligibleReason', NotEligibleReason) nunjucksEnv.addGlobal('InterestType', InterestType) nunjucksEnv.addGlobal('InterestTypeOption', InterestTypeOption) nunjucksEnv.addGlobal('InterestDateType', InterestDateType) nunjucksEnv.addGlobal('InterestEndDateOption', InterestEndDateOption) nunjucksEnv.addGlobal('FormaliseOption', FormaliseOption) nunjucksEnv.addGlobal('ClaimantResponseType', ClaimantResponseType) nunjucksEnv.addGlobal('ResidenceType', ResidenceType) nunjucksEnv.addGlobal('PaymentSchedule', PaymentSchedule) nunjucksEnv.addGlobal('UnemploymentType', UnemploymentType) nunjucksEnv.addGlobal('BankAccountType', BankAccountType) nunjucksEnv.addGlobal('ClaimStatus', ClaimStatus) nunjucksEnv.addGlobal('AppPaths', AppPaths) nunjucksEnv.addGlobal('ClaimantResponsePaths', ClaimantResponsePaths) nunjucksEnv.addGlobal('DashboardPaths', DashboardPaths) nunjucksEnv.addGlobal('CCJPaths', CCJPaths) nunjucksEnv.addGlobal('StatePaidPaths', StatePaidPaths) nunjucksEnv.addGlobal('ResponsePaths', ResponsePaths) nunjucksEnv.addGlobal('MediationPaths', MediationPaths) nunjucksEnv.addGlobal('PartAdmissionPaths', PartAdmissionPaths) nunjucksEnv.addGlobal('FullRejectionPaths', FullRejectionPaths) nunjucksEnv.addGlobal('DirectionsQuestionnairePaths', DirectionsQuestionnairePaths) nunjucksEnv.addGlobal('TestingSupportPaths', TestingSupportPaths) nunjucksEnv.addGlobal('SettlementAgreementPaths', SettlementAgreementPaths) nunjucksEnv.addGlobal('HowMuchPaidClaimantOption', HowMuchPaidClaimantOption) nunjucksEnv.addGlobal('MonthlyIncomeType', MonthlyIncomeType) nunjucksEnv.addGlobal('MonthlyExpenseType', MonthlyExpenseType) nunjucksEnv.addGlobal('PriorityDebtType', PriorityDebtType) nunjucksEnv.addGlobal('Service', Service) nunjucksEnv.addGlobal('DisabilityStatus', Disability) nunjucksEnv.addGlobal('cookieText', `GOV.UK uses cookies make the site simpler. <a href="${AppPaths.cookiesPage.uri}">Find out more about cookies</a>`) nunjucksEnv.addGlobal('serviceName', `Money Claims`) nunjucksEnv.addGlobal('headingVisible', true) nunjucksEnv.addGlobal('DecisionType', DecisionType) nunjucksEnv.addGlobal('PartyType', PartyType) nunjucksEnv.addGlobal('IncomeExpenseSchedule', IncomeExpenseSchedule) nunjucksEnv.addGlobal('FreeMediationOption', FreeMediationOption) }