UNPKG

858 BPlain TextView Raw
1const CURRENCY_FORMATTER: Intl.NumberFormat = new Intl.NumberFormat('de-DE', {
2 currency: 'EUR',
3 maximumFractionDigits: 2,
4 minimumFractionDigits: 2,
5});
6
7/**
8 * https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
9 *
10 * Missing config for leading 0's 1.1.1970 instead of 01.01.1970
11 */
12const DATE_FORMATTER: Intl.DateTimeFormat = new Intl.DateTimeFormat('de-DE');
13
14export class Filters {
15 public static currency(value: number): string {
16 if (isNaN(value) === false && typeof value === 'number') {
17 return CURRENCY_FORMATTER.format(value);
18 } else {
19 throw new Error('Value is not a number!');
20 }
21 }
22
23 public static date(value: Date): string {
24 if (value instanceof Date) {
25 return DATE_FORMATTER.format(value);
26 } else {
27 throw new Error('Value is not a date!');
28 }
29 }
30}