ngx-mask
Version:
awesome ngx mask
29 lines • 3.11 kB
JavaScript
import { Pipe } from '@angular/core';
import { MaskApplierService } from './mask-applier.service';
export class MaskPipe {
constructor(_maskService) {
this._maskService = _maskService;
}
transform(value, mask, thousandSeparator = null) {
if (!value && typeof value !== 'number') {
return '';
}
if (thousandSeparator) {
this._maskService.thousandSeparator = thousandSeparator;
}
if (typeof mask === 'string') {
return this._maskService.applyMask(`${value}`, mask);
}
return this._maskService.applyMaskWithPattern(`${value}`, mask);
}
}
MaskPipe.decorators = [
{ type: Pipe, args: [{
name: 'mask',
pure: true,
},] }
];
MaskPipe.ctorParameters = () => [
{ type: MaskApplierService }
];
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFzay5waXBlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vcHJvamVjdHMvbmd4LW1hc2stbGliL3NyYy9saWIvbWFzay5waXBlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxJQUFJLEVBQWlCLE1BQU0sZUFBZSxDQUFDO0FBRXBELE9BQU8sRUFBRSxrQkFBa0IsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBTzVELE1BQU0sT0FBTyxRQUFRO0lBQ25CLFlBQTJCLFlBQWdDO1FBQWhDLGlCQUFZLEdBQVosWUFBWSxDQUFvQjtJQUFHLENBQUM7SUFFeEQsU0FBUyxDQUNkLEtBQXNCLEVBQ3RCLElBQTRDLEVBQzVDLG9CQUFtQyxJQUFJO1FBRXZDLElBQUksQ0FBQyxLQUFLLElBQUksT0FBTyxLQUFLLEtBQUssUUFBUSxFQUFFO1lBQ3ZDLE9BQU8sRUFBRSxDQUFDO1NBQ1g7UUFDRCxJQUFJLGlCQUFpQixFQUFFO1lBQ3JCLElBQUksQ0FBQyxZQUFZLENBQUMsaUJBQWlCLEdBQUcsaUJBQWlCLENBQUM7U0FDekQ7U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