ngx-mask 8.1.4 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -52
- package/bundles/ngx-mask.umd.js +137 -28
- package/bundles/ngx-mask.umd.js.map +1 -1
- package/bundles/ngx-mask.umd.min.js +1 -1
- package/bundles/ngx-mask.umd.min.js.map +1 -1
- package/esm2015/index.js +3 -1
- package/esm2015/lib/config.js +4 -1
- package/esm2015/lib/mask-applier.service.js +14 -3
- package/esm2015/lib/mask.directive.js +60 -16
- package/esm2015/lib/mask.pipe.js +6 -2
- package/esm2015/lib/mask.service.js +1 -8
- package/esm2015/ngx-mask.js +2 -3
- package/esm5/index.js +3 -1
- package/esm5/lib/config.js +4 -1
- package/esm5/lib/mask-applier.service.js +14 -3
- package/esm5/lib/mask.directive.js +68 -15
- package/esm5/lib/mask.pipe.js +8 -2
- package/esm5/lib/mask.service.js +1 -8
- package/esm5/ngx-mask.js +2 -3
- package/fesm2015/ngx-mask.js +122 -26
- package/fesm2015/ngx-mask.js.map +1 -1
- package/fesm5/ngx-mask.js +132 -25
- package/fesm5/ngx-mask.js.map +1 -1
- package/index.d.ts +2 -0
- package/lib/config.d.ts +1 -0
- package/lib/mask-applier.service.d.ts +1 -0
- package/lib/mask.directive.d.ts +3 -0
- package/lib/mask.pipe.d.ts +1 -1
- package/lib/mask.service.d.ts +0 -2
- package/ngx-mask.d.ts +0 -1
- package/ngx-mask.metadata.json +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/forms"),require("@angular/common")):"function"==typeof define&&define.amd?define("ngx-mask",["exports","@angular/core","@angular/forms","@angular/common"],t):t((e=e||self)["ngx-mask"]={},e.ng.core,e.ng.forms,e.ng.common)}(this,function(e,t,i,s){"use strict";var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])})(e,t)};var a=function(){return(a=Object.assign||function(e){for(var t,i=1,s=arguments.length;i<s;i++)for(var r in t=arguments[i])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};function n(e,t){var i,s,r,a,n={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return a={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function o(a){return function(o){return function(a){if(i)throw new TypeError("Generator is already executing.");for(;n;)try{if(i=1,s&&(r=2&a[0]?s.return:a[0]?s.throw||((r=s.return)&&r.call(s),0):s.next)&&!(r=r.call(s,a[1])).done)return r;switch(s=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return n.label++,{value:a[1],done:!1};case 5:n.label++,s=a[1],a=[0];continue;case 7:a=n.ops.pop(),n.trys.pop();continue;default:if(!(r=(r=n.trys).length>0&&r[r.length-1])&&(6===a[0]||2===a[0])){n=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){n.label=a[1];break}if(6===a[0]&&n.label<r[1]){n.label=r[1],r=a;break}if(r&&n.label<r[2]){n.label=r[2],n.ops.push(a);break}r[2]&&n.ops.pop(),n.trys.pop();continue}a=t.call(e,n)}catch(e){a=[6,e],s=0}finally{i=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,o])}}}function o(e,t){var i="function"==typeof Symbol&&e[Symbol.iterator];if(!i)return e;var s,r,a=i.call(e),n=[];try{for(;(void 0===t||t-- >0)&&!(s=a.next()).done;)n.push(s.value)}catch(e){r={error:e}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}return n}var h=new t.InjectionToken("config"),l=new t.InjectionToken("NEW_CONFIG"),c=new t.InjectionToken("INITIAL_CONFIG"),p={suffix:"",prefix:"",thousandSeparator:" ",decimalMarker:".",clearIfNotMatch:!1,showTemplate:!1,showMaskTyped:!1,placeHolderCharacter:"_",dropSpecialCharacters:!0,hiddenInput:void 0,shownMaskExpression:"",separatorLimit:"",validation:!0,specialCharacters:["-","/","(",")",".",":"," ","+",",","@","[","]",'"',"'"],patterns:{0:{pattern:new RegExp("\\d")},9:{pattern:new RegExp("\\d"),optional:!0},X:{pattern:new RegExp("\\d"),symbol:"*"},A:{pattern:new RegExp("[a-zA-Z0-9]")},S:{pattern:new RegExp("[a-zA-Z]")},d:{pattern:new RegExp("\\d")},m:{pattern:new RegExp("\\d")},M:{pattern:new RegExp("\\d")},H:{pattern:new RegExp("\\d")},h:{pattern:new RegExp("\\d")},s:{pattern:new RegExp("\\d")}}},u=["Hh:m0:s0","Hh:m0","m0:s0"],f=["percent","Hh","s0","m0","separator","d0/M0/0000","d0/M0","d0","M0"],m=function(){function e(e){var t=this;this._config=e,this.maskExpression="",this.actualValue="",this.shownMaskExpression="",this._formatWithSeparators=function(e,i,s,r){var a=e.split(s),n=a.length>1?""+s+a[1]:"",o=a[0],h=t.separatorLimit.replace(/\s/g,"");h&&+h&&(o=o.slice(0,h.length));for(var l=/(\d+)(\d{3})/;l.test(o);)o=o.replace(l,"$1"+i+"$2");return void 0===r?o+n:0===r?o:o+n.substr(0,r+1)},this.percentage=function(e){return Number(e)>=0&&Number(e)<=100},this.getPrecision=function(e){var t=e.split(".");return t.length>1?Number(t[t.length-1]):1/0},this.checkInputPrecision=function(e,i,s){if(i<1/0){var r=new RegExp(t._charToRegExpExpression(s)+"\\d{"+i+"}.*$"),a=e.match(r);a&&a[0].length-1>i?e=e.substring(0,e.length-1):0===i&&e.endsWith(s)&&(e=e.substring(0,e.length-1))}return e},this._shift=new Set,this.clearIfNotMatch=this._config.clearIfNotMatch,this.dropSpecialCharacters=this._config.dropSpecialCharacters,this.maskSpecialCharacters=this._config.specialCharacters,this.maskAvailablePatterns=this._config.patterns,this.prefix=this._config.prefix,this.suffix=this._config.suffix,this.thousandSeparator=this._config.thousandSeparator,this.decimalMarker=this._config.decimalMarker,this.hiddenInput=this._config.hiddenInput,this.showMaskTyped=this._config.showMaskTyped,this.placeHolderCharacter=this._config.placeHolderCharacter,this.validation=this._config.validation,this.separatorLimit=this._config.separatorLimit}return e.prototype.applyMaskWithPattern=function(e,t){var i=o(t,2),s=i[0],r=i[1];return this.customPattern=r,this.applyMask(e,s)},e.prototype.applyMask=function(e,t,i,s){if(void 0===i&&(i=0),void 0===s&&(s=function(){}),null==e||void 0===t)return"";var r=0,a="",n=!1,o=!1,h=1,l=!1;e.slice(0,this.prefix.length)===this.prefix&&(e=e.slice(this.prefix.length,e.length)),this.suffix&&e.endsWith(this.suffix)&&(e=e.slice(0,e.length-this.suffix.length));var c=e.toString().split("");if("IP"===t&&(this.ipError=!!(c.filter(function(e){return"."===e}).length<3&&c.length<7),t="099.099.099.099"),t.startsWith("percent")){if(e.match("[a-z]|[A-Z]")||e.match(/[-!$%^&*()_+|~=`{}\[\]:";'<>?,\/]/)){e=this._stripToDecimal(e);var p=this.getPrecision(t);e=this.checkInputPrecision(e,p,".")}if(e.indexOf(".")>0&&!this.percentage(e.substring(0,e.indexOf(".")))){var u=e.substring(0,e.indexOf(".")-1);e=""+u+e.substring(e.indexOf("."),e.length)}a=this.percentage(e)?e:e.substring(0,e.length-1)}else if(t.startsWith("separator")){(e.match("[wа-яА-Я]")||e.match("[ЁёА-я]")||e.match("[a-z]|[A-Z]")||e.match(/[-@#!$%\\^&*()_£¬'+|~=`{}\[\]:";<>.?\/]/)||e.match("[^A-Za-z0-9,]"))&&(e=this._stripToDecimal(e)),e=e.length>1&&"0"===e[0]&&e[1]!==this.decimalMarker?e.slice(1,e.length):e;var f=this._charToRegExpExpression(this.thousandSeparator),m=this._charToRegExpExpression(this.decimalMarker),d='@#!$%^&*()_+|~=`{}\\[\\]:\\s,";<>?\\/'.replace(f,"").replace(m,""),k=new RegExp("["+d+"]");e.match(k)&&(e=e.substring(0,e.length-1));p=this.getPrecision(t);var g=(e=this.checkInputPrecision(e,p,this.decimalMarker)).replace(new RegExp(f,"g"),""),v=(a=this._formatWithSeparators(g,this.thousandSeparator,this.decimalMarker,p)).indexOf(",")-e.indexOf(",");if((x=a.length-e.length)>0&&","!==a[i]){o=!0;var _=0;do{this._shift.add(i+_),_++}while(_<x)}else 0!==v&&i>0&&!(a.indexOf(",")>=i&&i>3)||!(a.indexOf(".")>=i&&i>3)&&x<=0?(this._shift.clear(),o=!0,h=x,i+=x,this._shift.add(i)):this._shift.clear()}else for(var S=0,y=c[0];S<c.length&&r!==t.length;y=c[++S])if(this._checkSymbolMask(y,t[r])&&"?"===t[r+1])a+=y,r+=2;else if("*"===t[r+1]&&n&&this._checkSymbolMask(y,t[r+2]))a+=y,r+=3,n=!1;else if(this._checkSymbolMask(y,t[r])&&"*"===t[r+1])a+=y,n=!0;else if("?"===t[r+1]&&this._checkSymbolMask(y,t[r+2]))a+=y,r+=3;else if(this._checkSymbolMask(y,t[r])||this.hiddenInput&&this.maskAvailablePatterns[t[r]]&&this.maskAvailablePatterns[t[r]].symbol===y){if("H"===t[r]&&Number(y)>2){r+=1;var x=/[*?]/g.test(t.slice(0,r))?c.length:r;this._shift.add(x+this.prefix.length||0),S--;continue}if("h"===t[r]&&"2"===a&&Number(y)>3){r+=1,S--;continue}if("m"===t[r]&&Number(y)>5){r+=1;x=/[*?]/g.test(t.slice(0,r))?c.length:r;this._shift.add(x+this.prefix.length||0),S--;continue}if("s"===t[r]&&Number(y)>5){r+=1;x=/[*?]/g.test(t.slice(0,r))?c.length:r;this._shift.add(x+this.prefix.length||0),S--;continue}if("d"===t[r]&&(Number(e.slice(r,r+2))>31||"/"===e[r+1])){r+=1;x=/[*?]/g.test(t.slice(0,r))?c.length:r;this._shift.add(x+this.prefix.length||0),S--;continue}if("M"===t[r]){var M=0===r&&(Number(y)>2||Number(e.slice(r,r+2))>12||"/"===e[r+1]),E=e.slice(r-3,r-1).includes("/")&&("/"===e[r-2]&&Number(e.slice(r-1,r+1))>12&&"/"!==e[r]||"/"===e[r]||"/"===e[r-3]&&Number(e.slice(r-2,r))>12&&"/"!==e[r-1]||"/"===e[r-1]),b=Number(e.slice(r-3,r-1))<=31&&!e.slice(r-3,r-1).includes("/")&&"/"===e[r-1]&&(Number(e.slice(r,r+2))>12||"/"===e[r+1]),C=Number(e.slice(r-3,r-1))>31&&!e.slice(r-3,r-1).includes("/")&&!e.slice(r-2,r).includes("/")&&Number(e.slice(r-2,r))>12,w=Number(e.slice(r-3,r-1))<=31&&!e.slice(r-3,r-1).includes("/")&&"/"!==e[r-1]&&Number(e.slice(r-1,r+1))>12;if(M||E||b||C||w){r+=1;x=/[*?]/g.test(t.slice(0,r))?c.length:r;this._shift.add(x+this.prefix.length||0),S--;continue}}a+=y,r++}else if(-1!==this.maskSpecialCharacters.indexOf(t[r])){a+=t[r],r++;x=/[*?]/g.test(t.slice(0,r))?c.length:r;this._shift.add(x+this.prefix.length||0),S--}else this.maskSpecialCharacters.indexOf(y)>-1&&this.maskAvailablePatterns[t[r]]&&this.maskAvailablePatterns[t[r]].optional?(c[r]&&"099.099.099.099"!==t&&(a+=c[r]),r++,S--):"*"===this.maskExpression[r+1]&&this._findSpecialChar(this.maskExpression[r+2])&&this._findSpecialChar(y)===this.maskExpression[r+2]&&n?(r+=3,a+=y):"?"===this.maskExpression[r+1]&&this._findSpecialChar(this.maskExpression[r+2])&&this._findSpecialChar(y)===this.maskExpression[r+2]&&n?(r+=3,a+=y):this.showMaskTyped&&this.maskSpecialCharacters.indexOf(y)<0&&y!==this.placeHolderCharacter&&(l=!0);a.length+1===t.length&&-1!==this.maskSpecialCharacters.indexOf(t[t.length-1])&&(a+=t[t.length-1]);for(var V=i+1;this._shift.has(V);)h++,V++;var I=this._shift.has(i)?h:0;l&&I--,s(I,o),h<0&&this._shift.clear();var P=""+this.prefix+a+this.suffix;return 0===a.length&&(P=""+this.prefix+a),P},e.prototype._findSpecialChar=function(e){return this.maskSpecialCharacters.find(function(t){return t===e})},e.prototype._checkSymbolMask=function(e,t){return this.maskAvailablePatterns=this.customPattern?this.customPattern:this.maskAvailablePatterns,this.maskAvailablePatterns[t]&&this.maskAvailablePatterns[t].pattern&&this.maskAvailablePatterns[t].pattern.test(e)},e.prototype._stripToDecimal=function(e){return e.split("").filter(function(e){return e.match("\\d")||"."===e||","===e}).join("")},e.prototype._charToRegExpExpression=function(e){return" "===e?"\\s":"[\\^$.|?*+()".indexOf(e)>=0?"\\"+e:e},e.decorators=[{type:t.Injectable}],e.ctorParameters=function(){return[{type:void 0,decorators:[{type:t.Inject,args:[h]}]}]},e}();var d=function(e){function i(t,i,s,r){var a=e.call(this,i)||this;return a.document=t,a._config=i,a._elementRef=s,a._renderer=r,a.validation=!0,a.maskExpression="",a.isNumberValue=!1,a.showMaskTyped=!1,a.placeHolderCharacter="_",a.maskIsShown="",a.selStart=null,a.selEnd=null,a.onChange=function(e){},a._formElement=a._elementRef.nativeElement,a}return function(e,t){function i(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}(i,e),i.prototype.applyMask=function(t,i,s,r){var a=this;if(void 0===s&&(s=0),void 0===r&&(r=function(){}),!i)return t;if(this.maskIsShown=this.showMaskTyped?this.showMaskInInput():"","IP"===this.maskExpression&&this.showMaskTyped&&(this.maskIsShown=this.showMaskInInput(t||"#")),!t&&this.showMaskTyped)return this.formControlResult(this.prefix),this.prefix+this.maskIsShown;var n=t&&"number"==typeof this.selStart?t[this.selStart]:"",o="";if(void 0!==this.hiddenInput){var h=this.actualValue.split("");""!==t&&h.length?"number"==typeof this.selStart&&"number"==typeof this.selEnd&&(t.length>h.length?h.splice(this.selStart,0,n):t.length<h.length&&(h.length-t.length==1?h.splice(this.selStart-1,1):h.splice(this.selStart,this.selEnd-this.selStart))):h=[],o=this.actualValue.length?this.shiftTypedSymbols(h.join("")):t}o=Boolean(o)&&o.length?o:t;var l=e.prototype.applyMask.call(this,o,i,s,r);if(this.actualValue=this.getActualValue(l),"."===this.thousandSeparator&&"."===this.decimalMarker&&(this.decimalMarker=","),this.maskExpression.startsWith("separator")&&!0===this.dropSpecialCharacters&&(this.maskSpecialCharacters=this.maskSpecialCharacters.filter(function(e){return e!==a.decimalMarker})),this.formControlResult(l),!this.showMaskTyped)return this.hiddenInput&&l&&l.length?this.hideInput(l,this.maskExpression):l;var c=l.length,p=this.prefix+this.maskIsShown;return l+("IP"===this.maskExpression?p:p.slice(c))},i.prototype.applyValueChanges=function(e,t){void 0===e&&(e=0),void 0===t&&(t=function(){}),this._formElement.value=this.applyMask(this._formElement.value,this.maskExpression,e,t),this._formElement!==this.document.activeElement&&this.clearIfNotMatchFn()},i.prototype.hideInput=function(e,t){var i=this;return e.split("").map(function(e,s){return i.maskAvailablePatterns&&i.maskAvailablePatterns[t[s]]&&i.maskAvailablePatterns[t[s]].symbol?i.maskAvailablePatterns[t[s]].symbol:e}).join("")},i.prototype.getActualValue=function(e){var t=this,i=e.split("").filter(function(e,i){return t._checkSymbolMask(e,t.maskExpression[i])||t.maskSpecialCharacters.includes(t.maskExpression[i])&&e===t.maskExpression[i]});return i.join("")===e?i.join(""):e},i.prototype.shiftTypedSymbols=function(e){var t=this,i="";return(e&&e.split("").map(function(s,r){if(t.maskSpecialCharacters.includes(e[r+1])&&e[r+1]!==t.maskExpression[r+1])return i=s,e[r+1];if(i.length){var a=i;return i="",a}return s})||[]).join("")},i.prototype.showMaskInInput=function(e){if(this.showMaskTyped&&this.shownMaskExpression){if(this.maskExpression.length!==this.shownMaskExpression.length)throw new Error("Mask expression must match mask placeholder length");return this.shownMaskExpression}return this.showMaskTyped?e?this._checkForIp(e):this.maskExpression.replace(/\w/g,this.placeHolderCharacter):""},i.prototype.clearIfNotMatchFn=function(){this.clearIfNotMatch&&this.prefix.length+this.maskExpression.length+this.suffix.length!==this._formElement.value.replace(/_/g,"").length&&(this.formElementProperty=["value",""],this.applyMask(this._formElement.value,this.maskExpression))},Object.defineProperty(i.prototype,"formElementProperty",{set:function(e){var t=o(e,2),i=t[0],s=t[1];this._renderer.setProperty(this._formElement,i,s)},enumerable:!0,configurable:!0}),i.prototype.checkSpecialCharAmount=function(e){var t=this;return e.split("").filter(function(e){return t._findSpecialChar(e)}).length},i.prototype._checkForIp=function(e){if("#"===e)return this.placeHolderCharacter+"."+this.placeHolderCharacter+"."+this.placeHolderCharacter+"."+this.placeHolderCharacter;for(var t=[],i=0;i<e.length;i++)e[i].match("\\d")&&t.push(e[i]);return t.length<=3?this.placeHolderCharacter+"."+this.placeHolderCharacter+"."+this.placeHolderCharacter:t.length>3&&t.length<=6?this.placeHolderCharacter+"."+this.placeHolderCharacter:t.length>6&&t.length<=9?this.placeHolderCharacter:(t.length>9&&t.length,"")},i.prototype.formControlResult=function(e){Array.isArray(this.dropSpecialCharacters)?this.onChange(this._removeMask(this._removeSuffix(this._removePrefix(e)),this.dropSpecialCharacters)):this.dropSpecialCharacters?this.onChange(this._checkSymbols(e)):this.onChange(this._removeSuffix(this._removePrefix(e)))},i.prototype._removeMask=function(e,t){return e?e.replace(this._regExpForRemove(t),""):e},i.prototype._removePrefix=function(e){return this.prefix&&e?e.replace(this.prefix,""):e},i.prototype._removeSuffix=function(e){return this.suffix&&e?e.replace(this.suffix,""):e},i.prototype._retrieveSeparatorValue=function(e){return this._removeMask(this._removeSuffix(this._removePrefix(e)),this.maskSpecialCharacters)},i.prototype._regExpForRemove=function(e){return new RegExp(e.map(function(e){return"\\"+e}).join("|"),"gi")},i.prototype._checkSymbols=function(e){if(""===e)return e;var t=this._retrieveSeparatorPrecision(this.maskExpression),i=this._retrieveSeparatorValue(e);return"."!==this.decimalMarker&&(i=i.replace(this.decimalMarker,".")),this.isNumberValue?t?e===this.decimalMarker?null:this._checkPrecision(this.maskExpression,i):Number(i):i},i.prototype._retrieveSeparatorPrecision=function(e){var t=e.match(new RegExp("^separator\\.([^d]*)"));return t?Number(t[1]):null},i.prototype._checkPrecision=function(e,t){return e.indexOf("2")>0?Number(t).toFixed(2):Number(t)},i.decorators=[{type:t.Injectable}],i.ctorParameters=function(){return[{type:void 0,decorators:[{type:t.Inject,args:[s.DOCUMENT]}]},{type:void 0,decorators:[{type:t.Inject,args:[h]}]},{type:t.ElementRef},{type:t.Renderer2}]},i}(m);var k=function(){function e(e,t,i){this.document=e,this._maskService=t,this._config=i,this.maskExpression="",this.specialCharacters=[],this.patterns={},this.prefix="",this.suffix="",this.thousandSeparator=" ",this.decimalMarker=".",this.dropSpecialCharacters=null,this.hiddenInput=null,this.showMaskTyped=null,this.placeHolderCharacter=null,this.shownMaskExpression=null,this.showTemplate=null,this.clearIfNotMatch=null,this.validation=null,this.separatorLimit=null,this._maskValue="",this._position=null,this.onChange=function(e){},this.onTouch=function(){}}return e.prototype.ngOnChanges=function(e){var t=e.maskExpression,i=e.specialCharacters,s=e.patterns,r=e.prefix,a=e.suffix,n=e.thousandSeparator,o=e.decimalMarker,h=e.dropSpecialCharacters,l=e.hiddenInput,c=e.showMaskTyped,p=e.placeHolderCharacter,u=e.shownMaskExpression,f=e.showTemplate,m=e.clearIfNotMatch,d=e.validation,k=e.separatorLimit;if(t&&(this._maskValue=e.maskExpression.currentValue||""),i){if(!i.currentValue||!Array.isArray(i.currentValue))return;this._maskService.maskSpecialCharacters=e.specialCharacters.currentValue||[]}s&&(this._maskService.maskAvailablePatterns=s.currentValue),r&&(this._maskService.prefix=r.currentValue),a&&(this._maskService.suffix=a.currentValue),n&&(this._maskService.thousandSeparator=n.currentValue),o&&(this._maskService.decimalMarker=o.currentValue),h&&(this._maskService.dropSpecialCharacters=h.currentValue),l&&(this._maskService.hiddenInput=l.currentValue),c&&(this._maskService.showMaskTyped=c.currentValue),p&&(this._maskService.placeHolderCharacter=p.currentValue),u&&(this._maskService.shownMaskExpression=u.currentValue),f&&(this._maskService.showTemplate=f.currentValue),m&&(this._maskService.clearIfNotMatch=m.currentValue),d&&(this._maskService.validation=d.currentValue),k&&(this._maskService.separatorLimit=k.currentValue),this._applyMask()},e.prototype.validate=function(e){var t=e.value;if(!this._maskService.validation)return null;if(this._maskService.ipError)return{"Mask error":!0};if(this._maskValue.startsWith("separator"))return null;if(f.includes(this._maskValue))return null;if(this._maskService.clearIfNotMatch)return null;if(u.includes(this._maskValue))return this._validateTime(t);if(t&&t.toString().length>=1){var i=0,s=function(e){if(r._maskService.maskAvailablePatterns[e].optional&&!0===r._maskService.maskAvailablePatterns[e].optional){if(r._maskValue.indexOf(e)!==r._maskValue.lastIndexOf(e)){var s=r._maskValue.split("").filter(function(t){return t===e}).join("");i+=s.length}else-1!==r._maskValue.indexOf(e)&&i++;if(-1!==r._maskValue.indexOf(e)&&t.toString().length>=r._maskValue.indexOf(e))return{value:null};if(i===r._maskValue.length)return{value:null}}},r=this;for(var a in this._maskService.maskAvailablePatterns){var n=s(a);if("object"==typeof n)return n.value}if(1===this._maskValue.indexOf("{")&&t.toString().length===this._maskValue.length+Number(this._maskValue.split("{")[1].split("}")[0])-4)return null;if(1===this._maskValue.indexOf("*")||1===this._maskValue.indexOf("?"))return null;if(this._maskValue.indexOf("*")>1&&t.toString().length<this._maskValue.indexOf("*")||this._maskValue.indexOf("?")>1&&t.toString().length<this._maskValue.indexOf("?")||1===this._maskValue.indexOf("{"))return{"Mask error":!0};if(-1===this._maskValue.indexOf("*")||-1===this._maskValue.indexOf("?")){var o=this._maskService.dropSpecialCharacters?this._maskValue.length-this._maskService.checkSpecialCharAmount(this._maskValue)-i:this._maskValue.length-i;if(t.toString().length<o)return{"Mask error":!0}}}return null},e.prototype.onInput=function(e){var t=e.target;if(this._inputValue=t.value,this._maskValue){var i=1===t.selectionStart?t.selectionStart+this._maskService.prefix.length:t.selectionStart,s=0,r=!1;if(this._maskService.applyValueChanges(i,function(e,t){s=e,r=t}),this.document.activeElement===t){this._position=1===this._position&&1===this._inputValue.length?null:this._position;var a=this._position?this._inputValue.length+i+s:i+("Backspace"!==this._code||r?s:0);t.setSelectionRange(a,a),(this.maskExpression.includes("H")||this.maskExpression.includes("M"))&&0===s&&t.setSelectionRange(t.selectionStart+1,t.selectionStart+1),this._position=null}}else this.onChange(t.value)},e.prototype.onBlur=function(){this._maskService.clearIfNotMatchFn(),this.onTouch()},e.prototype.onFocus=function(e){var t=e.target;null!==t&&null!==t.selectionStart&&t.selectionStart===t.selectionEnd&&t.selectionStart>this._maskService.prefix.length&&38!==e.keyCode&&this._maskService.showMaskTyped&&(this._maskService.maskIsShown=this._maskService.showMaskInInput(),t.setSelectionRange&&this._maskService.prefix+this._maskService.maskIsShown===t.value?(t.focus(),t.setSelectionRange(0,0)):t.selectionStart>this._maskService.actualValue.length&&t.setSelectionRange(this._maskService.actualValue.length,this._maskService.actualValue.length));var i=t.value&&t.value!==this._maskService.prefix?t.value:this._maskService.prefix+this._maskService.maskIsShown;t.value!==i&&(t.value=i),(t.selectionStart||t.selectionEnd)<=this._maskService.prefix.length&&(t.selectionStart=this._maskService.prefix.length)},e.prototype.onKeyDown=function(e){this._code=e.code?e.code:e.key;var t=e.target;if(this._inputValue=t.value,38===e.keyCode&&e.preventDefault(),37===e.keyCode||8===e.keyCode||46===e.keyCode){if(8===e.keyCode&&0===t.value.length&&(t.selectionStart=t.selectionEnd),8===e.keyCode&&0!==t.selectionStart)if(this.specialCharacters=this.specialCharacters||this._config.specialCharacters,this.prefix.length>1&&t.selectionStart<=this.prefix.length)t.setSelectionRange(this.prefix.length,this.prefix.length);else{if(this._inputValue.length!==t.selectionStart&&1!==t.selectionStart)for(;this.specialCharacters.includes(this._inputValue[t.selectionStart-1].toString())&&(this.prefix.length>=1&&t.selectionStart>this.prefix.length||0===this.prefix.length);)t.setSelectionRange(t.selectionStart-1,t.selectionStart-1);this.suffixCheckOnPressDelete(e.keyCode,t)}this.suffixCheckOnPressDelete(e.keyCode,t),t.selectionStart<=this._maskService.prefix.length&&t.selectionEnd<=this._maskService.prefix.length&&e.preventDefault();var i=t.selectionStart;8!==e.keyCode||t.readOnly||0!==i||t.selectionEnd!==t.value.length||0===t.value.length||(this._position=this._maskService.prefix?this._maskService.prefix.length:0,this._maskService.applyMask(this._maskService.prefix,this._maskService.maskExpression,this._position))}this.suffix&&this.suffix.length>1&&this._inputValue.length-this.suffix.length<t.selectionStart&&t.setSelectionRange(this._inputValue.length-this.suffix.length,this._inputValue.length),this._maskService.selStart=t.selectionStart,this._maskService.selEnd=t.selectionEnd},e.prototype.writeValue=function(e){return t=this,i=void 0,r=function(){return n(this,function(t){return void 0===e&&(e=""),"number"==typeof e&&(e=String(e),e="."!==this.decimalMarker?e.replace(".",this.decimalMarker):e,this._maskService.isNumberValue=!0),e&&this._maskService.maskExpression||this._maskService.maskExpression&&(this._maskService.prefix||this._maskService.showMaskTyped)?this._maskService.formElementProperty=["value",this._maskService.applyMask(e,this._maskService.maskExpression)]:this._maskService.formElementProperty=["value",e],this._inputValue=e,[2]})},new((s=void 0)||(s=Promise))(function(e,a){function n(e){try{h(r.next(e))}catch(e){a(e)}}function o(e){try{h(r.throw(e))}catch(e){a(e)}}function h(t){t.done?e(t.value):new s(function(e){e(t.value)}).then(n,o)}h((r=r.apply(t,i||[])).next())});var t,i,s,r},e.prototype.registerOnChange=function(e){this.onChange=e,this._maskService.onChange=this.onChange},e.prototype.registerOnTouched=function(e){this.onTouch=e},e.prototype.suffixCheckOnPressDelete=function(e,t){46===e&&this.suffix.length>0&&this._inputValue.length-this.suffix.length<=t.selectionStart&&t.setSelectionRange(this._inputValue.length-this.suffix.length,this._inputValue.length),8===e&&(this.suffix.length>1&&this._inputValue.length-this.suffix.length<t.selectionStart&&t.setSelectionRange(this._inputValue.length-this.suffix.length,this._inputValue.length),1===this.suffix.length&&this._inputValue.length===t.selectionStart&&t.setSelectionRange(t.selectionStart-1,t.selectionStart-1))},e.prototype.setDisabledState=function(e){this._maskService.formElementProperty=["disabled",e]},e.prototype.onModelChange=function(e){e||(this._maskService.actualValue="")},e.prototype._repeatPatternSymbols=function(e){var t=this;return e.match(/{[0-9]+}/)&&e.split("").reduce(function(i,s,r){if(t._start="{"===s?r:t._start,"}"!==s)return t._maskService._findSpecialChar(s)?i+s:i;t._end=r;var a=Number(e.slice(t._start+1,t._end));return i+new Array(a+1).join(e[t._start-1])},"")||e},e.prototype._applyMask=function(){this._maskService.maskExpression=this._repeatPatternSymbols(this._maskValue||""),this._maskService.formElementProperty=["value",this._maskService.applyMask(this._inputValue,this._maskService.maskExpression)]},e.prototype._validateTime=function(e){var t=this._maskValue.split("").filter(function(e){return":"!==e}).length;return 0==+e[e.length-1]&&e.length<t?{"Mask error":!0}:e.length<=t-2?{"Mask error":!0}:null},e.decorators=[{type:t.Directive,args:[{selector:"[mask]",providers:[{provide:i.NG_VALUE_ACCESSOR,useExisting:t.forwardRef(function(){return e}),multi:!0},{provide:i.NG_VALIDATORS,useExisting:t.forwardRef(function(){return e}),multi:!0},d]}]}],e.ctorParameters=function(){return[{type:void 0,decorators:[{type:t.Inject,args:[s.DOCUMENT]}]},{type:d},{type:void 0,decorators:[{type:t.Inject,args:[h]}]}]},e.propDecorators={maskExpression:[{type:t.Input,args:["mask"]}],specialCharacters:[{type:t.Input}],patterns:[{type:t.Input}],prefix:[{type:t.Input}],suffix:[{type:t.Input}],thousandSeparator:[{type:t.Input}],decimalMarker:[{type:t.Input}],dropSpecialCharacters:[{type:t.Input}],hiddenInput:[{type:t.Input}],showMaskTyped:[{type:t.Input}],placeHolderCharacter:[{type:t.Input}],shownMaskExpression:[{type:t.Input}],showTemplate:[{type:t.Input}],clearIfNotMatch:[{type:t.Input}],validation:[{type:t.Input}],separatorLimit:[{type:t.Input}],onInput:[{type:t.HostListener,args:["input",["$event"]]}],onBlur:[{type:t.HostListener,args:["blur"]}],onFocus:[{type:t.HostListener,args:["click",["$event"]]}],onKeyDown:[{type:t.HostListener,args:["keydown",["$event"]]}],onModelChange:[{type:t.HostListener,args:["ngModelChange",["$event"]]}]},e}();var g=function(){function e(e){this._maskService=e}return e.prototype.transform=function(e,t){return e||"number"==typeof e?"string"==typeof t?this._maskService.applyMask(""+e,t):this._maskService.applyMaskWithPattern(""+e,t):""},e.decorators=[{type:t.Pipe,args:[{name:"mask",pure:!0}]}],e.ctorParameters=function(){return[{type:m}]},e}();var v=function(){function e(){}return e.forRoot=function(t){return{ngModule:e,providers:[{provide:l,useValue:t},{provide:c,useValue:p},{provide:h,useFactory:_,deps:[c,l]},m]}},e.forChild=function(t){return{ngModule:e}},e.decorators=[{type:t.NgModule,args:[{exports:[k,g],declarations:[k,g]}]}],e}();function _(e,t){return t instanceof Function?a({},e,t()):a({},e,t)}e.MaskApplierService=m,e.MaskDirective=k,e.MaskPipe=g,e.MaskService=d,e.NgxMaskModule=v,e._configFactory=_,e.ɵb=h,e.ɵc=l,e.ɵd=c,e.ɵe=p,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/forms"),require("@angular/common")):"function"==typeof define&&define.amd?define("ngx-mask",["exports","@angular/core","@angular/forms","@angular/common"],t):t((e=e||self)["ngx-mask"]={},e.ng.core,e.ng.forms,e.ng.common)}(this,function(e,t,i,s){"use strict";var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])})(e,t)};var a=function(){return(a=Object.assign||function(e){for(var t,i=1,s=arguments.length;i<s;i++)for(var r in t=arguments[i])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};function n(e,t){var i,s,r,a,n={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return a={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function o(a){return function(o){return function(a){if(i)throw new TypeError("Generator is already executing.");for(;n;)try{if(i=1,s&&(r=2&a[0]?s.return:a[0]?s.throw||((r=s.return)&&r.call(s),0):s.next)&&!(r=r.call(s,a[1])).done)return r;switch(s=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return n.label++,{value:a[1],done:!1};case 5:n.label++,s=a[1],a=[0];continue;case 7:a=n.ops.pop(),n.trys.pop();continue;default:if(!(r=(r=n.trys).length>0&&r[r.length-1])&&(6===a[0]||2===a[0])){n=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){n.label=a[1];break}if(6===a[0]&&n.label<r[1]){n.label=r[1],r=a;break}if(r&&n.label<r[2]){n.label=r[2],n.ops.push(a);break}r[2]&&n.ops.pop(),n.trys.pop();continue}a=t.call(e,n)}catch(e){a=[6,e],s=0}finally{i=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,o])}}}function o(e,t){var i="function"==typeof Symbol&&e[Symbol.iterator];if(!i)return e;var s,r,a=i.call(e),n=[];try{for(;(void 0===t||t-- >0)&&!(s=a.next()).done;)n.push(s.value)}catch(e){r={error:e}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}return n}var l=new t.InjectionToken("config"),h=new t.InjectionToken("NEW_CONFIG"),c=new t.InjectionToken("INITIAL_CONFIG"),u={suffix:"",prefix:"",thousandSeparator:" ",decimalMarker:".",clearIfNotMatch:!1,showTemplate:!1,showMaskTyped:!1,placeHolderCharacter:"_",dropSpecialCharacters:!0,hiddenInput:void 0,shownMaskExpression:"",separatorLimit:"",allowNegativeNumbers:!1,validation:!0,specialCharacters:["-","/","(",")",".",":"," ","+",",","@","[","]",'"',"'"],patterns:{0:{pattern:new RegExp("\\d")},9:{pattern:new RegExp("\\d"),optional:!0},X:{pattern:new RegExp("\\d"),symbol:"*"},A:{pattern:new RegExp("[a-zA-Z0-9]")},S:{pattern:new RegExp("[a-zA-Z]")},d:{pattern:new RegExp("\\d")},m:{pattern:new RegExp("\\d")},M:{pattern:new RegExp("\\d")},H:{pattern:new RegExp("\\d")},h:{pattern:new RegExp("\\d")},s:{pattern:new RegExp("\\d")}}},p=["Hh:m0:s0","Hh:m0","m0:s0"],f=["percent","Hh","s0","m0","separator","d0/M0/0000","d0/M0","d0","M0"],m=function(){function e(e){var t=this;this._config=e,this.maskExpression="",this.actualValue="",this.shownMaskExpression="",this._formatWithSeparators=function(e,i,s,r){var a=e.split(s),n=a.length>1?""+s+a[1]:"",o=a[0],l=t.separatorLimit.replace(/\s/g,"");l&&+l&&(o="-"===o[0]?"-"+o.slice(1,o.length).slice(0,l.length):o.slice(0,l.length));for(var h=/(\d+)(\d{3})/;h.test(o);)o=o.replace(h,"$1"+i+"$2");return void 0===r?o+n:0===r?o:o+n.substr(0,r+1)},this.percentage=function(e){return Number(e)>=0&&Number(e)<=100},this.getPrecision=function(e){var t=e.split(".");return t.length>1?Number(t[t.length-1]):1/0},this.checkInputPrecision=function(e,i,s){if(i<1/0){var r=new RegExp(t._charToRegExpExpression(s)+"\\d{"+i+"}.*$"),a=e.match(r);a&&a[0].length-1>i?e=e.substring(0,e.length-1):0===i&&e.endsWith(s)&&(e=e.substring(0,e.length-1))}return e},this._shift=new Set,this.clearIfNotMatch=this._config.clearIfNotMatch,this.dropSpecialCharacters=this._config.dropSpecialCharacters,this.maskSpecialCharacters=this._config.specialCharacters,this.maskAvailablePatterns=this._config.patterns,this.prefix=this._config.prefix,this.suffix=this._config.suffix,this.thousandSeparator=this._config.thousandSeparator,this.decimalMarker=this._config.decimalMarker,this.hiddenInput=this._config.hiddenInput,this.showMaskTyped=this._config.showMaskTyped,this.placeHolderCharacter=this._config.placeHolderCharacter,this.validation=this._config.validation,this.separatorLimit=this._config.separatorLimit,this.allowNegativeNumbers=this._config.allowNegativeNumbers}return e.prototype.applyMaskWithPattern=function(e,t){var i=o(t,2),s=i[0],r=i[1];return this.customPattern=r,this.applyMask(e,s)},e.prototype.applyMask=function(e,t,i,s){if(void 0===i&&(i=0),void 0===s&&(s=function(){}),null==e||void 0===t)return"";var r=0,a="",n=!1,o=!1,l=1,h=!1;e.slice(0,this.prefix.length)===this.prefix&&(e=e.slice(this.prefix.length,e.length)),this.suffix&&e.endsWith(this.suffix)&&(e=e.slice(0,e.length-this.suffix.length));var c=e.toString().split("");if("IP"===t&&(this.ipError=!!(c.filter(function(e){return"."===e}).length<3&&c.length<7),t="099.099.099.099"),t.startsWith("percent")){if(e.match("[a-z]|[A-Z]")||e.match(/[-!$%^&*()_+|~=`{}\[\]:";'<>?,\/]/)){e=this._stripToDecimal(e);var u=this.getPrecision(t);e=this.checkInputPrecision(e,u,".")}if(e.indexOf(".")>0&&!this.percentage(e.substring(0,e.indexOf(".")))){var p=e.substring(0,e.indexOf(".")-1);e=""+p+e.substring(e.indexOf("."),e.length)}a=this.percentage(e)?e:e.substring(0,e.length-1)}else if(t.startsWith("separator")){(e.match("[wа-яА-Я]")||e.match("[ЁёА-я]")||e.match("[a-z]|[A-Z]")||e.match(/[-@#!$%\\^&*()_£¬'+|~=`{}\[\]:";<>.?\/]/)||e.match("[^A-Za-z0-9,]"))&&(e=this._stripToDecimal(e)),e=e.length>1&&"0"===e[0]&&e[1]!==this.decimalMarker?e.slice(1,e.length):e;var f=this._charToRegExpExpression(this.thousandSeparator),m=this._charToRegExpExpression(this.decimalMarker),d='@#!$%^&*()_+|~=`{}\\[\\]:\\s,";<>?\\/'.replace(f,"").replace(m,""),k=new RegExp("["+d+"]");e.match(k)&&(e=e.substring(0,e.length-1));u=this.getPrecision(t);var g=(e=this.checkInputPrecision(e,u,this.decimalMarker)).replace(new RegExp(f,"g"),""),_=(a=this._formatWithSeparators(g,this.thousandSeparator,this.decimalMarker,u)).indexOf(",")-e.indexOf(",");if((x=a.length-e.length)>0&&","!==a[i]){o=!0;var v=0;do{this._shift.add(i+v),v++}while(v<x)}else 0!==_&&i>0&&!(a.indexOf(",")>=i&&i>3)||!(a.indexOf(".")>=i&&i>3)&&x<=0?(this._shift.clear(),o=!0,l=x,i+=x,this._shift.add(i)):this._shift.clear()}else for(var S=0,y=c[0];S<c.length&&r!==t.length;y=c[++S])if(this._checkSymbolMask(y,t[r])&&"?"===t[r+1])a+=y,r+=2;else if("*"===t[r+1]&&n&&this._checkSymbolMask(y,t[r+2]))a+=y,r+=3,n=!1;else if(this._checkSymbolMask(y,t[r])&&"*"===t[r+1])a+=y,n=!0;else if("?"===t[r+1]&&this._checkSymbolMask(y,t[r+2]))a+=y,r+=3;else if(this._checkSymbolMask(y,t[r])||this.hiddenInput&&this.maskAvailablePatterns[t[r]]&&this.maskAvailablePatterns[t[r]].symbol===y){if("H"===t[r]&&Number(y)>2){r+=1;var x=/[*?]/g.test(t.slice(0,r))?c.length:r;this._shift.add(x+this.prefix.length||0),S--;continue}if("h"===t[r]&&"2"===a&&Number(y)>3){r+=1,S--;continue}if("m"===t[r]&&Number(y)>5){r+=1;x=/[*?]/g.test(t.slice(0,r))?c.length:r;this._shift.add(x+this.prefix.length||0),S--;continue}if("s"===t[r]&&Number(y)>5){r+=1;x=/[*?]/g.test(t.slice(0,r))?c.length:r;this._shift.add(x+this.prefix.length||0),S--;continue}if("d"===t[r]&&(Number(e.slice(r,r+2))>31||"/"===e[r+1])){r+=1;x=/[*?]/g.test(t.slice(0,r))?c.length:r;this._shift.add(x+this.prefix.length||0),S--;continue}if("M"===t[r]){var b=0===r&&(Number(y)>2||Number(e.slice(r,r+2))>12||"/"===e[r+1]),E=e.slice(r-3,r-1).includes("/")&&("/"===e[r-2]&&Number(e.slice(r-1,r+1))>12&&"/"!==e[r]||"/"===e[r]||"/"===e[r-3]&&Number(e.slice(r-2,r))>12&&"/"!==e[r-1]||"/"===e[r-1]),C=Number(e.slice(r-3,r-1))<=31&&!e.slice(r-3,r-1).includes("/")&&"/"===e[r-1]&&(Number(e.slice(r,r+2))>12||"/"===e[r+1]),M=Number(e.slice(r-3,r-1))>31&&!e.slice(r-3,r-1).includes("/")&&!e.slice(r-2,r).includes("/")&&Number(e.slice(r-2,r))>12,w=Number(e.slice(r-3,r-1))<=31&&!e.slice(r-3,r-1).includes("/")&&"/"!==e[r-1]&&Number(e.slice(r-1,r+1))>12;if(b||E||C||M||w){r+=1;x=/[*?]/g.test(t.slice(0,r))?c.length:r;this._shift.add(x+this.prefix.length||0),S--;continue}}a+=y,r++}else if(-1!==this.maskSpecialCharacters.indexOf(t[r])){a+=t[r],r++;x=/[*?]/g.test(t.slice(0,r))?c.length:r;this._shift.add(x+this.prefix.length||0),S--}else this.maskSpecialCharacters.indexOf(y)>-1&&this.maskAvailablePatterns[t[r]]&&this.maskAvailablePatterns[t[r]].optional?(c[r]&&"099.099.099.099"!==t&&(a+=c[r]),r++,S--):"*"===this.maskExpression[r+1]&&this._findSpecialChar(this.maskExpression[r+2])&&this._findSpecialChar(y)===this.maskExpression[r+2]&&n?(r+=3,a+=y):"?"===this.maskExpression[r+1]&&this._findSpecialChar(this.maskExpression[r+2])&&this._findSpecialChar(y)===this.maskExpression[r+2]&&n?(r+=3,a+=y):this.showMaskTyped&&this.maskSpecialCharacters.indexOf(y)<0&&y!==this.placeHolderCharacter&&(h=!0);a.length+1===t.length&&-1!==this.maskSpecialCharacters.indexOf(t[t.length-1])&&(a+=t[t.length-1]);for(var V=i+1;this._shift.has(V);)l++,V++;var I=this._shift.has(i)?l:0;h&&I--,s(I,o),l<0&&this._shift.clear();var N=""+this.prefix+a+this.suffix;return 0===a.length&&(N=""+this.prefix+a),N},e.prototype._findSpecialChar=function(e){return this.maskSpecialCharacters.find(function(t){return t===e})},e.prototype._checkSymbolMask=function(e,t){return this.maskAvailablePatterns=this.customPattern?this.customPattern:this.maskAvailablePatterns,this.maskAvailablePatterns[t]&&this.maskAvailablePatterns[t].pattern&&this.maskAvailablePatterns[t].pattern.test(e)},e.prototype._stripToDecimal=function(e){return e.split("").filter(function(e,t){return e.match("^-?\\d")||"."===e||","===e||"-"===e&&0===t}).join("")},e.prototype._charToRegExpExpression=function(e){return" "===e?"\\s":"[\\^$.|?*+()".indexOf(e)>=0?"\\"+e:e},e.decorators=[{type:t.Injectable}],e.ctorParameters=function(){return[{type:void 0,decorators:[{type:t.Inject,args:[l]}]}]},e}();var d=function(e){function i(t,i,s,r){var a=e.call(this,i)||this;return a.document=t,a._config=i,a._elementRef=s,a._renderer=r,a.maskExpression="",a.isNumberValue=!1,a.placeHolderCharacter="_",a.maskIsShown="",a.selStart=null,a.selEnd=null,a.onChange=function(e){},a._formElement=a._elementRef.nativeElement,a}return function(e,t){function i(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}(i,e),i.prototype.applyMask=function(t,i,s,r){var a=this;if(void 0===s&&(s=0),void 0===r&&(r=function(){}),!i)return t;if(this.maskIsShown=this.showMaskTyped?this.showMaskInInput():"","IP"===this.maskExpression&&this.showMaskTyped&&(this.maskIsShown=this.showMaskInInput(t||"#")),!t&&this.showMaskTyped)return this.formControlResult(this.prefix),this.prefix+this.maskIsShown;var n=t&&"number"==typeof this.selStart?t[this.selStart]:"",o="";if(void 0!==this.hiddenInput){var l=this.actualValue.split("");""!==t&&l.length?"number"==typeof this.selStart&&"number"==typeof this.selEnd&&(t.length>l.length?l.splice(this.selStart,0,n):t.length<l.length&&(l.length-t.length==1?l.splice(this.selStart-1,1):l.splice(this.selStart,this.selEnd-this.selStart))):l=[],o=this.actualValue.length?this.shiftTypedSymbols(l.join("")):t}o=Boolean(o)&&o.length?o:t;var h=e.prototype.applyMask.call(this,o,i,s,r);if(this.actualValue=this.getActualValue(h),"."===this.thousandSeparator&&"."===this.decimalMarker&&(this.decimalMarker=","),this.maskExpression.startsWith("separator")&&!0===this.dropSpecialCharacters&&(this.maskSpecialCharacters=this.maskSpecialCharacters.filter(function(e){return e!==a.decimalMarker})),this.formControlResult(h),!this.showMaskTyped)return this.hiddenInput&&h&&h.length?this.hideInput(h,this.maskExpression):h;var c=h.length,u=this.prefix+this.maskIsShown;return h+("IP"===this.maskExpression?u:u.slice(c))},i.prototype.applyValueChanges=function(e,t){void 0===e&&(e=0),void 0===t&&(t=function(){}),this._formElement.value=this.applyMask(this._formElement.value,this.maskExpression,e,t),this._formElement!==this.document.activeElement&&this.clearIfNotMatchFn()},i.prototype.hideInput=function(e,t){var i=this;return e.split("").map(function(e,s){return i.maskAvailablePatterns&&i.maskAvailablePatterns[t[s]]&&i.maskAvailablePatterns[t[s]].symbol?i.maskAvailablePatterns[t[s]].symbol:e}).join("")},i.prototype.getActualValue=function(e){var t=this,i=e.split("").filter(function(e,i){return t._checkSymbolMask(e,t.maskExpression[i])||t.maskSpecialCharacters.includes(t.maskExpression[i])&&e===t.maskExpression[i]});return i.join("")===e?i.join(""):e},i.prototype.shiftTypedSymbols=function(e){var t=this,i="";return(e&&e.split("").map(function(s,r){if(t.maskSpecialCharacters.includes(e[r+1])&&e[r+1]!==t.maskExpression[r+1])return i=s,e[r+1];if(i.length){var a=i;return i="",a}return s})||[]).join("")},i.prototype.showMaskInInput=function(e){if(this.showMaskTyped&&this.shownMaskExpression){if(this.maskExpression.length!==this.shownMaskExpression.length)throw new Error("Mask expression must match mask placeholder length");return this.shownMaskExpression}return this.showMaskTyped?e?this._checkForIp(e):this.maskExpression.replace(/\w/g,this.placeHolderCharacter):""},i.prototype.clearIfNotMatchFn=function(){this.clearIfNotMatch&&this.prefix.length+this.maskExpression.length+this.suffix.length!==this._formElement.value.replace(/_/g,"").length&&(this.formElementProperty=["value",""],this.applyMask(this._formElement.value,this.maskExpression))},Object.defineProperty(i.prototype,"formElementProperty",{set:function(e){var t=o(e,2),i=t[0],s=t[1];this._renderer.setProperty(this._formElement,i,s)},enumerable:!0,configurable:!0}),i.prototype.checkSpecialCharAmount=function(e){var t=this;return e.split("").filter(function(e){return t._findSpecialChar(e)}).length},i.prototype._checkForIp=function(e){if("#"===e)return this.placeHolderCharacter+"."+this.placeHolderCharacter+"."+this.placeHolderCharacter+"."+this.placeHolderCharacter;for(var t=[],i=0;i<e.length;i++)e[i].match("\\d")&&t.push(e[i]);return t.length<=3?this.placeHolderCharacter+"."+this.placeHolderCharacter+"."+this.placeHolderCharacter:t.length>3&&t.length<=6?this.placeHolderCharacter+"."+this.placeHolderCharacter:t.length>6&&t.length<=9?this.placeHolderCharacter:(t.length>9&&t.length,"")},i.prototype.formControlResult=function(e){Array.isArray(this.dropSpecialCharacters)?this.onChange(this._removeMask(this._removeSuffix(this._removePrefix(e)),this.dropSpecialCharacters)):this.dropSpecialCharacters?this.onChange(this._checkSymbols(e)):this.onChange(this._removeSuffix(this._removePrefix(e)))},i.prototype._removeMask=function(e,t){return e?e.replace(this._regExpForRemove(t),""):e},i.prototype._removePrefix=function(e){return this.prefix&&e?e.replace(this.prefix,""):e},i.prototype._removeSuffix=function(e){return this.suffix&&e?e.replace(this.suffix,""):e},i.prototype._retrieveSeparatorValue=function(e){return this._removeMask(this._removeSuffix(this._removePrefix(e)),this.maskSpecialCharacters)},i.prototype._regExpForRemove=function(e){return new RegExp(e.map(function(e){return"\\"+e}).join("|"),"gi")},i.prototype._checkSymbols=function(e){if(""===e)return e;var t=this._retrieveSeparatorPrecision(this.maskExpression),i=this._retrieveSeparatorValue(e);return"."!==this.decimalMarker&&(i=i.replace(this.decimalMarker,".")),this.isNumberValue?t?e===this.decimalMarker?null:this._checkPrecision(this.maskExpression,i):Number(i):i},i.prototype._retrieveSeparatorPrecision=function(e){var t=e.match(new RegExp("^separator\\.([^d]*)"));return t?Number(t[1]):null},i.prototype._checkPrecision=function(e,t){return e.indexOf("2")>0?Number(t).toFixed(2):Number(t)},i.decorators=[{type:t.Injectable}],i.ctorParameters=function(){return[{type:void 0,decorators:[{type:t.Inject,args:[s.DOCUMENT]}]},{type:void 0,decorators:[{type:t.Inject,args:[l]}]},{type:t.ElementRef},{type:t.Renderer2}]},i}(m);var k=function(){function e(e,t,i){this.document=e,this._maskService=t,this._config=i,this.maskExpression="",this.specialCharacters=[],this.patterns={},this.prefix="",this.suffix="",this.thousandSeparator=" ",this.decimalMarker=".",this.dropSpecialCharacters=null,this.hiddenInput=null,this.showMaskTyped=null,this.placeHolderCharacter=null,this.shownMaskExpression=null,this.showTemplate=null,this.clearIfNotMatch=null,this.validation=null,this.separatorLimit=null,this.allowNegativeNumbers=null,this._maskValue="",this._position=null,this.onChange=function(e){},this.onTouch=function(){}}return e.prototype.ngOnChanges=function(e){var t=e.maskExpression,i=e.specialCharacters,s=e.patterns,r=e.prefix,a=e.suffix,n=e.thousandSeparator,o=e.decimalMarker,l=e.dropSpecialCharacters,h=e.hiddenInput,c=e.showMaskTyped,u=e.placeHolderCharacter,p=e.shownMaskExpression,f=e.showTemplate,m=e.clearIfNotMatch,d=e.validation,k=e.separatorLimit,g=e.allowNegativeNumbers;if(t&&(this._maskValue=e.maskExpression.currentValue||""),i){if(!i.currentValue||!Array.isArray(i.currentValue))return;this._maskService.maskSpecialCharacters=e.specialCharacters.currentValue||[]}s&&s.currentValue&&(this._maskService.maskAvailablePatterns=s.currentValue),r&&(this._maskService.prefix=r.currentValue),a&&(this._maskService.suffix=a.currentValue),n&&(this._maskService.thousandSeparator=n.currentValue),o&&(this._maskService.decimalMarker=o.currentValue),l&&(this._maskService.dropSpecialCharacters=l.currentValue),h&&(this._maskService.hiddenInput=h.currentValue),c&&(this._maskService.showMaskTyped=c.currentValue),u&&(this._maskService.placeHolderCharacter=u.currentValue),p&&(this._maskService.shownMaskExpression=p.currentValue),f&&(this._maskService.showTemplate=f.currentValue),m&&(this._maskService.clearIfNotMatch=m.currentValue),d&&(this._maskService.validation=d.currentValue),k&&(this._maskService.separatorLimit=k.currentValue),g&&(this._maskService.maskSpecialCharacters=this._maskService.maskSpecialCharacters.filter(function(e){return"-"!==e})),this._applyMask()},e.prototype.validate=function(e){var t=e.value;if(!this._maskService.validation)return null;if(this._maskService.ipError)return this._createValidationError(t);if(this._maskValue.startsWith("separator"))return null;if(f.includes(this._maskValue))return null;if(this._maskService.clearIfNotMatch)return null;if(p.includes(this._maskValue))return this._validateTime(t);if(t&&t.toString().length>=1){var i=0,s=function(e){if(r._maskService.maskAvailablePatterns[e].optional&&!0===r._maskService.maskAvailablePatterns[e].optional){if(r._maskValue.indexOf(e)!==r._maskValue.lastIndexOf(e)){var s=r._maskValue.split("").filter(function(t){return t===e}).join("");i+=s.length}else-1!==r._maskValue.indexOf(e)&&i++;if(-1!==r._maskValue.indexOf(e)&&t.toString().length>=r._maskValue.indexOf(e))return{value:null};if(i===r._maskValue.length)return{value:null}}},r=this;for(var a in this._maskService.maskAvailablePatterns){var n=s(a);if("object"==typeof n)return n.value}if(1===this._maskValue.indexOf("{")&&t.toString().length===this._maskValue.length+Number(this._maskValue.split("{")[1].split("}")[0])-4)return null;if(1===this._maskValue.indexOf("*")||1===this._maskValue.indexOf("?"))return null;if(this._maskValue.indexOf("*")>1&&t.toString().length<this._maskValue.indexOf("*")||this._maskValue.indexOf("?")>1&&t.toString().length<this._maskValue.indexOf("?")||1===this._maskValue.indexOf("{"))return this._createValidationError(t);if(-1===this._maskValue.indexOf("*")||-1===this._maskValue.indexOf("?")){var o=this._maskService.dropSpecialCharacters?this._maskValue.length-this._maskService.checkSpecialCharAmount(this._maskValue)-i:this._maskValue.length-i;if(t.toString().length<o)return this._createValidationError(t)}}return null},e.prototype.onInput=function(e){var t=e.target;if(this._inputValue=t.value,this._maskValue){var i=1===t.selectionStart?t.selectionStart+this._maskService.prefix.length:t.selectionStart,s=0,r=!1;if(this._maskService.applyValueChanges(i,function(e,t){s=e,r=t}),this.document.activeElement===t){this._position=1===this._position&&1===this._inputValue.length?null:this._position;var a=this._position?this._inputValue.length+i+s:i+("Backspace"!==this._code||r?s:0);a>this._getActualInputLength()&&(a=this._getActualInputLength()),t.setSelectionRange(a,a),(this.maskExpression.includes("H")||this.maskExpression.includes("M"))&&0===s&&t.setSelectionRange(t.selectionStart+1,t.selectionStart+1),this._position=null}}else this.onChange(t.value)},e.prototype.onBlur=function(){this._maskService.clearIfNotMatchFn(),this.onTouch()},e.prototype.onFocus=function(e){var t=e.target;null!==t&&null!==t.selectionStart&&t.selectionStart===t.selectionEnd&&t.selectionStart>this._maskService.prefix.length&&38!==e.keyCode&&this._maskService.showMaskTyped&&(this._maskService.maskIsShown=this._maskService.showMaskInInput(),t.setSelectionRange&&this._maskService.prefix+this._maskService.maskIsShown===t.value?(t.focus(),t.setSelectionRange(0,0)):t.selectionStart>this._maskService.actualValue.length&&t.setSelectionRange(this._maskService.actualValue.length,this._maskService.actualValue.length));var i=t.value&&t.value!==this._maskService.prefix?t.value:this._maskService.prefix+this._maskService.maskIsShown;t.value!==i&&(t.value=i),(t.selectionStart||t.selectionEnd)<=this._maskService.prefix.length?t.selectionStart=this._maskService.prefix.length:t.selectionEnd>this._getActualInputLength()&&(t.selectionEnd=this._getActualInputLength())},e.prototype.onKeyDown=function(e){this._code=e.code?e.code:e.key;var t=e.target;if(this._inputValue=t.value,38===e.keyCode&&e.preventDefault(),37===e.keyCode||8===e.keyCode||46===e.keyCode){if(8===e.keyCode&&0===t.value.length&&(t.selectionStart=t.selectionEnd),8===e.keyCode&&0!==t.selectionStart)if(this.specialCharacters=this.specialCharacters||this._config.specialCharacters,this.prefix.length>1&&t.selectionStart<=this.prefix.length)t.setSelectionRange(this.prefix.length,this.prefix.length);else{if(this._inputValue.length!==t.selectionStart&&1!==t.selectionStart)for(;this.specialCharacters.includes(this._inputValue[t.selectionStart-1].toString())&&(this.prefix.length>=1&&t.selectionStart>this.prefix.length||0===this.prefix.length);)t.setSelectionRange(t.selectionStart-1,t.selectionStart-1);this.suffixCheckOnPressDelete(e.keyCode,t)}this.suffixCheckOnPressDelete(e.keyCode,t),this._maskService.prefix.length&&t.selectionStart<=this._maskService.prefix.length&&t.selectionEnd<=this._maskService.prefix.length&&e.preventDefault();var i=t.selectionStart;8!==e.keyCode||t.readOnly||0!==i||t.selectionEnd!==t.value.length||0===t.value.length||(this._position=this._maskService.prefix?this._maskService.prefix.length:0,this._maskService.applyMask(this._maskService.prefix,this._maskService.maskExpression,this._position))}this.suffix&&this.suffix.length>1&&this._inputValue.length-this.suffix.length<t.selectionStart?t.setSelectionRange(this._inputValue.length-this.suffix.length,this._inputValue.length):(65===e.keyCode&&!0===e.ctrlKey||65===e.keyCode&&!0===e.metaKey)&&(t.setSelectionRange(0,this._getActualInputLength()),e.preventDefault()),this._maskService.selStart=t.selectionStart,this._maskService.selEnd=t.selectionEnd},e.prototype.writeValue=function(e){return t=this,i=void 0,r=function(){return n(this,function(t){return void 0===e&&(e=""),"number"==typeof e&&(e=String(e),e="."!==this.decimalMarker?e.replace(".",this.decimalMarker):e,this._maskService.isNumberValue=!0),e&&this._maskService.maskExpression||this._maskService.maskExpression&&(this._maskService.prefix||this._maskService.showMaskTyped)?this._maskService.formElementProperty=["value",this._maskService.applyMask(e,this._maskService.maskExpression)]:this._maskService.formElementProperty=["value",e],this._inputValue=e,[2]})},new((s=void 0)||(s=Promise))(function(e,a){function n(e){try{l(r.next(e))}catch(e){a(e)}}function o(e){try{l(r.throw(e))}catch(e){a(e)}}function l(t){t.done?e(t.value):new s(function(e){e(t.value)}).then(n,o)}l((r=r.apply(t,i||[])).next())});var t,i,s,r},e.prototype.registerOnChange=function(e){this.onChange=e,this._maskService.onChange=this.onChange},e.prototype.registerOnTouched=function(e){this.onTouch=e},e.prototype.suffixCheckOnPressDelete=function(e,t){46===e&&this.suffix.length>0&&this._inputValue.length-this.suffix.length<=t.selectionStart&&t.setSelectionRange(this._inputValue.length-this.suffix.length,this._inputValue.length),8===e&&(this.suffix.length>1&&this._inputValue.length-this.suffix.length<t.selectionStart&&t.setSelectionRange(this._inputValue.length-this.suffix.length,this._inputValue.length),1===this.suffix.length&&this._inputValue.length===t.selectionStart&&t.setSelectionRange(t.selectionStart-1,t.selectionStart-1))},e.prototype.setDisabledState=function(e){this._maskService.formElementProperty=["disabled",e]},e.prototype.onModelChange=function(e){e||(this._maskService.actualValue="")},e.prototype._repeatPatternSymbols=function(e){var t=this;return e.match(/{[0-9]+}/)&&e.split("").reduce(function(i,s,r){if(t._start="{"===s?r:t._start,"}"!==s)return t._maskService._findSpecialChar(s)?i+s:i;t._end=r;var a=Number(e.slice(t._start+1,t._end));return i+new Array(a+1).join(e[t._start-1])},"")||e},e.prototype._applyMask=function(){this._maskService.maskExpression=this._repeatPatternSymbols(this._maskValue||""),this._maskService.formElementProperty=["value",this._maskService.applyMask(this._inputValue,this._maskService.maskExpression)]},e.prototype._validateTime=function(e){var t=this._maskValue.split("").filter(function(e){return":"!==e}).length;return null===e||0===e.length?null:0==+e[e.length-1]&&e.length<t||e.length<=t-2?this._createValidationError(e):null},e.prototype._getActualInputLength=function(){return this._maskService.actualValue.length||this._maskService.actualValue.length+this._maskService.prefix.length},e.prototype._createValidationError=function(e){return{mask:{requiredMask:this._maskValue,actualValue:e}}},e.decorators=[{type:t.Directive,args:[{selector:"[mask]",providers:[{provide:i.NG_VALUE_ACCESSOR,useExisting:t.forwardRef(function(){return e}),multi:!0},{provide:i.NG_VALIDATORS,useExisting:t.forwardRef(function(){return e}),multi:!0},d]}]}],e.ctorParameters=function(){return[{type:void 0,decorators:[{type:t.Inject,args:[s.DOCUMENT]}]},{type:d},{type:void 0,decorators:[{type:t.Inject,args:[l]}]}]},e.propDecorators={maskExpression:[{type:t.Input,args:["mask"]}],specialCharacters:[{type:t.Input}],patterns:[{type:t.Input}],prefix:[{type:t.Input}],suffix:[{type:t.Input}],thousandSeparator:[{type:t.Input}],decimalMarker:[{type:t.Input}],dropSpecialCharacters:[{type:t.Input}],hiddenInput:[{type:t.Input}],showMaskTyped:[{type:t.Input}],placeHolderCharacter:[{type:t.Input}],shownMaskExpression:[{type:t.Input}],showTemplate:[{type:t.Input}],clearIfNotMatch:[{type:t.Input}],validation:[{type:t.Input}],separatorLimit:[{type:t.Input}],allowNegativeNumbers:[{type:t.Input}],onInput:[{type:t.HostListener,args:["input",["$event"]]}],onBlur:[{type:t.HostListener,args:["blur"]}],onFocus:[{type:t.HostListener,args:["click",["$event"]]}],onKeyDown:[{type:t.HostListener,args:["keydown",["$event"]]}],onModelChange:[{type:t.HostListener,args:["ngModelChange",["$event"]]}]},e}();var g=function(){function e(e){this._maskService=e}return e.prototype.transform=function(e,t,i){return void 0===i&&(i=null),e||"number"==typeof e?(i&&(this._maskService.thousandSeparator=i),"string"==typeof t?this._maskService.applyMask(""+e,t):this._maskService.applyMaskWithPattern(""+e,t)):""},e.decorators=[{type:t.Pipe,args:[{name:"mask",pure:!0}]}],e.ctorParameters=function(){return[{type:m}]},e}();var _=function(){function e(){}return e.forRoot=function(t){return{ngModule:e,providers:[{provide:h,useValue:t},{provide:c,useValue:u},{provide:l,useFactory:v,deps:[c,h]},m]}},e.forChild=function(t){return{ngModule:e}},e.decorators=[{type:t.NgModule,args:[{exports:[k,g],declarations:[k,g]}]}],e}();function v(e,t){return t instanceof Function?a({},e,t()):a({},e,t)}var S="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};S.KeyboardEvent||(S.KeyboardEvent=function(e,t){}),e.INITIAL_CONFIG=c,e.MaskApplierService=m,e.MaskDirective=k,e.MaskPipe=g,e.MaskService=d,e.NEW_CONFIG=h,e.NgxMaskModule=_,e._configFactory=v,e.config=l,e.initialConfig=u,e.timeMasks=p,e.withoutValidation=f,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
2
2
|
//# sourceMappingURL=ngx-mask.umd.min.js.map
|