mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
6 changed files with 2 additions and 114 deletions
@ -1,47 +0,0 @@ |
|||||
/* |
|
||||
* Squidex Headless CMS |
|
||||
* |
|
||||
* @license |
|
||||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|
||||
*/ |
|
||||
|
|
||||
import { CurrencyConfig, DecimalSeparatorConfig } from '@app/framework/internal'; |
|
||||
import { MoneyPipe } from './money.pipe'; |
|
||||
|
|
||||
describe('MoneyPipe', () => { |
|
||||
it('should format money values with symbol after number', () => { |
|
||||
const pipe = new MoneyPipe(new CurrencyConfig('EUR', '€'), new DecimalSeparatorConfig(',')); |
|
||||
|
|
||||
const actual = pipe.transform(123.49); |
|
||||
const expected = '123,<span class="decimal">49</span> €'; |
|
||||
|
|
||||
expect(actual).toBe(expected); |
|
||||
}); |
|
||||
|
|
||||
it('should format money values with symbol after number and one decimal', () => { |
|
||||
const pipe = new MoneyPipe(new CurrencyConfig('EUR', '€'), new DecimalSeparatorConfig(',')); |
|
||||
|
|
||||
const actual = pipe.transform(123.4); |
|
||||
const expected = '123,<span class="decimal">40</span> €'; |
|
||||
|
|
||||
expect(actual).toBe(expected); |
|
||||
}); |
|
||||
|
|
||||
it('should format money values with symbol before number', () => { |
|
||||
const pipe = new MoneyPipe(new CurrencyConfig('EUR', '€', false), new DecimalSeparatorConfig(',')); |
|
||||
|
|
||||
const actual = pipe.transform(123.49); |
|
||||
const expected = '€ 123,<span class="decimal">49</span>'; |
|
||||
|
|
||||
expect(actual).toBe(expected); |
|
||||
}); |
|
||||
|
|
||||
it('should format money values with symbol before number and one decimal', () => { |
|
||||
const pipe = new MoneyPipe(new CurrencyConfig('EUR', '€', false), new DecimalSeparatorConfig(',')); |
|
||||
|
|
||||
const actual = pipe.transform(123.4); |
|
||||
const expected = '€ 123,<span class="decimal">40</span>'; |
|
||||
|
|
||||
expect(actual).toBe(expected); |
|
||||
}); |
|
||||
}); |
|
||||
@ -1,35 +0,0 @@ |
|||||
/* |
|
||||
* Squidex Headless CMS |
|
||||
* |
|
||||
* @license |
|
||||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|
||||
*/ |
|
||||
|
|
||||
import { Pipe, PipeTransform } from '@angular/core'; |
|
||||
import { CurrencyConfig, DecimalSeparatorConfig } from '@app/framework/internal'; |
|
||||
|
|
||||
@Pipe({ |
|
||||
name: 'sqxMoney', |
|
||||
pure: true, |
|
||||
}) |
|
||||
export class MoneyPipe implements PipeTransform { |
|
||||
constructor( |
|
||||
private readonly currency: CurrencyConfig, |
|
||||
private readonly separator: DecimalSeparatorConfig, |
|
||||
) { |
|
||||
} |
|
||||
|
|
||||
public transform(value: number): any { |
|
||||
const money = value.toFixed(2).toString(); |
|
||||
|
|
||||
let result = `${money.substring(0, money.length - 3) + this.separator.value}<span class="decimal">${money.substring(money.length - 2)}</span>`; |
|
||||
|
|
||||
if (this.currency.showAfter) { |
|
||||
result = `${result} ${this.currency.symbol}`; |
|
||||
} else { |
|
||||
result = `${this.currency.symbol} ${result}`; |
|
||||
} |
|
||||
|
|
||||
return result; |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue