UNPKG

angular-input-masks

Version:
1 lines 12.8 kB
!function a(u,s,l){function o(r,e){if(!s[r]){if(!u[r]){var i="function"==typeof require&&require;if(!e&&i)return i(r,!0);if(c)return c(r,!0);var n=new Error("Cannot find module '"+r+"'");throw n.code="MODULE_NOT_FOUND",n}var t=s[r]={exports:{}};u[r][0].call(t.exports,function(e){return o(u[r][1][e]||e)},t,t.exports,a,u,s,l)}return s[r].exports}for(var c="function"==typeof require&&require,e=0;e<l.length;e++)o(l[e]);return o}({1:[function(e,r,i){"use strict";r.exports=angular.module("ui.utils.masks",[e("./global/global-masks"),e("./fr/fr-masks")]).name},{"./fr/fr-masks":2,"./global/global-masks":6}],2:[function(e,r,i){"use strict";var n=angular.module("ui.utils.masks.fr",[]).directive("uiFrPhoneNumberMask",e("./phone/fr-phone"));r.exports=n.name},{"./phone/fr-phone":3}],3:[function(e,r,i){"use strict";var n=e("string-mask"),t=e("../../helpers/mask-factory"),a=new n("00 00 00 00 00");r.exports=t({clearValue:function(e){return e.toString().replace(/[^0-9]/g,"").slice(0,10)},format:function(e){return(a.apply(e)||"").trim().replace(/[^0-9]$/,"")},validations:{frPhoneNumber:function(e){return 10===(e&&e.toString().length)}}})},{"../../helpers/mask-factory":12,"string-mask":void 0}],4:[function(e,r,i){"use strict";var n=e("string-mask"),t=e("../../helpers/mask-factory"),a=new n("0000 0000 0000 0000");r.exports=t({clearValue:function(e){return e.toString().replace(/[^0-9]/g,"").slice(0,16)},format:function(e){return(a.apply(e)||"").trim().replace(/[^0-9]$/,"")},validations:{creditCard:function(e){return 16===(e&&e.toString().length)}}})},{"../../helpers/mask-factory":12,"string-mask":void 0}],5:[function(e,r,i){"use strict";var s=e("date-fns/format"),l=e("date-fns/parse"),o=e("date-fns/isValid"),c=e("string-mask");var n={"pt-br":"DD/MM/YYYY","es-ar":"DD/MM/YYYY","es-mx":"DD/MM/YYYY",es:"DD/MM/YYYY","en-us":"MM/DD/YYYY",en:"MM/DD/YYYY","fr-fr":"DD/MM/YYYY",fr:"DD/MM/YYYY",ru:"DD.MM.YYYY"};function t(e){var u=n[e.id]||"YYYY-MM-DD";return{restrict:"A",require:"ngModel",link:function(e,r,i,n){i.parse=i.parse||"true",u=i.uiDateMask||u;var t=new c(u.replace(/[YMD]/g,"0"));function a(e){if(n.$isEmpty(e))return null;var r=e;return("object"==typeof e||/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}([-+][0-9]{2}:[0-9]{2}|Z)$/.test(e.toString()))&&(r=s(e,u)),r=r.replace(/[^0-9]/g,""),(t.apply(r)||"").trim().replace(/[^0-9]$/,"")}n.$formatters.push(a),n.$parsers.push(function(e){if(n.$isEmpty(e))return e;var r=a(e);return n.$viewValue!==r&&(n.$setViewValue(r),n.$render()),"false"===i.parse?r:l(r,u,new Date)}),n.$validators.date=function(e,r){return!!n.$isEmpty(e)||o(l(r,u,new Date))&&r.length===u.length}}}}t.$inject=["$locale"],r.exports=t},{"date-fns/format":void 0,"date-fns/isValid":void 0,"date-fns/parse":void 0,"string-mask":void 0}],6:[function(e,r,i){"use strict";var n=angular.module("ui.utils.masks.global",[]).directive("uiCreditCardMask",e("./credit-card/credit-card")).directive("uiDateMask",e("./date/date")).directive("uiMoneyMask",e("./money/money")).directive("uiNumberMask",e("./number/number")).directive("uiPercentageMask",e("./percentage/percentage")).directive("uiScientificNotationMask",e("./scientific-notation/scientific-notation")).directive("uiTimeMask",e("./time/time"));r.exports=n.name},{"./credit-card/credit-card":4,"./date/date":5,"./money/money":7,"./number/number":8,"./percentage/percentage":9,"./scientific-notation/scientific-notation":10,"./time/time":11}],7:[function(e,r,i){"use strict";var $=e("string-mask"),M=e("../../helpers/validators"),h=e("../../helpers/pre-formatters");function n(v,g){return{restrict:"A",require:"ngModel",link:function(e,r,a,u){var n=v.NUMBER_FORMATS.DECIMAL_SEP,t=v.NUMBER_FORMATS.GROUP_SEP,s=v.NUMBER_FORMATS.CURRENCY_SYM,l=" ",o=g(a.uiMoneyMask)(e),c=!1;function i(e){var r=0<e?n+new Array(e+1).join("0"):"",i="#"+t+"##0"+r;return angular.isDefined(a.uiCurrencyAfter)?i+=l:i=l+i,new $(i,{reverse:!0})}r.bind("keydown keypress",function(e){c=8===e.which}),angular.isDefined(a.uiDecimalDelimiter)&&(n=a.uiDecimalDelimiter),angular.isDefined(a.uiThousandsDelimiter)&&(t=a.uiThousandsDelimiter),angular.isDefined(a.uiHideGroupSep)&&(t=""),angular.isDefined(a.uiHideSpace)&&(l=""),angular.isDefined(a.currencySymbol)&&(s=a.currencySymbol,0===a.currencySymbol.length&&(l="")),isNaN(o)&&(o=2);var f,p,m=i(o=parseInt(o));function d(e){if(u.$isEmpty(e))return null;var r,i=e.replace(/[^\d]+/g,"");if(i=(i=i.replace(/^[0]+([1-9])/,"$1"))||"0",c&&angular.isDefined(a.uiCurrencyAfter)&&0!==i&&(i=i.substring(0,i.length-1),c=!1),r=angular.isDefined(a.uiCurrencyAfter)?m.apply(i)+s:s+m.apply(i),angular.isDefined(a.uiNegativeNumber)){var n="-"===e[0];"-"===e.slice(-1)^n&&i&&(i*=-1,r="-"+r)}e!==r&&(u.$setViewValue(r),u.$render());var t=parseInt(r.replace(/[^\d\-]+/g,""));return isNaN(t)?null:(angular.isDefined(a.uiIntegerModel)||(t/=Math.pow(10,o)),t)}(u.$formatters.push(function(e){if(u.$isEmpty(e))return"";angular.isDefined(a.uiIntegerModel)&&(e/=Math.pow(10,o));var r=angular.isDefined(a.uiNegativeNumber)&&e<0?"-":"",i=h.prepareNumberToFormatter(e,o);return angular.isDefined(a.uiCurrencyAfter)?r+m.apply(i)+s:r+s+m.apply(i)}),u.$parsers.push(d),a.uiMoneyMask&&e.$watch(a.uiMoneyMask,function(e){o=isNaN(e)?2:e,o=parseInt(o),m=i(o),d(u.$viewValue)}),a.currency&&e.$watch(a.currency,function(e){s=e,m=i(o),d(u.$viewValue)}),a.min)&&(u.$validators.min=function(e){return M.minNumber(u,e,f)},e.$watch(a.min,function(e){f=e,u.$validate()}));a.max&&(u.$validators.max=function(e){return M.maxNumber(u,e,p)},e.$watch(a.max,function(e){p=e,u.$validate()}))}}}n.$inject=["$locale","$parse"],r.exports=n},{"../../helpers/pre-formatters":14,"../../helpers/validators":15,"string-mask":void 0}],8:[function(e,r,i){"use strict";var d=e("../../helpers/validators"),v=e("../../helpers/number-mask-builder"),g=e("../../helpers/pre-formatters");function n(p,m){return{restrict:"A",require:"ngModel",link:function(e,r,a,u){var i=p.NUMBER_FORMATS.DECIMAL_SEP,n=p.NUMBER_FORMATS.GROUP_SEP,t=m(a.uiNumberMask)(e);angular.isDefined(a.uiHideGroupSep)&&(n=""),isNaN(t)&&(t=2);var s,l,o=v.viewMask(t,i,n),c=v.modelMask(t);function f(e){if(u.$isEmpty(e))return null;var r=g.clearDelimitersAndLeadingZeros(e)||"0",i=o.apply(r),n=parseFloat(c.apply(r));if(angular.isDefined(a.uiNegativeNumber)){var t="-"===e[0];("-"===e.slice(-1)^t||"-"===e)&&(i="-"+(0!==(n*=-1)?i:""))}return u.$viewValue!==i&&(u.$setViewValue(i),u.$render()),n}(r.on("blur",function(){"-"===u.$viewValue&&(u.$setViewValue(""),u.$render())}),u.$formatters.push(function(e){if(u.$isEmpty(e))return e;var r=angular.isDefined(a.uiNegativeNumber)&&e<0?"-":"",i=g.prepareNumberToFormatter(e,t);return r+o.apply(i)}),u.$parsers.push(f),a.uiNumberMask&&e.$watch(a.uiNumberMask,function(e){t=isNaN(e)?2:e,o=v.viewMask(t,i,n),c=v.modelMask(t),f(u.$viewValue)}),a.min)&&(u.$validators.min=function(e){return d.minNumber(u,e,s)},e.$watch(a.min,function(e){s=e,u.$validate()}));a.max&&(u.$validators.max=function(e){return d.maxNumber(u,e,l)},e.$watch(a.max,function(e){l=e,u.$validate()}))}}}n.$inject=["$locale","$parse"],r.exports=n},{"../../helpers/number-mask-builder":13,"../../helpers/pre-formatters":14,"../../helpers/validators":15}],9:[function(e,r,i){"use strict";var M=e("../../helpers/validators"),h=e("../../helpers/number-mask-builder"),k=e("../../helpers/pre-formatters");function n($){return{restrict:"A",require:"ngModel",link:function(e,r,u,s){var i=$.NUMBER_FORMATS.DECIMAL_SEP,a=!1;r.bind("keydown keypress",function(e){a=8===e.which});var n=$.NUMBER_FORMATS.GROUP_SEP;angular.isDefined(u.uiHideGroupSep)&&(n="");var l=" %";angular.isDefined(u.uiHidePercentageSign)?l="":angular.isDefined(u.uiHideSpace)&&(l="%");var o=parseInt(u.uiPercentageMask);isNaN(o)&&(o=2);var c={multiplier:100,decimalMask:2};angular.isDefined(u.uiPercentageValue)&&(c.multiplier=1,c.decimalMask=0);var t,f,p=o+c.decimalMask,m=h.viewMask(o,i,n),d=h.modelMask(p);function v(e){if(s.$isEmpty(e))return e;var r,i,n,t=angular.isDefined(u.uiNegativeNumber)&&e<0?"-":"",a=(r=e,i=o,n=c.multiplier,k.clearDelimitersAndLeadingZeros((parseFloat(r)*n).toFixed(i)));return t+m.apply(a)+l}function g(e){if(s.$isEmpty(e))return null;var r=k.clearDelimitersAndLeadingZeros(e)||"0";""!==l&&1<e.length&&-1===e.indexOf("%")&&(r=r.slice(0,r.length-1)),a&&1===e.length&&"%"!==e&&(r="0");var i=m.apply(r)+l,n=parseFloat(d.apply(r));if(angular.isDefined(u.uiNegativeNumber)){var t="-"===e[0];("-"===e.slice(-1)^t||"-"===e)&&(i="-"+(0!==(n*=-1)?i:""))}return s.$viewValue!==i&&(s.$setViewValue(i),s.$render()),n}(s.$formatters.push(v),s.$parsers.push(g),u.uiPercentageMask&&e.$watch(u.uiPercentageMask,function(e){o=isNaN(e)?2:e,p=o+c.decimalMask,m=h.viewMask(o,i,n),d=h.modelMask(p),g(v(s.$modelValue))}),u.min)&&(s.$validators.min=function(e){return M.minNumber(s,e,t)},e.$watch(u.min,function(e){t=e,s.$validate()}));u.max&&(s.$validators.max=function(e){return M.maxNumber(s,e,f)},e.$watch(u.max,function(e){f=e,s.$validate()}))}}}n.$inject=["$locale"],r.exports=n},{"../../helpers/number-mask-builder":13,"../../helpers/pre-formatters":14,"../../helpers/validators":15}],10:[function(e,r,i){"use strict";var n=e("string-mask");function t(e,i){var f=e.NUMBER_FORMATS.DECIMAL_SEP;return{restrict:"A",require:"ngModel",link:function(e,r,s,l){var o=i(s.uiScientificNotationMask)(e);isNaN(o)&&(o=2);var c=function(e){var r="0";if(0<e){r+=f;for(var i=0;i<e;i++)r+="0"}return new n(r,{reverse:!0})}(o);function a(e){if(l.$isEmpty(e))return e;var r,i;e="number"==typeof e?e.toExponential(o):e.toString().replace(f,".");var n,t={integerPartOfSignificand:(n=e.toString().match(/(-?[0-9]*)[\.]?([0-9]*)?[Ee]?([\+-]?[0-9]*)?/))[1],decimalPartOfSignificand:n[2],exponent:0|n[3]},a=t.integerPartOfSignificand||0,u=a.toString();return angular.isDefined(t.decimalPartOfSignificand)&&(u+=t.decimalPartOfSignificand),(1<=a||a<=-1)&&(angular.isDefined(t.decimalPartOfSignificand)&&t.decimalPartOfSignificand.length>o||0===o&&2<=u.length)&&(i=u.slice(o+1,u.length),u=u.slice(0,o+1)),r=c.apply(u),0!==t.exponent&&(i=t.exponent),angular.isDefined(i)&&(r+="e"+i),(angular.isDefined(s.uiNegativeNumber)&&"-"===e[0]?"-":"")+r}l.$formatters.push(a),l.$parsers.push(function(e){if(l.$isEmpty(e))return e;var r=/e-/.test(e),i=a(e.replace("e-","e")),n="-"===e.slice(-1);n^r&&(i=i.replace(/(e[-]?)/,"e-")),n&&r&&(i="-"!==i[0]?"-"+i:i.replace(/^(-)/,""));var t=parseFloat(i.replace(f,"."));return l.$viewValue!==i&&(l.$setViewValue(i),l.$render()),t}),l.$validators.max=function(e){return l.$isEmpty(e)||e<Number.MAX_VALUE}}}}t.$inject=["$locale","$parse"],r.exports=t},{"string-mask":void 0}],11:[function(e,r,i){"use strict";var o=e("string-mask");r.exports=function(){return{restrict:"A",require:"ngModel",link:function(e,r,i,a){var n="00:00:00";angular.isDefined(i.uiTimeMask)&&"short"===i.uiTimeMask&&(n="00:00");var u=n.length,t=n.replace(":","").length,s=new o(n);function l(e){if(a.$isEmpty(e))return e;var r=e.replace(/[^0-9]/g,"").slice(0,t)||"";return(s.apply(r)||"").replace(/[^0-9]$/,"")}a.$formatters.push(l),a.$parsers.push(function(e){if(a.$isEmpty(e))return e;var r=l(e),i=r;return a.$viewValue!==r&&(a.$setViewValue(r),a.$render()),i}),a.$validators.time=function(e){if(a.$isEmpty(e))return!0;var r=e.toString().split(/:/).filter(function(e){return!!e}),i=parseInt(r[0]),n=parseInt(r[1]),t=parseInt(r[2]||0);return e.toString().length===u&&i<24&&n<60&&t<60}}}}},{"string-mask":void 0}],12:[function(e,r,i){"use strict";r.exports=function(a){return function(){return{restrict:"A",require:"ngModel",link:function(e,r,i,t){t.$formatters.push(function(e){if(t.$isEmpty(e))return e;var r=a.clearValue(e.toString());return a.format(r)}),t.$parsers.push(function(e){if(t.$isEmpty(e))return e;var r=a.clearValue(e.toString()),i=a.format(r);if(t.$viewValue!==i&&(t.$setViewValue(i),t.$render()),angular.isUndefined(a.getModelValue))return r;var n=typeof t.$modelValue;return a.getModelValue(i,n)}),angular.forEach(a.validations,function(i,e){t.$validators[e]=function(e,r){return t.$isEmpty(e)||i(e,r)}})}}}}},{}],13:[function(e,r,i){"use strict";var a=e("string-mask");r.exports={viewMask:function(e,r,i){var n="#"+i+"##0";if(0<e){n+=r;for(var t=0;t<e;t++)n+="0"}return new a(n,{reverse:!0})},modelMask:function(e){var r="###0";if(0<e){r+=".";for(var i=0;i<e;i++)r+="0"}return new a(r,{reverse:!0})}}},{"string-mask":void 0}],14:[function(e,r,i){"use strict";function n(e){return"0"===e?"0":e.toString().replace(/^-/,"").replace(/^0*/,"").replace(/[^0-9]/g,"")}r.exports={clearDelimitersAndLeadingZeros:n,prepareNumberToFormatter:function(e,r){return n(parseFloat(e).toFixed(r))}}},{}],15:[function(e,r,i){"use strict";r.exports={maxNumber:function(e,r,i){var n=parseFloat(i,10);return e.$isEmpty(r)||isNaN(n)||r<=n},minNumber:function(e,r,i){var n=parseFloat(i,10);return e.$isEmpty(r)||isNaN(n)||n<=r}}},{}]},{},[1]);