UNPKG

mat-currency-format

Version:

This repos is creating a library for angular currency input and also it is showing how to use the library

2 lines 2.64 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common")):"function"==typeof define&&define.amd?define("mat-currency-format",["exports","@angular/core","@angular/common"],t):t((e=e||self)["mat-currency-format"]={},e.ng.core,e.ng.common)}(this,(function(e,t,r){"use strict";function n(e,t){var r=new Intl.NumberFormat(t).format(1111).replace(/1/g,""),n=new Intl.NumberFormat(t).format(1.1).replace(/1/g,""),o=e.replace(new RegExp("\\"+r,"g"),""),i=(o=o.replace(new RegExp("\\"+n,"g"),".")).replace(/[^\d.-]/g,"");return Number.isNaN(i)?0:i}var o=function(){function e(e,t,r,n){this.el=e,this.currencyPipe=t,this.renderer=r,this.locale=n,this.currencyCode="USD",this.allowNegative=!1,this.regex={positiveDecimal:new RegExp(/^\d*[\.|,]?\d*$/g),allDecimal:new RegExp(/^-?\d*[\.|,]?\d*$/g)},this.specialKeys=["Backspace","Delete","ArrowLeft","ArrowRight","Del"]}return e.prototype.ngAfterViewInit=function(){this.el.nativeElement.value=this.currencyPipe.transform(this.el.nativeElement.value,this.currencyCode)},e.prototype.onFocus=function(){this.el.nativeElement.value=this.el.nativeElement.value.replace(/[^\d.,-]/g,""),this.el.nativeElement.select()},e.prototype.onFocusout=function(){var e=this.el.nativeElement.value;(0===e.length||1===e.length&&[",",".",""].indexOf(e[0])>-1)&&(e="0"),this.el.nativeElement.value=this.currencyPipe.transform(e,this.currencyCode)},e.prototype.onKeyDown=function(e){-1===this.specialKeys.indexOf(e.key)&&((this.allowNegative?e.key.match(this.regex.allDecimal):e.key.match(this.regex.positiveDecimal))||e.preventDefault())},e.prototype.onBlur=function(e){var t=n(this.el.nativeElement.value,this.locale).replace(/^[^0-9]{2}..*/g,"");this.el.nativeElement.value=t},e.decorators=[{type:t.Directive,args:[{selector:"[mvndrMatCurrencyFormat]",providers:[r.CurrencyPipe]}]}],e.ctorParameters=function(){return[{type:t.ElementRef},{type:r.CurrencyPipe},{type:t.Renderer2},{type:String,decorators:[{type:t.Inject,args:[t.LOCALE_ID]}]}]},e.propDecorators={currencyCode:[{type:t.Input}],allowNegative:[{type:t.Input}],onFocus:[{type:t.HostListener,args:["focus"]}],onFocusout:[{type:t.HostListener,args:["focusout"]}],onKeyDown:[{type:t.HostListener,args:["keydown",["$event"]]}],onBlur:[{type:t.HostListener,args:["blur"]}]},e}();var i=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{declarations:[o],imports:[],exports:[o]}]}],e}();e.MatCurrencyFormatDirective=o,e.MatCurrencyFormatModule=i,e.reverseFormatNumber=n,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=mat-currency-format.umd.min.js.map