@taiga-ui/addon-commerce
Version:
Extension package for Taiga UI related to commerce, payment systems, currencies etc.
43 lines (39 loc) • 1.85 kB
JavaScript
import * as i0 from '@angular/core';
import { inject, Injector, INJECTOR, signal, computed, untracked, Pipe } from '@angular/core';
import { TuiAmountPipe } from '@taiga-ui/addon-commerce/pipes/amount';
import { TUI_NUMBER_FORMAT } from '@taiga-ui/core/tokens';
class TuiDecimalPipe {
constructor() {
this.format = inject(TUI_NUMBER_FORMAT);
this.amountPipe = Injector.create({
providers: [{ provide: TuiAmountPipe }],
parent: inject(INJECTOR),
}).get(TuiAmountPipe);
this.value = signal(Number.NaN);
this.currency = signal('');
this.formatted = computed(() => {
const format = this.format();
const amount = this.amountPipe.transform(this.value(), this.currency());
const [, decimal] = amount.split(format.decimalSeparator);
return decimal ? `${format.decimalSeparator}${decimal}` : '';
});
}
transform(value, currency = '') {
untracked(() => {
this.value.set(value);
this.currency.set(currency);
});
return this.formatted();
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: TuiDecimalPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.21", ngImport: i0, type: TuiDecimalPipe, isStandalone: true, name: "tuiDecimal", pure: false }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: TuiDecimalPipe, decorators: [{
type: Pipe,
args: [{ name: 'tuiDecimal', pure: false }]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { TuiDecimalPipe };
//# sourceMappingURL=taiga-ui-addon-commerce-pipes-decimal.mjs.map