From deb727482bd7da1b829a71fb53e6c9ad3aa2451c Mon Sep 17 00:00:00 2001 From: PatrickW Date: Tue, 12 May 2020 19:46:44 -0700 Subject: [PATCH] Fix double prefix display when `noImmediatePrefix` is set --- dist/cleave-angular.js | 2 +- dist/cleave-angular.min.js | 2 +- dist/cleave-esm.js | 4 ++-- dist/cleave-esm.min.js | 2 +- dist/cleave-react-node.js | 2 +- dist/cleave-react-node.min.js | 2 +- dist/cleave-react.js | 2 +- dist/cleave-react.min.js | 4 ++-- dist/cleave.js | 2 +- dist/cleave.min.js | 2 +- src/Cleave.js | 2 +- src/Cleave.react.js | 2 +- test/browser/custom.js | 12 ++++++++++++ 13 files changed, 26 insertions(+), 14 deletions(-) diff --git a/dist/cleave-angular.js b/dist/cleave-angular.js index db9f28da..077f4d3c 100644 --- a/dist/cleave-angular.js +++ b/dist/cleave-angular.js @@ -366,7 +366,7 @@ return /******/ (function(modules) { // webpackBootstrap if (pps.prefix && (!pps.noImmediatePrefix || value.length)) { if (pps.tailPrefix) { value = value + pps.prefix; - } else { + } else if(value !== pps.prefix) { value = pps.prefix + value; } diff --git a/dist/cleave-angular.min.js b/dist/cleave-angular.min.js index 449451ae..500c8066 100644 --- a/dist/cleave-angular.min.js +++ b/dist/cleave-angular.min.js @@ -5,4 +5,4 @@ * * Copyright (C) 2012-2020 Max Huang https://github.com/nosir/ */ -!function(root,factory){"object"==typeof exports&&"object"==typeof module?module.exports=factory():"function"==typeof define&&define.amd?define([],factory):"object"==typeof exports?exports.Cleave=factory():root.Cleave=factory()}(this,function(){return function(modules){function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={exports:{},id:moduleId,loaded:!1};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.loaded=!0,module.exports}var installedModules={};return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.p="",__webpack_require__(0)}([function(module,exports,__webpack_require__){(function(global){"use strict";var Cleave=function(element,opts){var owner=this,hasMultipleElements=!1;if("string"==typeof element?(owner.element=document.querySelector(element),hasMultipleElements=document.querySelectorAll(element).length>1):"undefined"!=typeof element.length&&element.length>0?(owner.element=element[0],hasMultipleElements=element.length>1):owner.element=element,!owner.element)throw new Error("[cleave.js] Please check the element");if(hasMultipleElements)try{console.warn("[cleave.js] Multiple input fields matched, cleave.js will only take the first one.")}catch(e){}opts.initValue=owner.element.value,owner.properties=Cleave.DefaultProperties.assign({},opts),owner.init()};Cleave.prototype={init:function(){var owner=this,pps=owner.properties;return pps.numeral||pps.phone||pps.creditCard||pps.time||pps.date||0!==pps.blocksLength||pps.prefix?(pps.maxLength=Cleave.Util.getMaxLength(pps.blocks),owner.isAndroid=Cleave.Util.isAndroid(),owner.lastInputValue="",owner.onChangeListener=owner.onChange.bind(owner),owner.onKeyDownListener=owner.onKeyDown.bind(owner),owner.onFocusListener=owner.onFocus.bind(owner),owner.onCutListener=owner.onCut.bind(owner),owner.onCopyListener=owner.onCopy.bind(owner),owner.initSwapHiddenInput(),owner.element.addEventListener("input",owner.onChangeListener),owner.element.addEventListener("keydown",owner.onKeyDownListener),owner.element.addEventListener("focus",owner.onFocusListener),owner.element.addEventListener("cut",owner.onCutListener),owner.element.addEventListener("copy",owner.onCopyListener),owner.initPhoneFormatter(),owner.initDateFormatter(),owner.initTimeFormatter(),owner.initNumeralFormatter(),void((pps.initValue||pps.prefix&&!pps.noImmediatePrefix)&&owner.onInput(pps.initValue))):void owner.onInput(pps.initValue)},initSwapHiddenInput:function(){var owner=this,pps=owner.properties;if(pps.swapHiddenInput){var inputFormatter=owner.element.cloneNode(!0);owner.element.parentNode.insertBefore(inputFormatter,owner.element),owner.elementSwapHidden=owner.element,owner.elementSwapHidden.type="hidden",owner.element=inputFormatter,owner.element.id=""}},initNumeralFormatter:function(){var owner=this,pps=owner.properties;pps.numeral&&(pps.numeralFormatter=new Cleave.NumeralFormatter(pps.numeralDecimalMark,pps.numeralIntegerScale,pps.numeralDecimalScale,pps.numeralThousandsGroupStyle,pps.numeralPositiveOnly,pps.stripLeadingZeroes,pps.prefix,pps.signBeforePrefix,pps.tailPrefix,pps.delimiter))},initTimeFormatter:function(){var owner=this,pps=owner.properties;pps.time&&(pps.timeFormatter=new Cleave.TimeFormatter(pps.timePattern,pps.timeFormat),pps.blocks=pps.timeFormatter.getBlocks(),pps.blocksLength=pps.blocks.length,pps.maxLength=Cleave.Util.getMaxLength(pps.blocks))},initDateFormatter:function(){var owner=this,pps=owner.properties;pps.date&&(pps.dateFormatter=new Cleave.DateFormatter(pps.datePattern,pps.dateMin,pps.dateMax),pps.blocks=pps.dateFormatter.getBlocks(),pps.blocksLength=pps.blocks.length,pps.maxLength=Cleave.Util.getMaxLength(pps.blocks))},initPhoneFormatter:function(){var owner=this,pps=owner.properties;if(pps.phone)try{pps.phoneFormatter=new Cleave.PhoneFormatter(new pps.root.Cleave.AsYouTypeFormatter(pps.phoneRegionCode),pps.delimiter)}catch(ex){throw new Error("[cleave.js] Please include phone-type-formatter.{country}.js lib")}},onKeyDown:function(event){var owner=this,pps=owner.properties,charCode=event.which||event.keyCode,Util=Cleave.Util,currentValue=owner.element.value;owner.hasBackspaceSupport=owner.hasBackspaceSupport||8===charCode,!owner.hasBackspaceSupport&&Util.isAndroidBackspaceKeydown(owner.lastInputValue,currentValue)&&(charCode=8),owner.lastInputValue=currentValue;var postDelimiter=Util.getPostDelimiter(currentValue,pps.delimiter,pps.delimiters);8===charCode&&postDelimiter?pps.postDelimiterBackspace=postDelimiter:pps.postDelimiterBackspace=!1},onChange:function(){this.onInput(this.element.value)},onFocus:function(){var owner=this,pps=owner.properties;pps.prefix&&pps.noImmediatePrefix&&!owner.element.value&&this.onInput(pps.prefix),Cleave.Util.fixPrefixCursor(owner.element,pps.prefix,pps.delimiter,pps.delimiters)},onCut:function(e){Cleave.Util.checkFullSelection(this.element.value)&&(this.copyClipboardData(e),this.onInput(""))},onCopy:function(e){Cleave.Util.checkFullSelection(this.element.value)&&this.copyClipboardData(e)},copyClipboardData:function(e){var owner=this,pps=owner.properties,Util=Cleave.Util,inputValue=owner.element.value,textToCopy="";textToCopy=pps.copyDelimiter?inputValue:Util.stripDelimiters(inputValue,pps.delimiter,pps.delimiters);try{e.clipboardData?e.clipboardData.setData("Text",textToCopy):window.clipboardData.setData("Text",textToCopy),e.preventDefault()}catch(ex){}},onInput:function(value){var owner=this,pps=owner.properties,Util=Cleave.Util,postDelimiterAfter=Util.getPostDelimiter(value,pps.delimiter,pps.delimiters);return pps.numeral||!pps.postDelimiterBackspace||postDelimiterAfter||(value=Util.headStr(value,value.length-pps.postDelimiterBackspace.length)),pps.phone?(!pps.prefix||pps.noImmediatePrefix&&!value.length?pps.result=pps.phoneFormatter.format(value):pps.result=pps.prefix+pps.phoneFormatter.format(value).slice(pps.prefix.length),void owner.updateValueState()):pps.numeral?(pps.prefix&&pps.noImmediatePrefix&&0===value.length?pps.result="":pps.result=pps.numeralFormatter.format(value),void owner.updateValueState()):(pps.date&&(value=pps.dateFormatter.getValidatedDate(value)),pps.time&&(value=pps.timeFormatter.getValidatedTime(value)),value=Util.stripDelimiters(value,pps.delimiter,pps.delimiters),value=Util.getPrefixStrippedValue(value,pps.prefix,pps.prefixLength,pps.result,pps.delimiter,pps.delimiters,pps.noImmediatePrefix,pps.tailPrefix,pps.signBeforePrefix),value=pps.numericOnly?Util.strip(value,/[^\d]/g):value,value=pps.uppercase?value.toUpperCase():value,value=pps.lowercase?value.toLowerCase():value,!pps.prefix||pps.noImmediatePrefix&&!value.length||(pps.tailPrefix?value+=pps.prefix:value=pps.prefix+value,0!==pps.blocksLength)?(pps.creditCard&&owner.updateCreditCardPropsByValue(value),value=Util.headStr(value,pps.maxLength),pps.result=Util.getFormattedValue(value,pps.blocks,pps.blocksLength,pps.delimiter,pps.delimiters,pps.delimiterLazyShow),void owner.updateValueState()):(pps.result=value,void owner.updateValueState()))},updateCreditCardPropsByValue:function(value){var creditCardInfo,owner=this,pps=owner.properties,Util=Cleave.Util;Util.headStr(pps.result,4)!==Util.headStr(value,4)&&(creditCardInfo=Cleave.CreditCardDetector.getInfo(value,pps.creditCardStrictMode),pps.blocks=creditCardInfo.blocks,pps.blocksLength=pps.blocks.length,pps.maxLength=Util.getMaxLength(pps.blocks),pps.creditCardType!==creditCardInfo.type&&(pps.creditCardType=creditCardInfo.type,pps.onCreditCardTypeChanged.call(owner,pps.creditCardType)))},updateValueState:function(){var owner=this,Util=Cleave.Util,pps=owner.properties;if(owner.element){var endPos=owner.element.selectionEnd,oldValue=owner.element.value,newValue=pps.result;if(endPos=Util.getNextCursorPosition(endPos,oldValue,newValue,pps.delimiter,pps.delimiters),owner.isAndroid)return void window.setTimeout(function(){owner.element.value=newValue,Util.setSelection(owner.element,endPos,pps.document,!1),owner.callOnValueChanged()},1);owner.element.value=newValue,pps.swapHiddenInput&&(owner.elementSwapHidden.value=owner.getRawValue()),Util.setSelection(owner.element,endPos,pps.document,!1),owner.callOnValueChanged()}},callOnValueChanged:function(){var owner=this,pps=owner.properties;pps.onValueChanged.call(owner,{target:{name:owner.element.name,value:pps.result,rawValue:owner.getRawValue()}})},setPhoneRegionCode:function(phoneRegionCode){var owner=this,pps=owner.properties;pps.phoneRegionCode=phoneRegionCode,owner.initPhoneFormatter(),owner.onChange()},setRawValue:function(value){var owner=this,pps=owner.properties;value=void 0!==value&&null!==value?value.toString():"",pps.numeral&&(value=value.replace(".",pps.numeralDecimalMark)),pps.postDelimiterBackspace=!1,owner.element.value=value,owner.onInput(value)},getRawValue:function(){var owner=this,pps=owner.properties,Util=Cleave.Util,rawValue=owner.element.value;return pps.rawValueTrimPrefix&&(rawValue=Util.getPrefixStrippedValue(rawValue,pps.prefix,pps.prefixLength,pps.result,pps.delimiter,pps.delimiters,pps.noImmediatePrefix,pps.tailPrefix,pps.signBeforePrefix)),rawValue=pps.numeral?pps.numeralFormatter.getRawValue(rawValue):Util.stripDelimiters(rawValue,pps.delimiter,pps.delimiters)},getISOFormatDate:function(){var owner=this,pps=owner.properties;return pps.date?pps.dateFormatter.getISOFormatDate():""},getISOFormatTime:function(){var owner=this,pps=owner.properties;return pps.time?pps.timeFormatter.getISOFormatTime():""},getFormattedValue:function(){return this.element.value},destroy:function(){var owner=this;owner.element.removeEventListener("input",owner.onChangeListener),owner.element.removeEventListener("keydown",owner.onKeyDownListener),owner.element.removeEventListener("focus",owner.onFocusListener),owner.element.removeEventListener("cut",owner.onCutListener),owner.element.removeEventListener("copy",owner.onCopyListener)},toString:function(){return"[Cleave Object]"}},Cleave.NumeralFormatter=__webpack_require__(1),Cleave.DateFormatter=__webpack_require__(2),Cleave.TimeFormatter=__webpack_require__(3),Cleave.PhoneFormatter=__webpack_require__(4),Cleave.CreditCardDetector=__webpack_require__(5),Cleave.Util=__webpack_require__(6),Cleave.DefaultProperties=__webpack_require__(7),("object"==typeof global&&global?global:window).Cleave=Cleave,module.exports=Cleave,angular.module("cleave.js",[]).directive("cleave",function(){return{restrict:"A",require:"ngModel",scope:{cleave:"&",onInit:"&?",onValueChange:"&?"},compile:function(){return{pre:function($scope,$element,attrs,ngModelCtrl){$scope.instance=new Cleave($element[0],$scope.cleave()),$scope.onInit&&$scope.onInit()($scope.instance),ngModelCtrl.$formatters.push(function(val){return $scope.instance.setRawValue(val),$scope.instance.getFormattedValue()}),ngModelCtrl.$parsers.push(function(newFormattedValue){return $scope.onValueChange&&$scope.onValueChange()(newFormattedValue),$scope.instance.getRawValue()}),$scope.$watch(function(){return $scope.cleave()},function(newOptions,oldOptions){$scope.instance.destroy(),$scope.instance=new Cleave($element[0],newOptions)},!0),$scope.$on("$destroy",function(){$scope.instance.destroy(),$scope.instance=null})}}}}})}).call(exports,function(){return this}())},function(module,exports){"use strict";var NumeralFormatter=function(numeralDecimalMark,numeralIntegerScale,numeralDecimalScale,numeralThousandsGroupStyle,numeralPositiveOnly,stripLeadingZeroes,prefix,signBeforePrefix,tailPrefix,delimiter){var owner=this;owner.numeralDecimalMark=numeralDecimalMark||".",owner.numeralIntegerScale=numeralIntegerScale>0?numeralIntegerScale:0,owner.numeralDecimalScale=numeralDecimalScale>=0?numeralDecimalScale:2,owner.numeralThousandsGroupStyle=numeralThousandsGroupStyle||NumeralFormatter.groupStyle.thousand,owner.numeralPositiveOnly=!!numeralPositiveOnly,owner.stripLeadingZeroes=stripLeadingZeroes!==!1,owner.prefix=prefix||""===prefix?prefix:"",owner.signBeforePrefix=!!signBeforePrefix,owner.tailPrefix=!!tailPrefix,owner.delimiter=delimiter||""===delimiter?delimiter:",",owner.delimiterRE=delimiter?new RegExp("\\"+delimiter,"g"):""};NumeralFormatter.groupStyle={thousand:"thousand",lakh:"lakh",wan:"wan",none:"none"},NumeralFormatter.prototype={getRawValue:function(value){return value.replace(this.delimiterRE,"").replace(this.numeralDecimalMark,".")},format:function(value){var parts,partSign,partSignAndPrefix,partInteger,owner=this,partDecimal="";switch(value=value.replace(/[A-Za-z]/g,"").replace(owner.numeralDecimalMark,"M").replace(/[^\dM-]/g,"").replace(/^\-/,"N").replace(/\-/g,"").replace("N",owner.numeralPositiveOnly?"":"-").replace("M",owner.numeralDecimalMark),owner.stripLeadingZeroes&&(value=value.replace(/^(-)?0+(?=\d)/,"$1")),partSign="-"===value.slice(0,1)?"-":"",partSignAndPrefix="undefined"!=typeof owner.prefix?owner.signBeforePrefix?partSign+owner.prefix:owner.prefix+partSign:partSign,partInteger=value,value.indexOf(owner.numeralDecimalMark)>=0&&(parts=value.split(owner.numeralDecimalMark),partInteger=parts[0],partDecimal=owner.numeralDecimalMark+parts[1].slice(0,owner.numeralDecimalScale)),"-"===partSign&&(partInteger=partInteger.slice(1)),owner.numeralIntegerScale>0&&(partInteger=partInteger.slice(0,owner.numeralIntegerScale)),owner.numeralThousandsGroupStyle){case NumeralFormatter.groupStyle.lakh:partInteger=partInteger.replace(/(\d)(?=(\d\d)+\d$)/g,"$1"+owner.delimiter);break;case NumeralFormatter.groupStyle.wan:partInteger=partInteger.replace(/(\d)(?=(\d{4})+$)/g,"$1"+owner.delimiter);break;case NumeralFormatter.groupStyle.thousand:partInteger=partInteger.replace(/(\d)(?=(\d{3})+$)/g,"$1"+owner.delimiter)}return owner.tailPrefix?partSign+partInteger.toString()+(owner.numeralDecimalScale>0?partDecimal.toString():"")+owner.prefix:partSignAndPrefix+partInteger.toString()+(owner.numeralDecimalScale>0?partDecimal.toString():"")}},module.exports=NumeralFormatter},function(module,exports){"use strict";var DateFormatter=function(datePattern,dateMin,dateMax){var owner=this;owner.date=[],owner.blocks=[],owner.datePattern=datePattern,owner.dateMin=dateMin.split("-").reverse().map(function(x){return parseInt(x,10)}),2===owner.dateMin.length&&owner.dateMin.unshift(0),owner.dateMax=dateMax.split("-").reverse().map(function(x){return parseInt(x,10)}),2===owner.dateMax.length&&owner.dateMax.unshift(0),owner.initBlocks()};DateFormatter.prototype={initBlocks:function(){var owner=this;owner.datePattern.forEach(function(value){"Y"===value?owner.blocks.push(4):owner.blocks.push(2)})},getISOFormatDate:function(){var owner=this,date=owner.date;return date[2]?date[2]+"-"+owner.addLeadingZero(date[1])+"-"+owner.addLeadingZero(date[0]):""},getBlocks:function(){return this.blocks},getValidatedDate:function(value){var owner=this,result="";return value=value.replace(/[^\d]/g,""),owner.blocks.forEach(function(length,index){if(value.length>0){var sub=value.slice(0,length),sub0=sub.slice(0,1),rest=value.slice(length);switch(owner.datePattern[index]){case"d":"00"===sub?sub="01":parseInt(sub0,10)>3?sub="0"+sub0:parseInt(sub,10)>31&&(sub="31");break;case"m":"00"===sub?sub="01":parseInt(sub0,10)>1?sub="0"+sub0:parseInt(sub,10)>12&&(sub="12")}result+=sub,value=rest}}),this.getFixedDateString(result)},getFixedDateString:function(value){var day,month,year,owner=this,datePattern=owner.datePattern,date=[],dayIndex=0,monthIndex=0,yearIndex=0,dayStartIndex=0,monthStartIndex=0,yearStartIndex=0,fullYearDone=!1;4===value.length&&"y"!==datePattern[0].toLowerCase()&&"y"!==datePattern[1].toLowerCase()&&(dayStartIndex="d"===datePattern[0]?0:2,monthStartIndex=2-dayStartIndex,day=parseInt(value.slice(dayStartIndex,dayStartIndex+2),10),month=parseInt(value.slice(monthStartIndex,monthStartIndex+2),10),date=this.getFixedDate(day,month,0)),8===value.length&&(datePattern.forEach(function(type,index){switch(type){case"d":dayIndex=index;break;case"m":monthIndex=index;break;default:yearIndex=index}}),yearStartIndex=2*yearIndex,dayStartIndex=dayIndex<=yearIndex?2*dayIndex:2*dayIndex+2,monthStartIndex=monthIndex<=yearIndex?2*monthIndex:2*monthIndex+2,day=parseInt(value.slice(dayStartIndex,dayStartIndex+2),10),month=parseInt(value.slice(monthStartIndex,monthStartIndex+2),10),year=parseInt(value.slice(yearStartIndex,yearStartIndex+4),10),fullYearDone=4===value.slice(yearStartIndex,yearStartIndex+4).length,date=this.getFixedDate(day,month,year)),4!==value.length||"y"!==datePattern[0]&&"y"!==datePattern[1]||(monthStartIndex="m"===datePattern[0]?0:2,yearStartIndex=2-monthStartIndex,month=parseInt(value.slice(monthStartIndex,monthStartIndex+2),10),year=parseInt(value.slice(yearStartIndex,yearStartIndex+2),10),fullYearDone=2===value.slice(yearStartIndex,yearStartIndex+2).length,date=[0,month,year]),6!==value.length||"Y"!==datePattern[0]&&"Y"!==datePattern[1]||(monthStartIndex="m"===datePattern[0]?0:4,yearStartIndex=2-.5*monthStartIndex,month=parseInt(value.slice(monthStartIndex,monthStartIndex+2),10),year=parseInt(value.slice(yearStartIndex,yearStartIndex+4),10),fullYearDone=4===value.slice(yearStartIndex,yearStartIndex+4).length,date=[0,month,year]),date=owner.getRangeFixedDate(date),owner.date=date;var result=0===date.length?value:datePattern.reduce(function(previous,current){switch(current){case"d":return previous+(0===date[0]?"":owner.addLeadingZero(date[0]));case"m":return previous+(0===date[1]?"":owner.addLeadingZero(date[1]));case"y":return previous+(fullYearDone?owner.addLeadingZeroForYear(date[2],!1):"");case"Y":return previous+(fullYearDone?owner.addLeadingZeroForYear(date[2],!0):"")}},"");return result},getRangeFixedDate:function(date){var owner=this,datePattern=owner.datePattern,dateMin=owner.dateMin||[],dateMax=owner.dateMax||[];return!date.length||dateMin.length<3&&dateMax.length<3?date:datePattern.find(function(x){return"y"===x.toLowerCase()})&&0===date[2]?date:dateMax.length&&(dateMax[2]date[2]||dateMin[2]===date[2]&&(dateMin[1]>date[1]||dateMin[1]===date[1]&&dateMin[0]>date[0]))?dateMin:date},getFixedDate:function(day,month,year){return day=Math.min(day,31),month=Math.min(month,12),year=parseInt(year||0,10),(month<7&&month%2===0||month>8&&month%2===1)&&(day=Math.min(day,2===month?this.isLeapYear(year)?29:28:30)),[day,month,year]},isLeapYear:function(year){return year%4===0&&year%100!==0||year%400===0},addLeadingZero:function(number){return(number<10?"0":"")+number},addLeadingZeroForYear:function(number,fullYearMode){return fullYearMode?(number<10?"000":number<100?"00":number<1e3?"0":"")+number:(number<10?"0":"")+number}},module.exports=DateFormatter},function(module,exports){"use strict";var TimeFormatter=function(timePattern,timeFormat){var owner=this;owner.time=[],owner.blocks=[],owner.timePattern=timePattern,owner.timeFormat=timeFormat,owner.initBlocks()};TimeFormatter.prototype={initBlocks:function(){var owner=this;owner.timePattern.forEach(function(){owner.blocks.push(2)})},getISOFormatTime:function(){var owner=this,time=owner.time;return time[2]?owner.addLeadingZero(time[0])+":"+owner.addLeadingZero(time[1])+":"+owner.addLeadingZero(time[2]):""},getBlocks:function(){return this.blocks},getTimeFormatOptions:function(){var owner=this;return"12"===String(owner.timeFormat)?{maxHourFirstDigit:1,maxHours:12,maxMinutesFirstDigit:5,maxMinutes:60}:{maxHourFirstDigit:2,maxHours:23,maxMinutesFirstDigit:5,maxMinutes:60}},getValidatedTime:function(value){var owner=this,result="";value=value.replace(/[^\d]/g,"");var timeFormatOptions=owner.getTimeFormatOptions();return owner.blocks.forEach(function(length,index){if(value.length>0){var sub=value.slice(0,length),sub0=sub.slice(0,1),rest=value.slice(length);switch(owner.timePattern[index]){case"h":parseInt(sub0,10)>timeFormatOptions.maxHourFirstDigit?sub="0"+sub0:parseInt(sub,10)>timeFormatOptions.maxHours&&(sub=timeFormatOptions.maxHours+"");break;case"m":case"s":parseInt(sub0,10)>timeFormatOptions.maxMinutesFirstDigit?sub="0"+sub0:parseInt(sub,10)>timeFormatOptions.maxMinutes&&(sub=timeFormatOptions.maxMinutes+"")}result+=sub,value=rest}}),this.getFixedTimeString(result)},getFixedTimeString:function(value){var second,minute,hour,owner=this,timePattern=owner.timePattern,time=[],secondIndex=0,minuteIndex=0,hourIndex=0,secondStartIndex=0,minuteStartIndex=0,hourStartIndex=0;return 6===value.length&&(timePattern.forEach(function(type,index){switch(type){case"s":secondIndex=2*index;break;case"m":minuteIndex=2*index;break;case"h":hourIndex=2*index}}),hourStartIndex=hourIndex,minuteStartIndex=minuteIndex,secondStartIndex=secondIndex,second=parseInt(value.slice(secondStartIndex,secondStartIndex+2),10),minute=parseInt(value.slice(minuteStartIndex,minuteStartIndex+2),10),hour=parseInt(value.slice(hourStartIndex,hourStartIndex+2),10),time=this.getFixedTime(hour,minute,second)),4===value.length&&owner.timePattern.indexOf("s")<0&&(timePattern.forEach(function(type,index){switch(type){case"m":minuteIndex=2*index;break;case"h":hourIndex=2*index}}),hourStartIndex=hourIndex,minuteStartIndex=minuteIndex,second=0,minute=parseInt(value.slice(minuteStartIndex,minuteStartIndex+2),10),hour=parseInt(value.slice(hourStartIndex,hourStartIndex+2),10),time=this.getFixedTime(hour,minute,second)),owner.time=time,0===time.length?value:timePattern.reduce(function(previous,current){switch(current){case"s":return previous+owner.addLeadingZero(time[2]);case"m":return previous+owner.addLeadingZero(time[1]);case"h":return previous+owner.addLeadingZero(time[0])}},"")},getFixedTime:function(hour,minute,second){return second=Math.min(parseInt(second||0,10),60),minute=Math.min(minute,60),hour=Math.min(hour,60),[hour,minute,second]},addLeadingZero:function(number){return(number<10?"0":"")+number}},module.exports=TimeFormatter},function(module,exports){"use strict";var PhoneFormatter=function(formatter,delimiter){var owner=this;owner.delimiter=delimiter||""===delimiter?delimiter:" ",owner.delimiterRE=delimiter?new RegExp("\\"+delimiter,"g"):"",owner.formatter=formatter};PhoneFormatter.prototype={setFormatter:function(formatter){this.formatter=formatter},format:function(phoneNumber){var owner=this;owner.formatter.clear(),phoneNumber=phoneNumber.replace(/[^\d+]/g,""),phoneNumber=phoneNumber.replace(/^\+/,"B").replace(/\+/g,"").replace("B","+"),phoneNumber=phoneNumber.replace(owner.delimiterRE,"");for(var current,result="",validated=!1,i=0,iMax=phoneNumber.length;i0;return 0===blocksLength?value:(blocks.forEach(function(length,index){if(value.length>0){var sub=value.slice(0,length),rest=value.slice(length);currentDelimiter=multipleDelimiters?delimiters[delimiterLazyShow?index-1:index]||currentDelimiter:delimiter,delimiterLazyShow?(index>0&&(result+=currentDelimiter),result+=sub):(result+=sub,sub.length===length&&index0?opts.numeralIntegerScale:0,target.numeralDecimalScale=opts.numeralDecimalScale>=0?opts.numeralDecimalScale:2,target.numeralDecimalMark=opts.numeralDecimalMark||".",target.numeralThousandsGroupStyle=opts.numeralThousandsGroupStyle||"thousand",target.numeralPositiveOnly=!!opts.numeralPositiveOnly,target.stripLeadingZeroes=opts.stripLeadingZeroes!==!1,target.signBeforePrefix=!!opts.signBeforePrefix,target.tailPrefix=!!opts.tailPrefix,target.swapHiddenInput=!!opts.swapHiddenInput,target.numericOnly=target.creditCard||target.date||!!opts.numericOnly,target.uppercase=!!opts.uppercase,target.lowercase=!!opts.lowercase,target.prefix=target.creditCard||target.date?"":opts.prefix||"",target.noImmediatePrefix=!!opts.noImmediatePrefix,target.prefixLength=target.prefix.length,target.rawValueTrimPrefix=!!opts.rawValueTrimPrefix,target.copyDelimiter=!!opts.copyDelimiter,target.initValue=void 0!==opts.initValue&&null!==opts.initValue?opts.initValue.toString():"",target.delimiter=opts.delimiter||""===opts.delimiter?opts.delimiter:opts.date?"/":opts.time?":":opts.numeral?",":(opts.phone," "),target.delimiterLength=target.delimiter.length,target.delimiterLazyShow=!!opts.delimiterLazyShow,target.delimiters=opts.delimiters||[],target.blocks=opts.blocks||[],target.blocksLength=target.blocks.length,target.root="object"==typeof global&&global?global:window,target.document=opts.document||target.root.document,target.maxLength=0,target.backspace=!1,target.result="",target.onValueChanged=opts.onValueChanged||function(){},target}};module.exports=DefaultProperties}).call(exports,function(){return this}())}])}); \ No newline at end of file +!function(root,factory){"object"==typeof exports&&"object"==typeof module?module.exports=factory():"function"==typeof define&&define.amd?define([],factory):"object"==typeof exports?exports.Cleave=factory():root.Cleave=factory()}(this,function(){return function(modules){function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={exports:{},id:moduleId,loaded:!1};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.loaded=!0,module.exports}var installedModules={};return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.p="",__webpack_require__(0)}([function(module,exports,__webpack_require__){(function(global){"use strict";var Cleave=function(element,opts){var owner=this,hasMultipleElements=!1;if("string"==typeof element?(owner.element=document.querySelector(element),hasMultipleElements=document.querySelectorAll(element).length>1):"undefined"!=typeof element.length&&element.length>0?(owner.element=element[0],hasMultipleElements=element.length>1):owner.element=element,!owner.element)throw new Error("[cleave.js] Please check the element");if(hasMultipleElements)try{console.warn("[cleave.js] Multiple input fields matched, cleave.js will only take the first one.")}catch(e){}opts.initValue=owner.element.value,owner.properties=Cleave.DefaultProperties.assign({},opts),owner.init()};Cleave.prototype={init:function(){var owner=this,pps=owner.properties;return pps.numeral||pps.phone||pps.creditCard||pps.time||pps.date||0!==pps.blocksLength||pps.prefix?(pps.maxLength=Cleave.Util.getMaxLength(pps.blocks),owner.isAndroid=Cleave.Util.isAndroid(),owner.lastInputValue="",owner.onChangeListener=owner.onChange.bind(owner),owner.onKeyDownListener=owner.onKeyDown.bind(owner),owner.onFocusListener=owner.onFocus.bind(owner),owner.onCutListener=owner.onCut.bind(owner),owner.onCopyListener=owner.onCopy.bind(owner),owner.initSwapHiddenInput(),owner.element.addEventListener("input",owner.onChangeListener),owner.element.addEventListener("keydown",owner.onKeyDownListener),owner.element.addEventListener("focus",owner.onFocusListener),owner.element.addEventListener("cut",owner.onCutListener),owner.element.addEventListener("copy",owner.onCopyListener),owner.initPhoneFormatter(),owner.initDateFormatter(),owner.initTimeFormatter(),owner.initNumeralFormatter(),void((pps.initValue||pps.prefix&&!pps.noImmediatePrefix)&&owner.onInput(pps.initValue))):void owner.onInput(pps.initValue)},initSwapHiddenInput:function(){var owner=this,pps=owner.properties;if(pps.swapHiddenInput){var inputFormatter=owner.element.cloneNode(!0);owner.element.parentNode.insertBefore(inputFormatter,owner.element),owner.elementSwapHidden=owner.element,owner.elementSwapHidden.type="hidden",owner.element=inputFormatter,owner.element.id=""}},initNumeralFormatter:function(){var owner=this,pps=owner.properties;pps.numeral&&(pps.numeralFormatter=new Cleave.NumeralFormatter(pps.numeralDecimalMark,pps.numeralIntegerScale,pps.numeralDecimalScale,pps.numeralThousandsGroupStyle,pps.numeralPositiveOnly,pps.stripLeadingZeroes,pps.prefix,pps.signBeforePrefix,pps.tailPrefix,pps.delimiter))},initTimeFormatter:function(){var owner=this,pps=owner.properties;pps.time&&(pps.timeFormatter=new Cleave.TimeFormatter(pps.timePattern,pps.timeFormat),pps.blocks=pps.timeFormatter.getBlocks(),pps.blocksLength=pps.blocks.length,pps.maxLength=Cleave.Util.getMaxLength(pps.blocks))},initDateFormatter:function(){var owner=this,pps=owner.properties;pps.date&&(pps.dateFormatter=new Cleave.DateFormatter(pps.datePattern,pps.dateMin,pps.dateMax),pps.blocks=pps.dateFormatter.getBlocks(),pps.blocksLength=pps.blocks.length,pps.maxLength=Cleave.Util.getMaxLength(pps.blocks))},initPhoneFormatter:function(){var owner=this,pps=owner.properties;if(pps.phone)try{pps.phoneFormatter=new Cleave.PhoneFormatter(new pps.root.Cleave.AsYouTypeFormatter(pps.phoneRegionCode),pps.delimiter)}catch(ex){throw new Error("[cleave.js] Please include phone-type-formatter.{country}.js lib")}},onKeyDown:function(event){var owner=this,pps=owner.properties,charCode=event.which||event.keyCode,Util=Cleave.Util,currentValue=owner.element.value;owner.hasBackspaceSupport=owner.hasBackspaceSupport||8===charCode,!owner.hasBackspaceSupport&&Util.isAndroidBackspaceKeydown(owner.lastInputValue,currentValue)&&(charCode=8),owner.lastInputValue=currentValue;var postDelimiter=Util.getPostDelimiter(currentValue,pps.delimiter,pps.delimiters);8===charCode&&postDelimiter?pps.postDelimiterBackspace=postDelimiter:pps.postDelimiterBackspace=!1},onChange:function(){this.onInput(this.element.value)},onFocus:function(){var owner=this,pps=owner.properties;pps.prefix&&pps.noImmediatePrefix&&!owner.element.value&&this.onInput(pps.prefix),Cleave.Util.fixPrefixCursor(owner.element,pps.prefix,pps.delimiter,pps.delimiters)},onCut:function(e){Cleave.Util.checkFullSelection(this.element.value)&&(this.copyClipboardData(e),this.onInput(""))},onCopy:function(e){Cleave.Util.checkFullSelection(this.element.value)&&this.copyClipboardData(e)},copyClipboardData:function(e){var owner=this,pps=owner.properties,Util=Cleave.Util,inputValue=owner.element.value,textToCopy="";textToCopy=pps.copyDelimiter?inputValue:Util.stripDelimiters(inputValue,pps.delimiter,pps.delimiters);try{e.clipboardData?e.clipboardData.setData("Text",textToCopy):window.clipboardData.setData("Text",textToCopy),e.preventDefault()}catch(ex){}},onInput:function(value){var owner=this,pps=owner.properties,Util=Cleave.Util,postDelimiterAfter=Util.getPostDelimiter(value,pps.delimiter,pps.delimiters);return pps.numeral||!pps.postDelimiterBackspace||postDelimiterAfter||(value=Util.headStr(value,value.length-pps.postDelimiterBackspace.length)),pps.phone?(!pps.prefix||pps.noImmediatePrefix&&!value.length?pps.result=pps.phoneFormatter.format(value):pps.result=pps.prefix+pps.phoneFormatter.format(value).slice(pps.prefix.length),void owner.updateValueState()):pps.numeral?(pps.prefix&&pps.noImmediatePrefix&&0===value.length?pps.result="":pps.result=pps.numeralFormatter.format(value),void owner.updateValueState()):(pps.date&&(value=pps.dateFormatter.getValidatedDate(value)),pps.time&&(value=pps.timeFormatter.getValidatedTime(value)),value=Util.stripDelimiters(value,pps.delimiter,pps.delimiters),value=Util.getPrefixStrippedValue(value,pps.prefix,pps.prefixLength,pps.result,pps.delimiter,pps.delimiters,pps.noImmediatePrefix,pps.tailPrefix,pps.signBeforePrefix),value=pps.numericOnly?Util.strip(value,/[^\d]/g):value,value=pps.uppercase?value.toUpperCase():value,value=pps.lowercase?value.toLowerCase():value,!pps.prefix||pps.noImmediatePrefix&&!value.length||(pps.tailPrefix?value+=pps.prefix:value!==pps.prefix&&(value=pps.prefix+value),0!==pps.blocksLength)?(pps.creditCard&&owner.updateCreditCardPropsByValue(value),value=Util.headStr(value,pps.maxLength),pps.result=Util.getFormattedValue(value,pps.blocks,pps.blocksLength,pps.delimiter,pps.delimiters,pps.delimiterLazyShow),void owner.updateValueState()):(pps.result=value,void owner.updateValueState()))},updateCreditCardPropsByValue:function(value){var creditCardInfo,owner=this,pps=owner.properties,Util=Cleave.Util;Util.headStr(pps.result,4)!==Util.headStr(value,4)&&(creditCardInfo=Cleave.CreditCardDetector.getInfo(value,pps.creditCardStrictMode),pps.blocks=creditCardInfo.blocks,pps.blocksLength=pps.blocks.length,pps.maxLength=Util.getMaxLength(pps.blocks),pps.creditCardType!==creditCardInfo.type&&(pps.creditCardType=creditCardInfo.type,pps.onCreditCardTypeChanged.call(owner,pps.creditCardType)))},updateValueState:function(){var owner=this,Util=Cleave.Util,pps=owner.properties;if(owner.element){var endPos=owner.element.selectionEnd,oldValue=owner.element.value,newValue=pps.result;if(endPos=Util.getNextCursorPosition(endPos,oldValue,newValue,pps.delimiter,pps.delimiters),owner.isAndroid)return void window.setTimeout(function(){owner.element.value=newValue,Util.setSelection(owner.element,endPos,pps.document,!1),owner.callOnValueChanged()},1);owner.element.value=newValue,pps.swapHiddenInput&&(owner.elementSwapHidden.value=owner.getRawValue()),Util.setSelection(owner.element,endPos,pps.document,!1),owner.callOnValueChanged()}},callOnValueChanged:function(){var owner=this,pps=owner.properties;pps.onValueChanged.call(owner,{target:{name:owner.element.name,value:pps.result,rawValue:owner.getRawValue()}})},setPhoneRegionCode:function(phoneRegionCode){var owner=this,pps=owner.properties;pps.phoneRegionCode=phoneRegionCode,owner.initPhoneFormatter(),owner.onChange()},setRawValue:function(value){var owner=this,pps=owner.properties;value=void 0!==value&&null!==value?value.toString():"",pps.numeral&&(value=value.replace(".",pps.numeralDecimalMark)),pps.postDelimiterBackspace=!1,owner.element.value=value,owner.onInput(value)},getRawValue:function(){var owner=this,pps=owner.properties,Util=Cleave.Util,rawValue=owner.element.value;return pps.rawValueTrimPrefix&&(rawValue=Util.getPrefixStrippedValue(rawValue,pps.prefix,pps.prefixLength,pps.result,pps.delimiter,pps.delimiters,pps.noImmediatePrefix,pps.tailPrefix,pps.signBeforePrefix)),rawValue=pps.numeral?pps.numeralFormatter.getRawValue(rawValue):Util.stripDelimiters(rawValue,pps.delimiter,pps.delimiters)},getISOFormatDate:function(){var owner=this,pps=owner.properties;return pps.date?pps.dateFormatter.getISOFormatDate():""},getISOFormatTime:function(){var owner=this,pps=owner.properties;return pps.time?pps.timeFormatter.getISOFormatTime():""},getFormattedValue:function(){return this.element.value},destroy:function(){var owner=this;owner.element.removeEventListener("input",owner.onChangeListener),owner.element.removeEventListener("keydown",owner.onKeyDownListener),owner.element.removeEventListener("focus",owner.onFocusListener),owner.element.removeEventListener("cut",owner.onCutListener),owner.element.removeEventListener("copy",owner.onCopyListener)},toString:function(){return"[Cleave Object]"}},Cleave.NumeralFormatter=__webpack_require__(1),Cleave.DateFormatter=__webpack_require__(2),Cleave.TimeFormatter=__webpack_require__(3),Cleave.PhoneFormatter=__webpack_require__(4),Cleave.CreditCardDetector=__webpack_require__(5),Cleave.Util=__webpack_require__(6),Cleave.DefaultProperties=__webpack_require__(7),("object"==typeof global&&global?global:window).Cleave=Cleave,module.exports=Cleave,angular.module("cleave.js",[]).directive("cleave",function(){return{restrict:"A",require:"ngModel",scope:{cleave:"&",onInit:"&?",onValueChange:"&?"},compile:function(){return{pre:function($scope,$element,attrs,ngModelCtrl){$scope.instance=new Cleave($element[0],$scope.cleave()),$scope.onInit&&$scope.onInit()($scope.instance),ngModelCtrl.$formatters.push(function(val){return $scope.instance.setRawValue(val),$scope.instance.getFormattedValue()}),ngModelCtrl.$parsers.push(function(newFormattedValue){return $scope.onValueChange&&$scope.onValueChange()(newFormattedValue),$scope.instance.getRawValue()}),$scope.$watch(function(){return $scope.cleave()},function(newOptions,oldOptions){$scope.instance.destroy(),$scope.instance=new Cleave($element[0],newOptions)},!0),$scope.$on("$destroy",function(){$scope.instance.destroy(),$scope.instance=null})}}}}})}).call(exports,function(){return this}())},function(module,exports){"use strict";var NumeralFormatter=function(numeralDecimalMark,numeralIntegerScale,numeralDecimalScale,numeralThousandsGroupStyle,numeralPositiveOnly,stripLeadingZeroes,prefix,signBeforePrefix,tailPrefix,delimiter){var owner=this;owner.numeralDecimalMark=numeralDecimalMark||".",owner.numeralIntegerScale=numeralIntegerScale>0?numeralIntegerScale:0,owner.numeralDecimalScale=numeralDecimalScale>=0?numeralDecimalScale:2,owner.numeralThousandsGroupStyle=numeralThousandsGroupStyle||NumeralFormatter.groupStyle.thousand,owner.numeralPositiveOnly=!!numeralPositiveOnly,owner.stripLeadingZeroes=stripLeadingZeroes!==!1,owner.prefix=prefix||""===prefix?prefix:"",owner.signBeforePrefix=!!signBeforePrefix,owner.tailPrefix=!!tailPrefix,owner.delimiter=delimiter||""===delimiter?delimiter:",",owner.delimiterRE=delimiter?new RegExp("\\"+delimiter,"g"):""};NumeralFormatter.groupStyle={thousand:"thousand",lakh:"lakh",wan:"wan",none:"none"},NumeralFormatter.prototype={getRawValue:function(value){return value.replace(this.delimiterRE,"").replace(this.numeralDecimalMark,".")},format:function(value){var parts,partSign,partSignAndPrefix,partInteger,owner=this,partDecimal="";switch(value=value.replace(/[A-Za-z]/g,"").replace(owner.numeralDecimalMark,"M").replace(/[^\dM-]/g,"").replace(/^\-/,"N").replace(/\-/g,"").replace("N",owner.numeralPositiveOnly?"":"-").replace("M",owner.numeralDecimalMark),owner.stripLeadingZeroes&&(value=value.replace(/^(-)?0+(?=\d)/,"$1")),partSign="-"===value.slice(0,1)?"-":"",partSignAndPrefix="undefined"!=typeof owner.prefix?owner.signBeforePrefix?partSign+owner.prefix:owner.prefix+partSign:partSign,partInteger=value,value.indexOf(owner.numeralDecimalMark)>=0&&(parts=value.split(owner.numeralDecimalMark),partInteger=parts[0],partDecimal=owner.numeralDecimalMark+parts[1].slice(0,owner.numeralDecimalScale)),"-"===partSign&&(partInteger=partInteger.slice(1)),owner.numeralIntegerScale>0&&(partInteger=partInteger.slice(0,owner.numeralIntegerScale)),owner.numeralThousandsGroupStyle){case NumeralFormatter.groupStyle.lakh:partInteger=partInteger.replace(/(\d)(?=(\d\d)+\d$)/g,"$1"+owner.delimiter);break;case NumeralFormatter.groupStyle.wan:partInteger=partInteger.replace(/(\d)(?=(\d{4})+$)/g,"$1"+owner.delimiter);break;case NumeralFormatter.groupStyle.thousand:partInteger=partInteger.replace(/(\d)(?=(\d{3})+$)/g,"$1"+owner.delimiter)}return owner.tailPrefix?partSign+partInteger.toString()+(owner.numeralDecimalScale>0?partDecimal.toString():"")+owner.prefix:partSignAndPrefix+partInteger.toString()+(owner.numeralDecimalScale>0?partDecimal.toString():"")}},module.exports=NumeralFormatter},function(module,exports){"use strict";var DateFormatter=function(datePattern,dateMin,dateMax){var owner=this;owner.date=[],owner.blocks=[],owner.datePattern=datePattern,owner.dateMin=dateMin.split("-").reverse().map(function(x){return parseInt(x,10)}),2===owner.dateMin.length&&owner.dateMin.unshift(0),owner.dateMax=dateMax.split("-").reverse().map(function(x){return parseInt(x,10)}),2===owner.dateMax.length&&owner.dateMax.unshift(0),owner.initBlocks()};DateFormatter.prototype={initBlocks:function(){var owner=this;owner.datePattern.forEach(function(value){"Y"===value?owner.blocks.push(4):owner.blocks.push(2)})},getISOFormatDate:function(){var owner=this,date=owner.date;return date[2]?date[2]+"-"+owner.addLeadingZero(date[1])+"-"+owner.addLeadingZero(date[0]):""},getBlocks:function(){return this.blocks},getValidatedDate:function(value){var owner=this,result="";return value=value.replace(/[^\d]/g,""),owner.blocks.forEach(function(length,index){if(value.length>0){var sub=value.slice(0,length),sub0=sub.slice(0,1),rest=value.slice(length);switch(owner.datePattern[index]){case"d":"00"===sub?sub="01":parseInt(sub0,10)>3?sub="0"+sub0:parseInt(sub,10)>31&&(sub="31");break;case"m":"00"===sub?sub="01":parseInt(sub0,10)>1?sub="0"+sub0:parseInt(sub,10)>12&&(sub="12")}result+=sub,value=rest}}),this.getFixedDateString(result)},getFixedDateString:function(value){var day,month,year,owner=this,datePattern=owner.datePattern,date=[],dayIndex=0,monthIndex=0,yearIndex=0,dayStartIndex=0,monthStartIndex=0,yearStartIndex=0,fullYearDone=!1;4===value.length&&"y"!==datePattern[0].toLowerCase()&&"y"!==datePattern[1].toLowerCase()&&(dayStartIndex="d"===datePattern[0]?0:2,monthStartIndex=2-dayStartIndex,day=parseInt(value.slice(dayStartIndex,dayStartIndex+2),10),month=parseInt(value.slice(monthStartIndex,monthStartIndex+2),10),date=this.getFixedDate(day,month,0)),8===value.length&&(datePattern.forEach(function(type,index){switch(type){case"d":dayIndex=index;break;case"m":monthIndex=index;break;default:yearIndex=index}}),yearStartIndex=2*yearIndex,dayStartIndex=dayIndex<=yearIndex?2*dayIndex:2*dayIndex+2,monthStartIndex=monthIndex<=yearIndex?2*monthIndex:2*monthIndex+2,day=parseInt(value.slice(dayStartIndex,dayStartIndex+2),10),month=parseInt(value.slice(monthStartIndex,monthStartIndex+2),10),year=parseInt(value.slice(yearStartIndex,yearStartIndex+4),10),fullYearDone=4===value.slice(yearStartIndex,yearStartIndex+4).length,date=this.getFixedDate(day,month,year)),4!==value.length||"y"!==datePattern[0]&&"y"!==datePattern[1]||(monthStartIndex="m"===datePattern[0]?0:2,yearStartIndex=2-monthStartIndex,month=parseInt(value.slice(monthStartIndex,monthStartIndex+2),10),year=parseInt(value.slice(yearStartIndex,yearStartIndex+2),10),fullYearDone=2===value.slice(yearStartIndex,yearStartIndex+2).length,date=[0,month,year]),6!==value.length||"Y"!==datePattern[0]&&"Y"!==datePattern[1]||(monthStartIndex="m"===datePattern[0]?0:4,yearStartIndex=2-.5*monthStartIndex,month=parseInt(value.slice(monthStartIndex,monthStartIndex+2),10),year=parseInt(value.slice(yearStartIndex,yearStartIndex+4),10),fullYearDone=4===value.slice(yearStartIndex,yearStartIndex+4).length,date=[0,month,year]),date=owner.getRangeFixedDate(date),owner.date=date;var result=0===date.length?value:datePattern.reduce(function(previous,current){switch(current){case"d":return previous+(0===date[0]?"":owner.addLeadingZero(date[0]));case"m":return previous+(0===date[1]?"":owner.addLeadingZero(date[1]));case"y":return previous+(fullYearDone?owner.addLeadingZeroForYear(date[2],!1):"");case"Y":return previous+(fullYearDone?owner.addLeadingZeroForYear(date[2],!0):"")}},"");return result},getRangeFixedDate:function(date){var owner=this,datePattern=owner.datePattern,dateMin=owner.dateMin||[],dateMax=owner.dateMax||[];return!date.length||dateMin.length<3&&dateMax.length<3?date:datePattern.find(function(x){return"y"===x.toLowerCase()})&&0===date[2]?date:dateMax.length&&(dateMax[2]date[2]||dateMin[2]===date[2]&&(dateMin[1]>date[1]||dateMin[1]===date[1]&&dateMin[0]>date[0]))?dateMin:date},getFixedDate:function(day,month,year){return day=Math.min(day,31),month=Math.min(month,12),year=parseInt(year||0,10),(month<7&&month%2===0||month>8&&month%2===1)&&(day=Math.min(day,2===month?this.isLeapYear(year)?29:28:30)),[day,month,year]},isLeapYear:function(year){return year%4===0&&year%100!==0||year%400===0},addLeadingZero:function(number){return(number<10?"0":"")+number},addLeadingZeroForYear:function(number,fullYearMode){return fullYearMode?(number<10?"000":number<100?"00":number<1e3?"0":"")+number:(number<10?"0":"")+number}},module.exports=DateFormatter},function(module,exports){"use strict";var TimeFormatter=function(timePattern,timeFormat){var owner=this;owner.time=[],owner.blocks=[],owner.timePattern=timePattern,owner.timeFormat=timeFormat,owner.initBlocks()};TimeFormatter.prototype={initBlocks:function(){var owner=this;owner.timePattern.forEach(function(){owner.blocks.push(2)})},getISOFormatTime:function(){var owner=this,time=owner.time;return time[2]?owner.addLeadingZero(time[0])+":"+owner.addLeadingZero(time[1])+":"+owner.addLeadingZero(time[2]):""},getBlocks:function(){return this.blocks},getTimeFormatOptions:function(){var owner=this;return"12"===String(owner.timeFormat)?{maxHourFirstDigit:1,maxHours:12,maxMinutesFirstDigit:5,maxMinutes:60}:{maxHourFirstDigit:2,maxHours:23,maxMinutesFirstDigit:5,maxMinutes:60}},getValidatedTime:function(value){var owner=this,result="";value=value.replace(/[^\d]/g,"");var timeFormatOptions=owner.getTimeFormatOptions();return owner.blocks.forEach(function(length,index){if(value.length>0){var sub=value.slice(0,length),sub0=sub.slice(0,1),rest=value.slice(length);switch(owner.timePattern[index]){case"h":parseInt(sub0,10)>timeFormatOptions.maxHourFirstDigit?sub="0"+sub0:parseInt(sub,10)>timeFormatOptions.maxHours&&(sub=timeFormatOptions.maxHours+"");break;case"m":case"s":parseInt(sub0,10)>timeFormatOptions.maxMinutesFirstDigit?sub="0"+sub0:parseInt(sub,10)>timeFormatOptions.maxMinutes&&(sub=timeFormatOptions.maxMinutes+"")}result+=sub,value=rest}}),this.getFixedTimeString(result)},getFixedTimeString:function(value){var second,minute,hour,owner=this,timePattern=owner.timePattern,time=[],secondIndex=0,minuteIndex=0,hourIndex=0,secondStartIndex=0,minuteStartIndex=0,hourStartIndex=0;return 6===value.length&&(timePattern.forEach(function(type,index){switch(type){case"s":secondIndex=2*index;break;case"m":minuteIndex=2*index;break;case"h":hourIndex=2*index}}),hourStartIndex=hourIndex,minuteStartIndex=minuteIndex,secondStartIndex=secondIndex,second=parseInt(value.slice(secondStartIndex,secondStartIndex+2),10),minute=parseInt(value.slice(minuteStartIndex,minuteStartIndex+2),10),hour=parseInt(value.slice(hourStartIndex,hourStartIndex+2),10),time=this.getFixedTime(hour,minute,second)),4===value.length&&owner.timePattern.indexOf("s")<0&&(timePattern.forEach(function(type,index){switch(type){case"m":minuteIndex=2*index;break;case"h":hourIndex=2*index}}),hourStartIndex=hourIndex,minuteStartIndex=minuteIndex,second=0,minute=parseInt(value.slice(minuteStartIndex,minuteStartIndex+2),10),hour=parseInt(value.slice(hourStartIndex,hourStartIndex+2),10),time=this.getFixedTime(hour,minute,second)),owner.time=time,0===time.length?value:timePattern.reduce(function(previous,current){switch(current){case"s":return previous+owner.addLeadingZero(time[2]);case"m":return previous+owner.addLeadingZero(time[1]);case"h":return previous+owner.addLeadingZero(time[0])}},"")},getFixedTime:function(hour,minute,second){return second=Math.min(parseInt(second||0,10),60),minute=Math.min(minute,60),hour=Math.min(hour,60),[hour,minute,second]},addLeadingZero:function(number){return(number<10?"0":"")+number}},module.exports=TimeFormatter},function(module,exports){"use strict";var PhoneFormatter=function(formatter,delimiter){var owner=this;owner.delimiter=delimiter||""===delimiter?delimiter:" ",owner.delimiterRE=delimiter?new RegExp("\\"+delimiter,"g"):"",owner.formatter=formatter};PhoneFormatter.prototype={setFormatter:function(formatter){this.formatter=formatter},format:function(phoneNumber){var owner=this;owner.formatter.clear(),phoneNumber=phoneNumber.replace(/[^\d+]/g,""),phoneNumber=phoneNumber.replace(/^\+/,"B").replace(/\+/g,"").replace("B","+"),phoneNumber=phoneNumber.replace(owner.delimiterRE,"");for(var current,result="",validated=!1,i=0,iMax=phoneNumber.length;i0;return 0===blocksLength?value:(blocks.forEach(function(length,index){if(value.length>0){var sub=value.slice(0,length),rest=value.slice(length);currentDelimiter=multipleDelimiters?delimiters[delimiterLazyShow?index-1:index]||currentDelimiter:delimiter,delimiterLazyShow?(index>0&&(result+=currentDelimiter),result+=sub):(result+=sub,sub.length===length&&index0?opts.numeralIntegerScale:0,target.numeralDecimalScale=opts.numeralDecimalScale>=0?opts.numeralDecimalScale:2,target.numeralDecimalMark=opts.numeralDecimalMark||".",target.numeralThousandsGroupStyle=opts.numeralThousandsGroupStyle||"thousand",target.numeralPositiveOnly=!!opts.numeralPositiveOnly,target.stripLeadingZeroes=opts.stripLeadingZeroes!==!1,target.signBeforePrefix=!!opts.signBeforePrefix,target.tailPrefix=!!opts.tailPrefix,target.swapHiddenInput=!!opts.swapHiddenInput,target.numericOnly=target.creditCard||target.date||!!opts.numericOnly,target.uppercase=!!opts.uppercase,target.lowercase=!!opts.lowercase,target.prefix=target.creditCard||target.date?"":opts.prefix||"",target.noImmediatePrefix=!!opts.noImmediatePrefix,target.prefixLength=target.prefix.length,target.rawValueTrimPrefix=!!opts.rawValueTrimPrefix,target.copyDelimiter=!!opts.copyDelimiter,target.initValue=void 0!==opts.initValue&&null!==opts.initValue?opts.initValue.toString():"",target.delimiter=opts.delimiter||""===opts.delimiter?opts.delimiter:opts.date?"/":opts.time?":":opts.numeral?",":(opts.phone," "),target.delimiterLength=target.delimiter.length,target.delimiterLazyShow=!!opts.delimiterLazyShow,target.delimiters=opts.delimiters||[],target.blocks=opts.blocks||[],target.blocksLength=target.blocks.length,target.root="object"==typeof global&&global?global:window,target.document=opts.document||target.root.document,target.maxLength=0,target.backspace=!1,target.result="",target.onValueChanged=opts.onValueChanged||function(){},target}};module.exports=DefaultProperties}).call(exports,function(){return this}())}])}); \ No newline at end of file diff --git a/dist/cleave-esm.js b/dist/cleave-esm.js index 0ff7652e..9b298d58 100644 --- a/dist/cleave-esm.js +++ b/dist/cleave-esm.js @@ -1,4 +1,4 @@ -var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; +var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; var NumeralFormatter = function (numeralDecimalMark, numeralIntegerScale, @@ -1361,7 +1361,7 @@ Cleave.prototype = { if (pps.prefix && (!pps.noImmediatePrefix || value.length)) { if (pps.tailPrefix) { value = value + pps.prefix; - } else { + } else if(value !== pps.prefix) { value = pps.prefix + value; } diff --git a/dist/cleave-esm.min.js b/dist/cleave-esm.min.js index c1348bf5..d66045dd 100644 --- a/dist/cleave-esm.min.js +++ b/dist/cleave-esm.min.js @@ -1 +1 @@ -var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},t=function(e,i,r,n,a,s,o,l,c,u){this.numeralDecimalMark=e||".",this.numeralIntegerScale=i>0?i:0,this.numeralDecimalScale=r>=0?r:2,this.numeralThousandsGroupStyle=n||t.groupStyle.thousand,this.numeralPositiveOnly=!!a,this.stripLeadingZeroes=!1!==s,this.prefix=o||""===o?o:"",this.signBeforePrefix=!!l,this.tailPrefix=!!c,this.delimiter=u||""===u?u:",",this.delimiterRE=u?new RegExp("\\"+u,"g"):""};t.groupStyle={thousand:"thousand",lakh:"lakh",wan:"wan",none:"none"},t.prototype={getRawValue:function(e){return e.replace(this.delimiterRE,"").replace(this.numeralDecimalMark,".")},format:function(e){var i,r,n,a,s="";switch(e=e.replace(/[A-Za-z]/g,"").replace(this.numeralDecimalMark,"M").replace(/[^\dM-]/g,"").replace(/^\-/,"N").replace(/\-/g,"").replace("N",this.numeralPositiveOnly?"":"-").replace("M",this.numeralDecimalMark),this.stripLeadingZeroes&&(e=e.replace(/^(-)?0+(?=\d)/,"$1")),r="-"===e.slice(0,1)?"-":"",n=void 0!==this.prefix?this.signBeforePrefix?r+this.prefix:this.prefix+r:r,a=e,e.indexOf(this.numeralDecimalMark)>=0&&(a=(i=e.split(this.numeralDecimalMark))[0],s=this.numeralDecimalMark+i[1].slice(0,this.numeralDecimalScale)),"-"===r&&(a=a.slice(1)),this.numeralIntegerScale>0&&(a=a.slice(0,this.numeralIntegerScale)),this.numeralThousandsGroupStyle){case t.groupStyle.lakh:a=a.replace(/(\d)(?=(\d\d)+\d$)/g,"$1"+this.delimiter);break;case t.groupStyle.wan:a=a.replace(/(\d)(?=(\d{4})+$)/g,"$1"+this.delimiter);break;case t.groupStyle.thousand:a=a.replace(/(\d)(?=(\d{3})+$)/g,"$1"+this.delimiter)}return this.tailPrefix?r+a.toString()+(this.numeralDecimalScale>0?s.toString():"")+this.prefix:n+a.toString()+(this.numeralDecimalScale>0?s.toString():"")}};var i=t,r=function(e,t,i){this.date=[],this.blocks=[],this.datePattern=e,this.dateMin=t.split("-").reverse().map(function(e){return parseInt(e,10)}),2===this.dateMin.length&&this.dateMin.unshift(0),this.dateMax=i.split("-").reverse().map(function(e){return parseInt(e,10)}),2===this.dateMax.length&&this.dateMax.unshift(0),this.initBlocks()};r.prototype={initBlocks:function(){var e=this;e.datePattern.forEach(function(t){"Y"===t?e.blocks.push(4):e.blocks.push(2)})},getISOFormatDate:function(){var e=this.date;return e[2]?e[2]+"-"+this.addLeadingZero(e[1])+"-"+this.addLeadingZero(e[0]):""},getBlocks:function(){return this.blocks},getValidatedDate:function(e){var t=this,i="";return e=e.replace(/[^\d]/g,""),t.blocks.forEach(function(r,n){if(e.length>0){var a=e.slice(0,r),s=a.slice(0,1),o=e.slice(r);switch(t.datePattern[n]){case"d":"00"===a?a="01":parseInt(s,10)>3?a="0"+s:parseInt(a,10)>31&&(a="31");break;case"m":"00"===a?a="01":parseInt(s,10)>1?a="0"+s:parseInt(a,10)>12&&(a="12")}i+=a,e=o}}),this.getFixedDateString(i)},getFixedDateString:function(e){var t,i,r,n=this,a=n.datePattern,s=[],o=0,l=0,c=0,u=0,d=0,h=0,m=!1;return 4===e.length&&"y"!==a[0].toLowerCase()&&"y"!==a[1].toLowerCase()&&(d=2-(u="d"===a[0]?0:2),t=parseInt(e.slice(u,u+2),10),i=parseInt(e.slice(d,d+2),10),s=this.getFixedDate(t,i,0)),8===e.length&&(a.forEach(function(e,t){switch(e){case"d":o=t;break;case"m":l=t;break;default:c=t}}),h=2*c,u=o<=c?2*o:2*o+2,d=l<=c?2*l:2*l+2,t=parseInt(e.slice(u,u+2),10),i=parseInt(e.slice(d,d+2),10),r=parseInt(e.slice(h,h+4),10),m=4===e.slice(h,h+4).length,s=this.getFixedDate(t,i,r)),4!==e.length||"y"!==a[0]&&"y"!==a[1]||(h=2-(d="m"===a[0]?0:2),i=parseInt(e.slice(d,d+2),10),r=parseInt(e.slice(h,h+2),10),m=2===e.slice(h,h+2).length,s=[0,i,r]),6!==e.length||"Y"!==a[0]&&"Y"!==a[1]||(h=2-.5*(d="m"===a[0]?0:4),i=parseInt(e.slice(d,d+2),10),r=parseInt(e.slice(h,h+4),10),m=4===e.slice(h,h+4).length,s=[0,i,r]),s=n.getRangeFixedDate(s),n.date=s,0===s.length?e:a.reduce(function(e,t){switch(t){case"d":return e+(0===s[0]?"":n.addLeadingZero(s[0]));case"m":return e+(0===s[1]?"":n.addLeadingZero(s[1]));case"y":return e+(m?n.addLeadingZeroForYear(s[2],!1):"");case"Y":return e+(m?n.addLeadingZeroForYear(s[2],!0):"")}},"")},getRangeFixedDate:function(e){var t=this.datePattern,i=this.dateMin||[],r=this.dateMax||[];return!e.length||i.length<3&&r.length<3?e:t.find(function(e){return"y"===e.toLowerCase()})&&0===e[2]?e:r.length&&(r[2]e[2]||i[2]===e[2]&&(i[1]>e[1]||i[1]===e[1]&&i[0]>e[0]))?i:e},getFixedDate:function(e,t,i){return e=Math.min(e,31),t=Math.min(t,12),i=parseInt(i||0,10),(t<7&&t%2==0||t>8&&t%2==1)&&(e=Math.min(e,2===t?this.isLeapYear(i)?29:28:30)),[e,t,i]},isLeapYear:function(e){return e%4==0&&e%100!=0||e%400==0},addLeadingZero:function(e){return(e<10?"0":"")+e},addLeadingZeroForYear:function(e,t){return t?(e<10?"000":e<100?"00":e<1e3?"0":"")+e:(e<10?"0":"")+e}};var n=r,a=function(e,t){this.time=[],this.blocks=[],this.timePattern=e,this.timeFormat=t,this.initBlocks()};a.prototype={initBlocks:function(){var e=this;e.timePattern.forEach(function(){e.blocks.push(2)})},getISOFormatTime:function(){var e=this.time;return e[2]?this.addLeadingZero(e[0])+":"+this.addLeadingZero(e[1])+":"+this.addLeadingZero(e[2]):""},getBlocks:function(){return this.blocks},getTimeFormatOptions:function(){return"12"===String(this.timeFormat)?{maxHourFirstDigit:1,maxHours:12,maxMinutesFirstDigit:5,maxMinutes:60}:{maxHourFirstDigit:2,maxHours:23,maxMinutesFirstDigit:5,maxMinutes:60}},getValidatedTime:function(e){var t=this,i="";e=e.replace(/[^\d]/g,"");var r=t.getTimeFormatOptions();return t.blocks.forEach(function(n,a){if(e.length>0){var s=e.slice(0,n),o=s.slice(0,1),l=e.slice(n);switch(t.timePattern[a]){case"h":parseInt(o,10)>r.maxHourFirstDigit?s="0"+o:parseInt(s,10)>r.maxHours&&(s=r.maxHours+"");break;case"m":case"s":parseInt(o,10)>r.maxMinutesFirstDigit?s="0"+o:parseInt(s,10)>r.maxMinutes&&(s=r.maxMinutes+"")}i+=s,e=l}}),this.getFixedTimeString(i)},getFixedTimeString:function(e){var t,i,r,n=this,a=n.timePattern,s=[],o=0,l=0,c=0,u=0,d=0,h=0;return 6===e.length&&(a.forEach(function(e,t){switch(e){case"s":o=2*t;break;case"m":l=2*t;break;case"h":c=2*t}}),h=c,d=l,u=o,t=parseInt(e.slice(u,u+2),10),i=parseInt(e.slice(d,d+2),10),r=parseInt(e.slice(h,h+2),10),s=this.getFixedTime(r,i,t)),4===e.length&&n.timePattern.indexOf("s")<0&&(a.forEach(function(e,t){switch(e){case"m":l=2*t;break;case"h":c=2*t}}),h=c,d=l,t=0,i=parseInt(e.slice(d,d+2),10),r=parseInt(e.slice(h,h+2),10),s=this.getFixedTime(r,i,t)),n.time=s,0===s.length?e:a.reduce(function(e,t){switch(t){case"s":return e+n.addLeadingZero(s[2]);case"m":return e+n.addLeadingZero(s[1]);case"h":return e+n.addLeadingZero(s[0])}},"")},getFixedTime:function(e,t,i){return i=Math.min(parseInt(i||0,10),60),t=Math.min(t,60),[e=Math.min(e,60),t,i]},addLeadingZero:function(e){return(e<10?"0":"")+e}};var s=a,o=function(e,t){this.delimiter=t||""===t?t:" ",this.delimiterRE=t?new RegExp("\\"+t,"g"):"",this.formatter=e};o.prototype={setFormatter:function(e){this.formatter=e},format:function(e){this.formatter.clear();for(var t,i="",r=!1,n=0,a=(e=(e=(e=e.replace(/[^\d+]/g,"")).replace(/^\+/,"B").replace(/\+/g,"").replace("B","+")).replace(this.delimiterRE,"")).length;n0;return 0===i?e:(t.forEach(function(t,c){if(e.length>0){var u=e.slice(0,t),d=e.slice(t);s=l?n[a?c-1:c]||s:r,a?(c>0&&(o+=s),o+=u):(o+=u,u.length===t&&c0?i.numeralIntegerScale:0,t.numeralDecimalScale=i.numeralDecimalScale>=0?i.numeralDecimalScale:2,t.numeralDecimalMark=i.numeralDecimalMark||".",t.numeralThousandsGroupStyle=i.numeralThousandsGroupStyle||"thousand",t.numeralPositiveOnly=!!i.numeralPositiveOnly,t.stripLeadingZeroes=!1!==i.stripLeadingZeroes,t.signBeforePrefix=!!i.signBeforePrefix,t.tailPrefix=!!i.tailPrefix,t.swapHiddenInput=!!i.swapHiddenInput,t.numericOnly=t.creditCard||t.date||!!i.numericOnly,t.uppercase=!!i.uppercase,t.lowercase=!!i.lowercase,t.prefix=t.creditCard||t.date?"":i.prefix||"",t.noImmediatePrefix=!!i.noImmediatePrefix,t.prefixLength=t.prefix.length,t.rawValueTrimPrefix=!!i.rawValueTrimPrefix,t.copyDelimiter=!!i.copyDelimiter,t.initValue=void 0!==i.initValue&&null!==i.initValue?i.initValue.toString():"",t.delimiter=i.delimiter||""===i.delimiter?i.delimiter:i.date?"/":i.time?":":i.numeral?",":(i.phone," "),t.delimiterLength=t.delimiter.length,t.delimiterLazyShow=!!i.delimiterLazyShow,t.delimiters=i.delimiters||[],t.blocks=i.blocks||[],t.blocksLength=t.blocks.length,t.root="object"==typeof e&&e?e:window,t.document=i.document||t.root.document,t.maxLength=0,t.backspace=!1,t.result="",t.onValueChanged=i.onValueChanged||function(){},t}},m=function(e,t){var i=!1;if("string"==typeof e?(this.element=document.querySelector(e),i=document.querySelectorAll(e).length>1):void 0!==e.length&&e.length>0?(this.element=e[0],i=e.length>1):this.element=e,!this.element)throw new Error("[cleave.js] Please check the element");if(i)try{console.warn("[cleave.js] Multiple input fields matched, cleave.js will only take the first one.")}catch(e){}t.initValue=this.element.value,this.properties=m.DefaultProperties.assign({},t),this.init()};m.prototype={init:function(){var e=this.properties;e.numeral||e.phone||e.creditCard||e.time||e.date||0!==e.blocksLength||e.prefix?(e.maxLength=m.Util.getMaxLength(e.blocks),this.isAndroid=m.Util.isAndroid(),this.lastInputValue="",this.onChangeListener=this.onChange.bind(this),this.onKeyDownListener=this.onKeyDown.bind(this),this.onFocusListener=this.onFocus.bind(this),this.onCutListener=this.onCut.bind(this),this.onCopyListener=this.onCopy.bind(this),this.initSwapHiddenInput(),this.element.addEventListener("input",this.onChangeListener),this.element.addEventListener("keydown",this.onKeyDownListener),this.element.addEventListener("focus",this.onFocusListener),this.element.addEventListener("cut",this.onCutListener),this.element.addEventListener("copy",this.onCopyListener),this.initPhoneFormatter(),this.initDateFormatter(),this.initTimeFormatter(),this.initNumeralFormatter(),(e.initValue||e.prefix&&!e.noImmediatePrefix)&&this.onInput(e.initValue)):this.onInput(e.initValue)},initSwapHiddenInput:function(){if(this.properties.swapHiddenInput){var e=this.element.cloneNode(!0);this.element.parentNode.insertBefore(e,this.element),this.elementSwapHidden=this.element,this.elementSwapHidden.type="hidden",this.element=e,this.element.id=""}},initNumeralFormatter:function(){var e=this.properties;e.numeral&&(e.numeralFormatter=new m.NumeralFormatter(e.numeralDecimalMark,e.numeralIntegerScale,e.numeralDecimalScale,e.numeralThousandsGroupStyle,e.numeralPositiveOnly,e.stripLeadingZeroes,e.prefix,e.signBeforePrefix,e.tailPrefix,e.delimiter))},initTimeFormatter:function(){var e=this.properties;e.time&&(e.timeFormatter=new m.TimeFormatter(e.timePattern,e.timeFormat),e.blocks=e.timeFormatter.getBlocks(),e.blocksLength=e.blocks.length,e.maxLength=m.Util.getMaxLength(e.blocks))},initDateFormatter:function(){var e=this.properties;e.date&&(e.dateFormatter=new m.DateFormatter(e.datePattern,e.dateMin,e.dateMax),e.blocks=e.dateFormatter.getBlocks(),e.blocksLength=e.blocks.length,e.maxLength=m.Util.getMaxLength(e.blocks))},initPhoneFormatter:function(){var e=this.properties;if(e.phone)try{e.phoneFormatter=new m.PhoneFormatter(new e.root.Cleave.AsYouTypeFormatter(e.phoneRegionCode),e.delimiter)}catch(e){throw new Error("[cleave.js] Please include phone-type-formatter.{country}.js lib")}},onKeyDown:function(e){var t=this.properties,i=e.which||e.keyCode,r=m.Util,n=this.element.value;this.hasBackspaceSupport=this.hasBackspaceSupport||8===i,!this.hasBackspaceSupport&&r.isAndroidBackspaceKeydown(this.lastInputValue,n)&&(i=8),this.lastInputValue=n;var a=r.getPostDelimiter(n,t.delimiter,t.delimiters);t.postDelimiterBackspace=!(8!==i||!a)&&a},onChange:function(){this.onInput(this.element.value)},onFocus:function(){var e=this.properties;e.prefix&&e.noImmediatePrefix&&!this.element.value&&this.onInput(e.prefix),m.Util.fixPrefixCursor(this.element,e.prefix,e.delimiter,e.delimiters)},onCut:function(e){m.Util.checkFullSelection(this.element.value)&&(this.copyClipboardData(e),this.onInput(""))},onCopy:function(e){m.Util.checkFullSelection(this.element.value)&&this.copyClipboardData(e)},copyClipboardData:function(e){var t=this.properties,i=m.Util,r=this.element.value,n="";n=t.copyDelimiter?r:i.stripDelimiters(r,t.delimiter,t.delimiters);try{e.clipboardData?e.clipboardData.setData("Text",n):window.clipboardData.setData("Text",n),e.preventDefault()}catch(e){}},onInput:function(e){var t=this.properties,i=m.Util,r=i.getPostDelimiter(e,t.delimiter,t.delimiters);return t.numeral||!t.postDelimiterBackspace||r||(e=i.headStr(e,e.length-t.postDelimiterBackspace.length)),t.phone?(!t.prefix||t.noImmediatePrefix&&!e.length?t.result=t.phoneFormatter.format(e):t.result=t.prefix+t.phoneFormatter.format(e).slice(t.prefix.length),void this.updateValueState()):t.numeral?(t.prefix&&t.noImmediatePrefix&&0===e.length?t.result="":t.result=t.numeralFormatter.format(e),void this.updateValueState()):(t.date&&(e=t.dateFormatter.getValidatedDate(e)),t.time&&(e=t.timeFormatter.getValidatedTime(e)),e=i.stripDelimiters(e,t.delimiter,t.delimiters),e=i.getPrefixStrippedValue(e,t.prefix,t.prefixLength,t.result,t.delimiter,t.delimiters,t.noImmediatePrefix,t.tailPrefix,t.signBeforePrefix),e=t.numericOnly?i.strip(e,/[^\d]/g):e,e=t.uppercase?e.toUpperCase():e,e=t.lowercase?e.toLowerCase():e,!t.prefix||t.noImmediatePrefix&&!e.length||(t.tailPrefix?e+=t.prefix:e=t.prefix+e,0!==t.blocksLength)?(t.creditCard&&this.updateCreditCardPropsByValue(e),e=i.headStr(e,t.maxLength),t.result=i.getFormattedValue(e,t.blocks,t.blocksLength,t.delimiter,t.delimiters,t.delimiterLazyShow),void this.updateValueState()):(t.result=e,void this.updateValueState()))},updateCreditCardPropsByValue:function(e){var t,i=this.properties,r=m.Util;r.headStr(i.result,4)!==r.headStr(e,4)&&(t=m.CreditCardDetector.getInfo(e,i.creditCardStrictMode),i.blocks=t.blocks,i.blocksLength=i.blocks.length,i.maxLength=r.getMaxLength(i.blocks),i.creditCardType!==t.type&&(i.creditCardType=t.type,i.onCreditCardTypeChanged.call(this,i.creditCardType)))},updateValueState:function(){var e=this,t=m.Util,i=e.properties;if(e.element){var r=e.element.selectionEnd,n=e.element.value,a=i.result;r=t.getNextCursorPosition(r,n,a,i.delimiter,i.delimiters),e.isAndroid?window.setTimeout(function(){e.element.value=a,t.setSelection(e.element,r,i.document,!1),e.callOnValueChanged()},1):(e.element.value=a,i.swapHiddenInput&&(e.elementSwapHidden.value=e.getRawValue()),t.setSelection(e.element,r,i.document,!1),e.callOnValueChanged())}},callOnValueChanged:function(){var e=this.properties;e.onValueChanged.call(this,{target:{name:this.element.name,value:e.result,rawValue:this.getRawValue()}})},setPhoneRegionCode:function(e){this.properties.phoneRegionCode=e,this.initPhoneFormatter(),this.onChange()},setRawValue:function(e){var t=this.properties;e=null!=e?e.toString():"",t.numeral&&(e=e.replace(".",t.numeralDecimalMark)),t.postDelimiterBackspace=!1,this.element.value=e,this.onInput(e)},getRawValue:function(){var e=this.properties,t=m.Util,i=this.element.value;return e.rawValueTrimPrefix&&(i=t.getPrefixStrippedValue(i,e.prefix,e.prefixLength,e.result,e.delimiter,e.delimiters,e.noImmediatePrefix,e.tailPrefix,e.signBeforePrefix)),i=e.numeral?e.numeralFormatter.getRawValue(i):t.stripDelimiters(i,e.delimiter,e.delimiters)},getISOFormatDate:function(){var e=this.properties;return e.date?e.dateFormatter.getISOFormatDate():""},getISOFormatTime:function(){var e=this.properties;return e.time?e.timeFormatter.getISOFormatTime():""},getFormattedValue:function(){return this.element.value},destroy:function(){this.element.removeEventListener("input",this.onChangeListener),this.element.removeEventListener("keydown",this.onKeyDownListener),this.element.removeEventListener("focus",this.onFocusListener),this.element.removeEventListener("cut",this.onCutListener),this.element.removeEventListener("copy",this.onCopyListener)},toString:function(){return"[Cleave Object]"}},m.NumeralFormatter=i,m.DateFormatter=n,m.TimeFormatter=s,m.PhoneFormatter=l,m.CreditCardDetector=u,m.Util=d,m.DefaultProperties=h,("object"==typeof e&&e?e:window).Cleave=m;export default m; \ No newline at end of file +var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},t=function(e,i,r,n,a,s,o,l,c,u){this.numeralDecimalMark=e||".",this.numeralIntegerScale=i>0?i:0,this.numeralDecimalScale=r>=0?r:2,this.numeralThousandsGroupStyle=n||t.groupStyle.thousand,this.numeralPositiveOnly=!!a,this.stripLeadingZeroes=!1!==s,this.prefix=o||""===o?o:"",this.signBeforePrefix=!!l,this.tailPrefix=!!c,this.delimiter=u||""===u?u:",",this.delimiterRE=u?new RegExp("\\"+u,"g"):""};t.groupStyle={thousand:"thousand",lakh:"lakh",wan:"wan",none:"none"},t.prototype={getRawValue:function(e){return e.replace(this.delimiterRE,"").replace(this.numeralDecimalMark,".")},format:function(e){var i,r,n,a,s="";switch(e=e.replace(/[A-Za-z]/g,"").replace(this.numeralDecimalMark,"M").replace(/[^\dM-]/g,"").replace(/^\-/,"N").replace(/\-/g,"").replace("N",this.numeralPositiveOnly?"":"-").replace("M",this.numeralDecimalMark),this.stripLeadingZeroes&&(e=e.replace(/^(-)?0+(?=\d)/,"$1")),r="-"===e.slice(0,1)?"-":"",n=void 0!==this.prefix?this.signBeforePrefix?r+this.prefix:this.prefix+r:r,a=e,e.indexOf(this.numeralDecimalMark)>=0&&(a=(i=e.split(this.numeralDecimalMark))[0],s=this.numeralDecimalMark+i[1].slice(0,this.numeralDecimalScale)),"-"===r&&(a=a.slice(1)),this.numeralIntegerScale>0&&(a=a.slice(0,this.numeralIntegerScale)),this.numeralThousandsGroupStyle){case t.groupStyle.lakh:a=a.replace(/(\d)(?=(\d\d)+\d$)/g,"$1"+this.delimiter);break;case t.groupStyle.wan:a=a.replace(/(\d)(?=(\d{4})+$)/g,"$1"+this.delimiter);break;case t.groupStyle.thousand:a=a.replace(/(\d)(?=(\d{3})+$)/g,"$1"+this.delimiter)}return this.tailPrefix?r+a.toString()+(this.numeralDecimalScale>0?s.toString():"")+this.prefix:n+a.toString()+(this.numeralDecimalScale>0?s.toString():"")}};var i=t,r=function(e,t,i){this.date=[],this.blocks=[],this.datePattern=e,this.dateMin=t.split("-").reverse().map(function(e){return parseInt(e,10)}),2===this.dateMin.length&&this.dateMin.unshift(0),this.dateMax=i.split("-").reverse().map(function(e){return parseInt(e,10)}),2===this.dateMax.length&&this.dateMax.unshift(0),this.initBlocks()};r.prototype={initBlocks:function(){var e=this;e.datePattern.forEach(function(t){"Y"===t?e.blocks.push(4):e.blocks.push(2)})},getISOFormatDate:function(){var e=this.date;return e[2]?e[2]+"-"+this.addLeadingZero(e[1])+"-"+this.addLeadingZero(e[0]):""},getBlocks:function(){return this.blocks},getValidatedDate:function(e){var t=this,i="";return e=e.replace(/[^\d]/g,""),t.blocks.forEach(function(r,n){if(e.length>0){var a=e.slice(0,r),s=a.slice(0,1),o=e.slice(r);switch(t.datePattern[n]){case"d":"00"===a?a="01":parseInt(s,10)>3?a="0"+s:parseInt(a,10)>31&&(a="31");break;case"m":"00"===a?a="01":parseInt(s,10)>1?a="0"+s:parseInt(a,10)>12&&(a="12")}i+=a,e=o}}),this.getFixedDateString(i)},getFixedDateString:function(e){var t,i,r,n=this,a=n.datePattern,s=[],o=0,l=0,c=0,u=0,d=0,h=0,m=!1;return 4===e.length&&"y"!==a[0].toLowerCase()&&"y"!==a[1].toLowerCase()&&(d=2-(u="d"===a[0]?0:2),t=parseInt(e.slice(u,u+2),10),i=parseInt(e.slice(d,d+2),10),s=this.getFixedDate(t,i,0)),8===e.length&&(a.forEach(function(e,t){switch(e){case"d":o=t;break;case"m":l=t;break;default:c=t}}),h=2*c,u=o<=c?2*o:2*o+2,d=l<=c?2*l:2*l+2,t=parseInt(e.slice(u,u+2),10),i=parseInt(e.slice(d,d+2),10),r=parseInt(e.slice(h,h+4),10),m=4===e.slice(h,h+4).length,s=this.getFixedDate(t,i,r)),4!==e.length||"y"!==a[0]&&"y"!==a[1]||(h=2-(d="m"===a[0]?0:2),i=parseInt(e.slice(d,d+2),10),r=parseInt(e.slice(h,h+2),10),m=2===e.slice(h,h+2).length,s=[0,i,r]),6!==e.length||"Y"!==a[0]&&"Y"!==a[1]||(h=2-.5*(d="m"===a[0]?0:4),i=parseInt(e.slice(d,d+2),10),r=parseInt(e.slice(h,h+4),10),m=4===e.slice(h,h+4).length,s=[0,i,r]),s=n.getRangeFixedDate(s),n.date=s,0===s.length?e:a.reduce(function(e,t){switch(t){case"d":return e+(0===s[0]?"":n.addLeadingZero(s[0]));case"m":return e+(0===s[1]?"":n.addLeadingZero(s[1]));case"y":return e+(m?n.addLeadingZeroForYear(s[2],!1):"");case"Y":return e+(m?n.addLeadingZeroForYear(s[2],!0):"")}},"")},getRangeFixedDate:function(e){var t=this.datePattern,i=this.dateMin||[],r=this.dateMax||[];return!e.length||i.length<3&&r.length<3?e:t.find(function(e){return"y"===e.toLowerCase()})&&0===e[2]?e:r.length&&(r[2]e[2]||i[2]===e[2]&&(i[1]>e[1]||i[1]===e[1]&&i[0]>e[0]))?i:e},getFixedDate:function(e,t,i){return e=Math.min(e,31),t=Math.min(t,12),i=parseInt(i||0,10),(t<7&&t%2==0||t>8&&t%2==1)&&(e=Math.min(e,2===t?this.isLeapYear(i)?29:28:30)),[e,t,i]},isLeapYear:function(e){return e%4==0&&e%100!=0||e%400==0},addLeadingZero:function(e){return(e<10?"0":"")+e},addLeadingZeroForYear:function(e,t){return t?(e<10?"000":e<100?"00":e<1e3?"0":"")+e:(e<10?"0":"")+e}};var n=r,a=function(e,t){this.time=[],this.blocks=[],this.timePattern=e,this.timeFormat=t,this.initBlocks()};a.prototype={initBlocks:function(){var e=this;e.timePattern.forEach(function(){e.blocks.push(2)})},getISOFormatTime:function(){var e=this.time;return e[2]?this.addLeadingZero(e[0])+":"+this.addLeadingZero(e[1])+":"+this.addLeadingZero(e[2]):""},getBlocks:function(){return this.blocks},getTimeFormatOptions:function(){return"12"===String(this.timeFormat)?{maxHourFirstDigit:1,maxHours:12,maxMinutesFirstDigit:5,maxMinutes:60}:{maxHourFirstDigit:2,maxHours:23,maxMinutesFirstDigit:5,maxMinutes:60}},getValidatedTime:function(e){var t=this,i="";e=e.replace(/[^\d]/g,"");var r=t.getTimeFormatOptions();return t.blocks.forEach(function(n,a){if(e.length>0){var s=e.slice(0,n),o=s.slice(0,1),l=e.slice(n);switch(t.timePattern[a]){case"h":parseInt(o,10)>r.maxHourFirstDigit?s="0"+o:parseInt(s,10)>r.maxHours&&(s=r.maxHours+"");break;case"m":case"s":parseInt(o,10)>r.maxMinutesFirstDigit?s="0"+o:parseInt(s,10)>r.maxMinutes&&(s=r.maxMinutes+"")}i+=s,e=l}}),this.getFixedTimeString(i)},getFixedTimeString:function(e){var t,i,r,n=this,a=n.timePattern,s=[],o=0,l=0,c=0,u=0,d=0,h=0;return 6===e.length&&(a.forEach(function(e,t){switch(e){case"s":o=2*t;break;case"m":l=2*t;break;case"h":c=2*t}}),h=c,d=l,u=o,t=parseInt(e.slice(u,u+2),10),i=parseInt(e.slice(d,d+2),10),r=parseInt(e.slice(h,h+2),10),s=this.getFixedTime(r,i,t)),4===e.length&&n.timePattern.indexOf("s")<0&&(a.forEach(function(e,t){switch(e){case"m":l=2*t;break;case"h":c=2*t}}),h=c,d=l,t=0,i=parseInt(e.slice(d,d+2),10),r=parseInt(e.slice(h,h+2),10),s=this.getFixedTime(r,i,t)),n.time=s,0===s.length?e:a.reduce(function(e,t){switch(t){case"s":return e+n.addLeadingZero(s[2]);case"m":return e+n.addLeadingZero(s[1]);case"h":return e+n.addLeadingZero(s[0])}},"")},getFixedTime:function(e,t,i){return i=Math.min(parseInt(i||0,10),60),t=Math.min(t,60),[e=Math.min(e,60),t,i]},addLeadingZero:function(e){return(e<10?"0":"")+e}};var s=a,o=function(e,t){this.delimiter=t||""===t?t:" ",this.delimiterRE=t?new RegExp("\\"+t,"g"):"",this.formatter=e};o.prototype={setFormatter:function(e){this.formatter=e},format:function(e){this.formatter.clear();for(var t,i="",r=!1,n=0,a=(e=(e=(e=e.replace(/[^\d+]/g,"")).replace(/^\+/,"B").replace(/\+/g,"").replace("B","+")).replace(this.delimiterRE,"")).length;n0;return 0===i?e:(t.forEach(function(t,c){if(e.length>0){var u=e.slice(0,t),d=e.slice(t);s=l?n[a?c-1:c]||s:r,a?(c>0&&(o+=s),o+=u):(o+=u,u.length===t&&c0?i.numeralIntegerScale:0,t.numeralDecimalScale=i.numeralDecimalScale>=0?i.numeralDecimalScale:2,t.numeralDecimalMark=i.numeralDecimalMark||".",t.numeralThousandsGroupStyle=i.numeralThousandsGroupStyle||"thousand",t.numeralPositiveOnly=!!i.numeralPositiveOnly,t.stripLeadingZeroes=!1!==i.stripLeadingZeroes,t.signBeforePrefix=!!i.signBeforePrefix,t.tailPrefix=!!i.tailPrefix,t.swapHiddenInput=!!i.swapHiddenInput,t.numericOnly=t.creditCard||t.date||!!i.numericOnly,t.uppercase=!!i.uppercase,t.lowercase=!!i.lowercase,t.prefix=t.creditCard||t.date?"":i.prefix||"",t.noImmediatePrefix=!!i.noImmediatePrefix,t.prefixLength=t.prefix.length,t.rawValueTrimPrefix=!!i.rawValueTrimPrefix,t.copyDelimiter=!!i.copyDelimiter,t.initValue=void 0!==i.initValue&&null!==i.initValue?i.initValue.toString():"",t.delimiter=i.delimiter||""===i.delimiter?i.delimiter:i.date?"/":i.time?":":i.numeral?",":(i.phone," "),t.delimiterLength=t.delimiter.length,t.delimiterLazyShow=!!i.delimiterLazyShow,t.delimiters=i.delimiters||[],t.blocks=i.blocks||[],t.blocksLength=t.blocks.length,t.root="object"==typeof e&&e?e:window,t.document=i.document||t.root.document,t.maxLength=0,t.backspace=!1,t.result="",t.onValueChanged=i.onValueChanged||function(){},t}},m=function(e,t){var i=!1;if("string"==typeof e?(this.element=document.querySelector(e),i=document.querySelectorAll(e).length>1):void 0!==e.length&&e.length>0?(this.element=e[0],i=e.length>1):this.element=e,!this.element)throw new Error("[cleave.js] Please check the element");if(i)try{console.warn("[cleave.js] Multiple input fields matched, cleave.js will only take the first one.")}catch(e){}t.initValue=this.element.value,this.properties=m.DefaultProperties.assign({},t),this.init()};m.prototype={init:function(){var e=this.properties;e.numeral||e.phone||e.creditCard||e.time||e.date||0!==e.blocksLength||e.prefix?(e.maxLength=m.Util.getMaxLength(e.blocks),this.isAndroid=m.Util.isAndroid(),this.lastInputValue="",this.onChangeListener=this.onChange.bind(this),this.onKeyDownListener=this.onKeyDown.bind(this),this.onFocusListener=this.onFocus.bind(this),this.onCutListener=this.onCut.bind(this),this.onCopyListener=this.onCopy.bind(this),this.initSwapHiddenInput(),this.element.addEventListener("input",this.onChangeListener),this.element.addEventListener("keydown",this.onKeyDownListener),this.element.addEventListener("focus",this.onFocusListener),this.element.addEventListener("cut",this.onCutListener),this.element.addEventListener("copy",this.onCopyListener),this.initPhoneFormatter(),this.initDateFormatter(),this.initTimeFormatter(),this.initNumeralFormatter(),(e.initValue||e.prefix&&!e.noImmediatePrefix)&&this.onInput(e.initValue)):this.onInput(e.initValue)},initSwapHiddenInput:function(){if(this.properties.swapHiddenInput){var e=this.element.cloneNode(!0);this.element.parentNode.insertBefore(e,this.element),this.elementSwapHidden=this.element,this.elementSwapHidden.type="hidden",this.element=e,this.element.id=""}},initNumeralFormatter:function(){var e=this.properties;e.numeral&&(e.numeralFormatter=new m.NumeralFormatter(e.numeralDecimalMark,e.numeralIntegerScale,e.numeralDecimalScale,e.numeralThousandsGroupStyle,e.numeralPositiveOnly,e.stripLeadingZeroes,e.prefix,e.signBeforePrefix,e.tailPrefix,e.delimiter))},initTimeFormatter:function(){var e=this.properties;e.time&&(e.timeFormatter=new m.TimeFormatter(e.timePattern,e.timeFormat),e.blocks=e.timeFormatter.getBlocks(),e.blocksLength=e.blocks.length,e.maxLength=m.Util.getMaxLength(e.blocks))},initDateFormatter:function(){var e=this.properties;e.date&&(e.dateFormatter=new m.DateFormatter(e.datePattern,e.dateMin,e.dateMax),e.blocks=e.dateFormatter.getBlocks(),e.blocksLength=e.blocks.length,e.maxLength=m.Util.getMaxLength(e.blocks))},initPhoneFormatter:function(){var e=this.properties;if(e.phone)try{e.phoneFormatter=new m.PhoneFormatter(new e.root.Cleave.AsYouTypeFormatter(e.phoneRegionCode),e.delimiter)}catch(e){throw new Error("[cleave.js] Please include phone-type-formatter.{country}.js lib")}},onKeyDown:function(e){var t=this.properties,i=e.which||e.keyCode,r=m.Util,n=this.element.value;this.hasBackspaceSupport=this.hasBackspaceSupport||8===i,!this.hasBackspaceSupport&&r.isAndroidBackspaceKeydown(this.lastInputValue,n)&&(i=8),this.lastInputValue=n;var a=r.getPostDelimiter(n,t.delimiter,t.delimiters);t.postDelimiterBackspace=!(8!==i||!a)&&a},onChange:function(){this.onInput(this.element.value)},onFocus:function(){var e=this.properties;e.prefix&&e.noImmediatePrefix&&!this.element.value&&this.onInput(e.prefix),m.Util.fixPrefixCursor(this.element,e.prefix,e.delimiter,e.delimiters)},onCut:function(e){m.Util.checkFullSelection(this.element.value)&&(this.copyClipboardData(e),this.onInput(""))},onCopy:function(e){m.Util.checkFullSelection(this.element.value)&&this.copyClipboardData(e)},copyClipboardData:function(e){var t=this.properties,i=m.Util,r=this.element.value,n="";n=t.copyDelimiter?r:i.stripDelimiters(r,t.delimiter,t.delimiters);try{e.clipboardData?e.clipboardData.setData("Text",n):window.clipboardData.setData("Text",n),e.preventDefault()}catch(e){}},onInput:function(e){var t=this.properties,i=m.Util,r=i.getPostDelimiter(e,t.delimiter,t.delimiters);return t.numeral||!t.postDelimiterBackspace||r||(e=i.headStr(e,e.length-t.postDelimiterBackspace.length)),t.phone?(!t.prefix||t.noImmediatePrefix&&!e.length?t.result=t.phoneFormatter.format(e):t.result=t.prefix+t.phoneFormatter.format(e).slice(t.prefix.length),void this.updateValueState()):t.numeral?(t.prefix&&t.noImmediatePrefix&&0===e.length?t.result="":t.result=t.numeralFormatter.format(e),void this.updateValueState()):(t.date&&(e=t.dateFormatter.getValidatedDate(e)),t.time&&(e=t.timeFormatter.getValidatedTime(e)),e=i.stripDelimiters(e,t.delimiter,t.delimiters),e=i.getPrefixStrippedValue(e,t.prefix,t.prefixLength,t.result,t.delimiter,t.delimiters,t.noImmediatePrefix,t.tailPrefix,t.signBeforePrefix),e=t.numericOnly?i.strip(e,/[^\d]/g):e,e=t.uppercase?e.toUpperCase():e,e=t.lowercase?e.toLowerCase():e,!t.prefix||t.noImmediatePrefix&&!e.length||(t.tailPrefix?e+=t.prefix:e!==t.prefix&&(e=t.prefix+e),0!==t.blocksLength)?(t.creditCard&&this.updateCreditCardPropsByValue(e),e=i.headStr(e,t.maxLength),t.result=i.getFormattedValue(e,t.blocks,t.blocksLength,t.delimiter,t.delimiters,t.delimiterLazyShow),void this.updateValueState()):(t.result=e,void this.updateValueState()))},updateCreditCardPropsByValue:function(e){var t,i=this.properties,r=m.Util;r.headStr(i.result,4)!==r.headStr(e,4)&&(t=m.CreditCardDetector.getInfo(e,i.creditCardStrictMode),i.blocks=t.blocks,i.blocksLength=i.blocks.length,i.maxLength=r.getMaxLength(i.blocks),i.creditCardType!==t.type&&(i.creditCardType=t.type,i.onCreditCardTypeChanged.call(this,i.creditCardType)))},updateValueState:function(){var e=this,t=m.Util,i=e.properties;if(e.element){var r=e.element.selectionEnd,n=e.element.value,a=i.result;r=t.getNextCursorPosition(r,n,a,i.delimiter,i.delimiters),e.isAndroid?window.setTimeout(function(){e.element.value=a,t.setSelection(e.element,r,i.document,!1),e.callOnValueChanged()},1):(e.element.value=a,i.swapHiddenInput&&(e.elementSwapHidden.value=e.getRawValue()),t.setSelection(e.element,r,i.document,!1),e.callOnValueChanged())}},callOnValueChanged:function(){var e=this.properties;e.onValueChanged.call(this,{target:{name:this.element.name,value:e.result,rawValue:this.getRawValue()}})},setPhoneRegionCode:function(e){this.properties.phoneRegionCode=e,this.initPhoneFormatter(),this.onChange()},setRawValue:function(e){var t=this.properties;e=null!=e?e.toString():"",t.numeral&&(e=e.replace(".",t.numeralDecimalMark)),t.postDelimiterBackspace=!1,this.element.value=e,this.onInput(e)},getRawValue:function(){var e=this.properties,t=m.Util,i=this.element.value;return e.rawValueTrimPrefix&&(i=t.getPrefixStrippedValue(i,e.prefix,e.prefixLength,e.result,e.delimiter,e.delimiters,e.noImmediatePrefix,e.tailPrefix,e.signBeforePrefix)),i=e.numeral?e.numeralFormatter.getRawValue(i):t.stripDelimiters(i,e.delimiter,e.delimiters)},getISOFormatDate:function(){var e=this.properties;return e.date?e.dateFormatter.getISOFormatDate():""},getISOFormatTime:function(){var e=this.properties;return e.time?e.timeFormatter.getISOFormatTime():""},getFormattedValue:function(){return this.element.value},destroy:function(){this.element.removeEventListener("input",this.onChangeListener),this.element.removeEventListener("keydown",this.onKeyDownListener),this.element.removeEventListener("focus",this.onFocusListener),this.element.removeEventListener("cut",this.onCutListener),this.element.removeEventListener("copy",this.onCopyListener)},toString:function(){return"[Cleave Object]"}},m.NumeralFormatter=i,m.DateFormatter=n,m.TimeFormatter=s,m.PhoneFormatter=l,m.CreditCardDetector=u,m.Util=d,m.DefaultProperties=h,("object"==typeof e&&e?e:window).Cleave=m;export default m; \ No newline at end of file diff --git a/dist/cleave-react-node.js b/dist/cleave-react-node.js index ed460658..c4e5ba19 100644 --- a/dist/cleave-react-node.js +++ b/dist/cleave-react-node.js @@ -425,7 +425,7 @@ return /******/ (function(modules) { // webpackBootstrap if (pps.prefix && (!pps.noImmediatePrefix || value.length)) { if (pps.tailPrefix) { value = value + pps.prefix; - } else { + } else if (value !== pps.prefix) { value = pps.prefix + value; } diff --git a/dist/cleave-react-node.min.js b/dist/cleave-react-node.min.js index 12bd6670..a2cdec56 100644 --- a/dist/cleave-react-node.min.js +++ b/dist/cleave-react-node.min.js @@ -5,4 +5,4 @@ * * Copyright (C) 2012-2020 Max Huang https://github.com/nosir/ */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.Cleave=t(require("react")):e.Cleave=t(e.React)}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return e[r].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}var i=Object.assign||function(e){for(var t=1;t0?d.headStr(e,r.maxLength):e,r.result=d.getFormattedValue(e,r.blocks,r.blocksLength,r.delimiter,r.delimiters,r.delimiterLazyShow),void n.updateValueState()):(r.result=e,void n.updateValueState()))},updateCreditCardPropsByValue:function(e){var t,n=this,r=n.properties;d.headStr(r.result,4)!==d.headStr(e,4)&&(t=p.getInfo(e,r.creditCardStrictMode),r.blocks=t.blocks,r.blocksLength=r.blocks.length,r.maxLength=d.getMaxLength(r.blocks),r.creditCardType!==t.type&&(r.creditCardType=t.type,r.onCreditCardTypeChanged.call(n,r.creditCardType)))},updateValueState:function(){var e=this,t=e.properties;if(!e.element)return void e.setState({value:t.result});var n=e.element.selectionEnd,r=e.element.value,i=t.result;return e.lastInputValue=i,n=d.getNextCursorPosition(n,r,i,t.delimiter,t.delimiters),e.isAndroid?void window.setTimeout(function(){e.setState({value:i,cursorPosition:n})},1):void e.setState({value:i,cursorPosition:n})},render:function(){var e=this,t=e.props,n=(t.value,t.options,t.onKeyDown,t.onFocus,t.onBlur,t.onChange,t.onInit,t.htmlRef),a=r(t,["value","options","onKeyDown","onFocus","onBlur","onChange","onInit","htmlRef"]);return o.createElement("input",i({type:"text",ref:function(t){e.element=t,n&&n.apply(this,arguments)},value:e.state.value,onKeyDown:e.onKeyDown,onChange:e.onChange,onFocus:e.onFocus,onBlur:e.onBlur},a))}});e.exports=f},function(t,n){t.exports=e},function(e,t,n){"use strict";var r=n(1),i=n(3);if("undefined"==typeof r)throw Error("create-react-class could not find the React object. If you are using script tags, make sure that React is being loaded before create-react-class.");var o=(new r.Component).updater;e.exports=i(r.Component,r.isValidElement,o)},function(e,t,n){"use strict";function r(e){return e}function i(e,t,n){function i(e,t,n){for(var r in t)t.hasOwnProperty(r)&&"production"!==process.env.NODE_ENV&&c("function"==typeof t[r],"%s: %s type `%s` is invalid; it must be a function, usually from React.PropTypes.",e.displayName||"ReactClass",l[n],r)}function p(e,t){var n=D.hasOwnProperty(t)?D[t]:null;w.hasOwnProperty(t)&&s("OVERRIDE_BASE"===n,"ReactClassInterface: You are attempting to override `%s` from your class specification. Ensure that your method names do not overlap with React methods.",t),e&&s("DEFINE_MANY"===n||"DEFINE_MANY_MERGED"===n,"ReactClassInterface: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.",t)}function d(e,n){if(n){s("function"!=typeof n,"ReactClass: You're attempting to use a component class or function as a mixin. Instead, just use a regular object."),s(!t(n),"ReactClass: You're attempting to use a component as a mixin. Instead, just use a regular object.");var r=e.prototype,i=r.__reactAutoBindPairs;n.hasOwnProperty(u)&&I.mixins(e,n.mixins);for(var o in n)if(n.hasOwnProperty(o)&&o!==u){var a=n[o],l=r.hasOwnProperty(o);if(p(l,o),I.hasOwnProperty(o))I[o](e,a);else{var d=D.hasOwnProperty(o),m="function"==typeof a,f=m&&!d&&!l&&n.autobind!==!1;if(f)i.push(o,a),r[o]=a;else if(l){var v=D[o];s(d&&("DEFINE_MANY_MERGED"===v||"DEFINE_MANY"===v),"ReactClass: Unexpected spec policy %s for key %s when mixing in component specs.",v,o),"DEFINE_MANY_MERGED"===v?r[o]=h(r[o],a):"DEFINE_MANY"===v&&(r[o]=g(r[o],a))}else r[o]=a,"production"!==process.env.NODE_ENV&&"function"==typeof a&&n.displayName&&(r[o].displayName=n.displayName+"_"+o)}}}else if("production"!==process.env.NODE_ENV){var y=typeof n,x="object"===y&&null!==n;"production"!==process.env.NODE_ENV&&c(x,"%s: You're attempting to include a mixin that is either null or not an object. Check the mixins included by the component, as well as any mixins they include themselves. Expected object but got %s.",e.displayName||"ReactClass",null===n?null:y)}}function m(e,t){if(t)for(var n in t){var r=t[n];if(t.hasOwnProperty(n)){var i=n in I;s(!i,'ReactClass: You are attempting to define a reserved property, `%s`, that shouldn\'t be on the "statics" key. Define it as an instance property instead; it will still be accessible on the constructor.',n);var o=n in e;if(o){var a=b.hasOwnProperty(n)?b[n]:null;return s("DEFINE_MANY_MERGED"===a,"ReactClass: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.",n),void(e[n]=h(e[n],r))}e[n]=r}}}function f(e,t){s(e&&t&&"object"==typeof e&&"object"==typeof t,"mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.");for(var n in t)t.hasOwnProperty(n)&&(s(void 0===e[n],"mergeIntoWithNoDuplicateKeys(): Tried to merge two objects with the same key: `%s`. This conflict may be due to a mixin; in particular, this may be caused by two getInitialState() or getDefaultProps() methods returning objects with clashing keys.",n),e[n]=t[n]);return e}function h(e,t){return function(){var n=e.apply(this,arguments),r=t.apply(this,arguments);if(null==n)return r;if(null==r)return n;var i={};return f(i,n),f(i,r),i}}function g(e,t){return function(){e.apply(this,arguments),t.apply(this,arguments)}}function v(e,t){var n=t.bind(e);if("production"!==process.env.NODE_ENV){n.__reactBoundContext=e,n.__reactBoundMethod=t,n.__reactBoundArguments=null;var r=e.constructor.displayName,i=n.bind;n.bind=function(o){for(var a=arguments.length,s=Array(a>1?a-1:0),l=1;l1?t-1:0),r=1;r2?n-2:0),i=2;i0?t:0,p.numeralDecimalScale=n>=0?n:2,p.numeralThousandsGroupStyle=i||r.groupStyle.thousand,p.numeralPositiveOnly=!!o,p.stripLeadingZeroes=a!==!1,p.prefix=s||""===s?s:"",p.signBeforePrefix=!!c,p.tailPrefix=!!l,p.delimiter=u||""===u?u:",",p.delimiterRE=u?new RegExp("\\"+u,"g"):""};n.groupStyle={thousand:"thousand",lakh:"lakh",wan:"wan",none:"none"},n.prototype={getRawValue:function(e){return e.replace(this.delimiterRE,"").replace(this.numeralDecimalMark,".")},format:function(e){var t,r,i,o,a=this,s="";switch(e=e.replace(/[A-Za-z]/g,"").replace(a.numeralDecimalMark,"M").replace(/[^\dM-]/g,"").replace(/^\-/,"N").replace(/\-/g,"").replace("N",a.numeralPositiveOnly?"":"-").replace("M",a.numeralDecimalMark),a.stripLeadingZeroes&&(e=e.replace(/^(-)?0+(?=\d)/,"$1")),r="-"===e.slice(0,1)?"-":"",i="undefined"!=typeof a.prefix?a.signBeforePrefix?r+a.prefix:a.prefix+r:r,o=e,e.indexOf(a.numeralDecimalMark)>=0&&(t=e.split(a.numeralDecimalMark),o=t[0],s=a.numeralDecimalMark+t[1].slice(0,a.numeralDecimalScale)),"-"===r&&(o=o.slice(1)),a.numeralIntegerScale>0&&(o=o.slice(0,a.numeralIntegerScale)),a.numeralThousandsGroupStyle){case n.groupStyle.lakh:o=o.replace(/(\d)(?=(\d\d)+\d$)/g,"$1"+a.delimiter);break;case n.groupStyle.wan:o=o.replace(/(\d)(?=(\d{4})+$)/g,"$1"+a.delimiter);break;case n.groupStyle.thousand:o=o.replace(/(\d)(?=(\d{3})+$)/g,"$1"+a.delimiter)}return a.tailPrefix?r+o.toString()+(a.numeralDecimalScale>0?s.toString():"")+a.prefix:i+o.toString()+(a.numeralDecimalScale>0?s.toString():"")}},e.exports=n},function(e,t){"use strict";var n=function(e,t,n){var r=this;r.date=[],r.blocks=[],r.datePattern=e,r.dateMin=t.split("-").reverse().map(function(e){return parseInt(e,10)}),2===r.dateMin.length&&r.dateMin.unshift(0),r.dateMax=n.split("-").reverse().map(function(e){return parseInt(e,10)}),2===r.dateMax.length&&r.dateMax.unshift(0),r.initBlocks()};n.prototype={initBlocks:function(){var e=this;e.datePattern.forEach(function(t){"Y"===t?e.blocks.push(4):e.blocks.push(2)})},getISOFormatDate:function(){var e=this,t=e.date;return t[2]?t[2]+"-"+e.addLeadingZero(t[1])+"-"+e.addLeadingZero(t[0]):""},getBlocks:function(){return this.blocks},getValidatedDate:function(e){var t=this,n="";return e=e.replace(/[^\d]/g,""),t.blocks.forEach(function(r,i){if(e.length>0){var o=e.slice(0,r),a=o.slice(0,1),s=e.slice(r);switch(t.datePattern[i]){case"d":"00"===o?o="01":parseInt(a,10)>3?o="0"+a:parseInt(o,10)>31&&(o="31");break;case"m":"00"===o?o="01":parseInt(a,10)>1?o="0"+a:parseInt(o,10)>12&&(o="12")}n+=o,e=s}}),this.getFixedDateString(n)},getFixedDateString:function(e){var t,n,r,i=this,o=i.datePattern,a=[],s=0,c=0,l=0,u=0,p=0,d=0,m=!1;4===e.length&&"y"!==o[0].toLowerCase()&&"y"!==o[1].toLowerCase()&&(u="d"===o[0]?0:2,p=2-u,t=parseInt(e.slice(u,u+2),10),n=parseInt(e.slice(p,p+2),10),a=this.getFixedDate(t,n,0)),8===e.length&&(o.forEach(function(e,t){switch(e){case"d":s=t;break;case"m":c=t;break;default:l=t}}),d=2*l,u=s<=l?2*s:2*s+2,p=c<=l?2*c:2*c+2,t=parseInt(e.slice(u,u+2),10),n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+4),10),m=4===e.slice(d,d+4).length,a=this.getFixedDate(t,n,r)),4!==e.length||"y"!==o[0]&&"y"!==o[1]||(p="m"===o[0]?0:2,d=2-p,n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+2),10),m=2===e.slice(d,d+2).length,a=[0,n,r]),6!==e.length||"Y"!==o[0]&&"Y"!==o[1]||(p="m"===o[0]?0:4,d=2-.5*p,n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+4),10),m=4===e.slice(d,d+4).length,a=[0,n,r]),a=i.getRangeFixedDate(a),i.date=a;var f=0===a.length?e:o.reduce(function(e,t){switch(t){case"d":return e+(0===a[0]?"":i.addLeadingZero(a[0]));case"m":return e+(0===a[1]?"":i.addLeadingZero(a[1]));case"y":return e+(m?i.addLeadingZeroForYear(a[2],!1):"");case"Y":return e+(m?i.addLeadingZeroForYear(a[2],!0):"")}},"");return f},getRangeFixedDate:function(e){var t=this,n=t.datePattern,r=t.dateMin||[],i=t.dateMax||[];return!e.length||r.length<3&&i.length<3?e:n.find(function(e){return"y"===e.toLowerCase()})&&0===e[2]?e:i.length&&(i[2]e[2]||r[2]===e[2]&&(r[1]>e[1]||r[1]===e[1]&&r[0]>e[0]))?r:e},getFixedDate:function(e,t,n){return e=Math.min(e,31),t=Math.min(t,12),n=parseInt(n||0,10),(t<7&&t%2===0||t>8&&t%2===1)&&(e=Math.min(e,2===t?this.isLeapYear(n)?29:28:30)),[e,t,n]},isLeapYear:function(e){return e%4===0&&e%100!==0||e%400===0},addLeadingZero:function(e){return(e<10?"0":"")+e},addLeadingZeroForYear:function(e,t){return t?(e<10?"000":e<100?"00":e<1e3?"0":"")+e:(e<10?"0":"")+e}},e.exports=n},function(e,t){"use strict";var n=function(e,t){var n=this;n.time=[],n.blocks=[],n.timePattern=e,n.timeFormat=t,n.initBlocks()};n.prototype={initBlocks:function(){var e=this;e.timePattern.forEach(function(){e.blocks.push(2)})},getISOFormatTime:function(){var e=this,t=e.time;return t[2]?e.addLeadingZero(t[0])+":"+e.addLeadingZero(t[1])+":"+e.addLeadingZero(t[2]):""},getBlocks:function(){return this.blocks},getTimeFormatOptions:function(){var e=this;return"12"===String(e.timeFormat)?{maxHourFirstDigit:1,maxHours:12,maxMinutesFirstDigit:5,maxMinutes:60}:{maxHourFirstDigit:2,maxHours:23,maxMinutesFirstDigit:5,maxMinutes:60}},getValidatedTime:function(e){var t=this,n="";e=e.replace(/[^\d]/g,"");var r=t.getTimeFormatOptions();return t.blocks.forEach(function(i,o){if(e.length>0){var a=e.slice(0,i),s=a.slice(0,1),c=e.slice(i);switch(t.timePattern[o]){case"h":parseInt(s,10)>r.maxHourFirstDigit?a="0"+s:parseInt(a,10)>r.maxHours&&(a=r.maxHours+"");break;case"m":case"s":parseInt(s,10)>r.maxMinutesFirstDigit?a="0"+s:parseInt(a,10)>r.maxMinutes&&(a=r.maxMinutes+"")}n+=a,e=c}}),this.getFixedTimeString(n)},getFixedTimeString:function(e){var t,n,r,i=this,o=i.timePattern,a=[],s=0,c=0,l=0,u=0,p=0,d=0;return 6===e.length&&(o.forEach(function(e,t){switch(e){case"s":s=2*t;break;case"m":c=2*t;break;case"h":l=2*t}}),d=l,p=c,u=s,t=parseInt(e.slice(u,u+2),10),n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+2),10),a=this.getFixedTime(r,n,t)),4===e.length&&i.timePattern.indexOf("s")<0&&(o.forEach(function(e,t){switch(e){case"m":c=2*t;break;case"h":l=2*t}}),d=l,p=c,t=0,n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+2),10),a=this.getFixedTime(r,n,t)),i.time=a,0===a.length?e:o.reduce(function(e,t){switch(t){case"s":return e+i.addLeadingZero(a[2]);case"m":return e+i.addLeadingZero(a[1]);case"h":return e+i.addLeadingZero(a[0])}},"")},getFixedTime:function(e,t,n){return n=Math.min(parseInt(n||0,10),60),t=Math.min(t,60),e=Math.min(e,60),[e,t,n]},addLeadingZero:function(e){return(e<10?"0":"")+e}},e.exports=n},function(e,t){"use strict";var n=function(e,t){var n=this;n.delimiter=t||""===t?t:" ",n.delimiterRE=t?new RegExp("\\"+t,"g"):"",n.formatter=e};n.prototype={setFormatter:function(e){this.formatter=e},format:function(e){var t=this;t.formatter.clear(),e=e.replace(/[^\d+]/g,""),e=e.replace(/^\+/,"B").replace(/\+/g,"").replace("B","+"),e=e.replace(t.delimiterRE,"");for(var n,r="",i=!1,o=0,a=e.length;o0;return 0===n?e:(t.forEach(function(t,l){if(e.length>0){var u=e.slice(0,t),p=e.slice(t);a=c?i[o?l-1:l]||a:r,o?(l>0&&(s+=a),s+=u):(s+=u,u.length===t&&l0?t.numeralIntegerScale:0,e.numeralDecimalScale=t.numeralDecimalScale>=0?t.numeralDecimalScale:2,e.numeralDecimalMark=t.numeralDecimalMark||".",e.numeralThousandsGroupStyle=t.numeralThousandsGroupStyle||"thousand",e.numeralPositiveOnly=!!t.numeralPositiveOnly,e.stripLeadingZeroes=t.stripLeadingZeroes!==!1,e.signBeforePrefix=!!t.signBeforePrefix,e.tailPrefix=!!t.tailPrefix,e.swapHiddenInput=!!t.swapHiddenInput,e.numericOnly=e.creditCard||e.date||!!t.numericOnly,e.uppercase=!!t.uppercase,e.lowercase=!!t.lowercase,e.prefix=e.creditCard||e.date?"":t.prefix||"",e.noImmediatePrefix=!!t.noImmediatePrefix,e.prefixLength=e.prefix.length,e.rawValueTrimPrefix=!!t.rawValueTrimPrefix,e.copyDelimiter=!!t.copyDelimiter,e.initValue=void 0!==t.initValue&&null!==t.initValue?t.initValue.toString():"",e.delimiter=t.delimiter||""===t.delimiter?t.delimiter:t.date?"/":t.time?":":t.numeral?",":(t.phone," "),e.delimiterLength=e.delimiter.length,e.delimiterLazyShow=!!t.delimiterLazyShow,e.delimiters=t.delimiters||[],e.blocks=t.blocks||[],e.blocksLength=e.blocks.length,e.root="object"===("undefined"==typeof global?"undefined":n(global))&&global?global:window,e.document=t.document||e.root.document,e.maxLength=0,e.backspace=!1,e.result="",e.onValueChanged=t.onValueChanged||function(){},e}};e.exports=r}])}); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.Cleave=t(require("react")):e.Cleave=t(e.React)}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return e[r].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}var i=Object.assign||function(e){for(var t=1;t0?d.headStr(e,r.maxLength):e,r.result=d.getFormattedValue(e,r.blocks,r.blocksLength,r.delimiter,r.delimiters,r.delimiterLazyShow),void n.updateValueState()):(r.result=e,void n.updateValueState()))},updateCreditCardPropsByValue:function(e){var t,n=this,r=n.properties;d.headStr(r.result,4)!==d.headStr(e,4)&&(t=p.getInfo(e,r.creditCardStrictMode),r.blocks=t.blocks,r.blocksLength=r.blocks.length,r.maxLength=d.getMaxLength(r.blocks),r.creditCardType!==t.type&&(r.creditCardType=t.type,r.onCreditCardTypeChanged.call(n,r.creditCardType)))},updateValueState:function(){var e=this,t=e.properties;if(!e.element)return void e.setState({value:t.result});var n=e.element.selectionEnd,r=e.element.value,i=t.result;return e.lastInputValue=i,n=d.getNextCursorPosition(n,r,i,t.delimiter,t.delimiters),e.isAndroid?void window.setTimeout(function(){e.setState({value:i,cursorPosition:n})},1):void e.setState({value:i,cursorPosition:n})},render:function(){var e=this,t=e.props,n=(t.value,t.options,t.onKeyDown,t.onFocus,t.onBlur,t.onChange,t.onInit,t.htmlRef),a=r(t,["value","options","onKeyDown","onFocus","onBlur","onChange","onInit","htmlRef"]);return o.createElement("input",i({type:"text",ref:function(t){e.element=t,n&&n.apply(this,arguments)},value:e.state.value,onKeyDown:e.onKeyDown,onChange:e.onChange,onFocus:e.onFocus,onBlur:e.onBlur},a))}});e.exports=f},function(t,n){t.exports=e},function(e,t,n){"use strict";var r=n(1),i=n(3);if("undefined"==typeof r)throw Error("create-react-class could not find the React object. If you are using script tags, make sure that React is being loaded before create-react-class.");var o=(new r.Component).updater;e.exports=i(r.Component,r.isValidElement,o)},function(e,t,n){"use strict";function r(e){return e}function i(e,t,n){function i(e,t,n){for(var r in t)t.hasOwnProperty(r)&&"production"!==process.env.NODE_ENV&&c("function"==typeof t[r],"%s: %s type `%s` is invalid; it must be a function, usually from React.PropTypes.",e.displayName||"ReactClass",l[n],r)}function p(e,t){var n=D.hasOwnProperty(t)?D[t]:null;w.hasOwnProperty(t)&&s("OVERRIDE_BASE"===n,"ReactClassInterface: You are attempting to override `%s` from your class specification. Ensure that your method names do not overlap with React methods.",t),e&&s("DEFINE_MANY"===n||"DEFINE_MANY_MERGED"===n,"ReactClassInterface: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.",t)}function d(e,n){if(n){s("function"!=typeof n,"ReactClass: You're attempting to use a component class or function as a mixin. Instead, just use a regular object."),s(!t(n),"ReactClass: You're attempting to use a component as a mixin. Instead, just use a regular object.");var r=e.prototype,i=r.__reactAutoBindPairs;n.hasOwnProperty(u)&&I.mixins(e,n.mixins);for(var o in n)if(n.hasOwnProperty(o)&&o!==u){var a=n[o],l=r.hasOwnProperty(o);if(p(l,o),I.hasOwnProperty(o))I[o](e,a);else{var d=D.hasOwnProperty(o),m="function"==typeof a,f=m&&!d&&!l&&n.autobind!==!1;if(f)i.push(o,a),r[o]=a;else if(l){var v=D[o];s(d&&("DEFINE_MANY_MERGED"===v||"DEFINE_MANY"===v),"ReactClass: Unexpected spec policy %s for key %s when mixing in component specs.",v,o),"DEFINE_MANY_MERGED"===v?r[o]=h(r[o],a):"DEFINE_MANY"===v&&(r[o]=g(r[o],a))}else r[o]=a,"production"!==process.env.NODE_ENV&&"function"==typeof a&&n.displayName&&(r[o].displayName=n.displayName+"_"+o)}}}else if("production"!==process.env.NODE_ENV){var y=typeof n,x="object"===y&&null!==n;"production"!==process.env.NODE_ENV&&c(x,"%s: You're attempting to include a mixin that is either null or not an object. Check the mixins included by the component, as well as any mixins they include themselves. Expected object but got %s.",e.displayName||"ReactClass",null===n?null:y)}}function m(e,t){if(t)for(var n in t){var r=t[n];if(t.hasOwnProperty(n)){var i=n in I;s(!i,'ReactClass: You are attempting to define a reserved property, `%s`, that shouldn\'t be on the "statics" key. Define it as an instance property instead; it will still be accessible on the constructor.',n);var o=n in e;if(o){var a=b.hasOwnProperty(n)?b[n]:null;return s("DEFINE_MANY_MERGED"===a,"ReactClass: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.",n),void(e[n]=h(e[n],r))}e[n]=r}}}function f(e,t){s(e&&t&&"object"==typeof e&&"object"==typeof t,"mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.");for(var n in t)t.hasOwnProperty(n)&&(s(void 0===e[n],"mergeIntoWithNoDuplicateKeys(): Tried to merge two objects with the same key: `%s`. This conflict may be due to a mixin; in particular, this may be caused by two getInitialState() or getDefaultProps() methods returning objects with clashing keys.",n),e[n]=t[n]);return e}function h(e,t){return function(){var n=e.apply(this,arguments),r=t.apply(this,arguments);if(null==n)return r;if(null==r)return n;var i={};return f(i,n),f(i,r),i}}function g(e,t){return function(){e.apply(this,arguments),t.apply(this,arguments)}}function v(e,t){var n=t.bind(e);if("production"!==process.env.NODE_ENV){n.__reactBoundContext=e,n.__reactBoundMethod=t,n.__reactBoundArguments=null;var r=e.constructor.displayName,i=n.bind;n.bind=function(o){for(var a=arguments.length,s=Array(a>1?a-1:0),l=1;l1?t-1:0),r=1;r2?n-2:0),i=2;i0?t:0,p.numeralDecimalScale=n>=0?n:2,p.numeralThousandsGroupStyle=i||r.groupStyle.thousand,p.numeralPositiveOnly=!!o,p.stripLeadingZeroes=a!==!1,p.prefix=s||""===s?s:"",p.signBeforePrefix=!!c,p.tailPrefix=!!l,p.delimiter=u||""===u?u:",",p.delimiterRE=u?new RegExp("\\"+u,"g"):""};n.groupStyle={thousand:"thousand",lakh:"lakh",wan:"wan",none:"none"},n.prototype={getRawValue:function(e){return e.replace(this.delimiterRE,"").replace(this.numeralDecimalMark,".")},format:function(e){var t,r,i,o,a=this,s="";switch(e=e.replace(/[A-Za-z]/g,"").replace(a.numeralDecimalMark,"M").replace(/[^\dM-]/g,"").replace(/^\-/,"N").replace(/\-/g,"").replace("N",a.numeralPositiveOnly?"":"-").replace("M",a.numeralDecimalMark),a.stripLeadingZeroes&&(e=e.replace(/^(-)?0+(?=\d)/,"$1")),r="-"===e.slice(0,1)?"-":"",i="undefined"!=typeof a.prefix?a.signBeforePrefix?r+a.prefix:a.prefix+r:r,o=e,e.indexOf(a.numeralDecimalMark)>=0&&(t=e.split(a.numeralDecimalMark),o=t[0],s=a.numeralDecimalMark+t[1].slice(0,a.numeralDecimalScale)),"-"===r&&(o=o.slice(1)),a.numeralIntegerScale>0&&(o=o.slice(0,a.numeralIntegerScale)),a.numeralThousandsGroupStyle){case n.groupStyle.lakh:o=o.replace(/(\d)(?=(\d\d)+\d$)/g,"$1"+a.delimiter);break;case n.groupStyle.wan:o=o.replace(/(\d)(?=(\d{4})+$)/g,"$1"+a.delimiter);break;case n.groupStyle.thousand:o=o.replace(/(\d)(?=(\d{3})+$)/g,"$1"+a.delimiter)}return a.tailPrefix?r+o.toString()+(a.numeralDecimalScale>0?s.toString():"")+a.prefix:i+o.toString()+(a.numeralDecimalScale>0?s.toString():"")}},e.exports=n},function(e,t){"use strict";var n=function(e,t,n){var r=this;r.date=[],r.blocks=[],r.datePattern=e,r.dateMin=t.split("-").reverse().map(function(e){return parseInt(e,10)}),2===r.dateMin.length&&r.dateMin.unshift(0),r.dateMax=n.split("-").reverse().map(function(e){return parseInt(e,10)}),2===r.dateMax.length&&r.dateMax.unshift(0),r.initBlocks()};n.prototype={initBlocks:function(){var e=this;e.datePattern.forEach(function(t){"Y"===t?e.blocks.push(4):e.blocks.push(2)})},getISOFormatDate:function(){var e=this,t=e.date;return t[2]?t[2]+"-"+e.addLeadingZero(t[1])+"-"+e.addLeadingZero(t[0]):""},getBlocks:function(){return this.blocks},getValidatedDate:function(e){var t=this,n="";return e=e.replace(/[^\d]/g,""),t.blocks.forEach(function(r,i){if(e.length>0){var o=e.slice(0,r),a=o.slice(0,1),s=e.slice(r);switch(t.datePattern[i]){case"d":"00"===o?o="01":parseInt(a,10)>3?o="0"+a:parseInt(o,10)>31&&(o="31");break;case"m":"00"===o?o="01":parseInt(a,10)>1?o="0"+a:parseInt(o,10)>12&&(o="12")}n+=o,e=s}}),this.getFixedDateString(n)},getFixedDateString:function(e){var t,n,r,i=this,o=i.datePattern,a=[],s=0,c=0,l=0,u=0,p=0,d=0,m=!1;4===e.length&&"y"!==o[0].toLowerCase()&&"y"!==o[1].toLowerCase()&&(u="d"===o[0]?0:2,p=2-u,t=parseInt(e.slice(u,u+2),10),n=parseInt(e.slice(p,p+2),10),a=this.getFixedDate(t,n,0)),8===e.length&&(o.forEach(function(e,t){switch(e){case"d":s=t;break;case"m":c=t;break;default:l=t}}),d=2*l,u=s<=l?2*s:2*s+2,p=c<=l?2*c:2*c+2,t=parseInt(e.slice(u,u+2),10),n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+4),10),m=4===e.slice(d,d+4).length,a=this.getFixedDate(t,n,r)),4!==e.length||"y"!==o[0]&&"y"!==o[1]||(p="m"===o[0]?0:2,d=2-p,n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+2),10),m=2===e.slice(d,d+2).length,a=[0,n,r]),6!==e.length||"Y"!==o[0]&&"Y"!==o[1]||(p="m"===o[0]?0:4,d=2-.5*p,n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+4),10),m=4===e.slice(d,d+4).length,a=[0,n,r]),a=i.getRangeFixedDate(a),i.date=a;var f=0===a.length?e:o.reduce(function(e,t){switch(t){case"d":return e+(0===a[0]?"":i.addLeadingZero(a[0]));case"m":return e+(0===a[1]?"":i.addLeadingZero(a[1]));case"y":return e+(m?i.addLeadingZeroForYear(a[2],!1):"");case"Y":return e+(m?i.addLeadingZeroForYear(a[2],!0):"")}},"");return f},getRangeFixedDate:function(e){var t=this,n=t.datePattern,r=t.dateMin||[],i=t.dateMax||[];return!e.length||r.length<3&&i.length<3?e:n.find(function(e){return"y"===e.toLowerCase()})&&0===e[2]?e:i.length&&(i[2]e[2]||r[2]===e[2]&&(r[1]>e[1]||r[1]===e[1]&&r[0]>e[0]))?r:e},getFixedDate:function(e,t,n){return e=Math.min(e,31),t=Math.min(t,12),n=parseInt(n||0,10),(t<7&&t%2===0||t>8&&t%2===1)&&(e=Math.min(e,2===t?this.isLeapYear(n)?29:28:30)),[e,t,n]},isLeapYear:function(e){return e%4===0&&e%100!==0||e%400===0},addLeadingZero:function(e){return(e<10?"0":"")+e},addLeadingZeroForYear:function(e,t){return t?(e<10?"000":e<100?"00":e<1e3?"0":"")+e:(e<10?"0":"")+e}},e.exports=n},function(e,t){"use strict";var n=function(e,t){var n=this;n.time=[],n.blocks=[],n.timePattern=e,n.timeFormat=t,n.initBlocks()};n.prototype={initBlocks:function(){var e=this;e.timePattern.forEach(function(){e.blocks.push(2)})},getISOFormatTime:function(){var e=this,t=e.time;return t[2]?e.addLeadingZero(t[0])+":"+e.addLeadingZero(t[1])+":"+e.addLeadingZero(t[2]):""},getBlocks:function(){return this.blocks},getTimeFormatOptions:function(){var e=this;return"12"===String(e.timeFormat)?{maxHourFirstDigit:1,maxHours:12,maxMinutesFirstDigit:5,maxMinutes:60}:{maxHourFirstDigit:2,maxHours:23,maxMinutesFirstDigit:5,maxMinutes:60}},getValidatedTime:function(e){var t=this,n="";e=e.replace(/[^\d]/g,"");var r=t.getTimeFormatOptions();return t.blocks.forEach(function(i,o){if(e.length>0){var a=e.slice(0,i),s=a.slice(0,1),c=e.slice(i);switch(t.timePattern[o]){case"h":parseInt(s,10)>r.maxHourFirstDigit?a="0"+s:parseInt(a,10)>r.maxHours&&(a=r.maxHours+"");break;case"m":case"s":parseInt(s,10)>r.maxMinutesFirstDigit?a="0"+s:parseInt(a,10)>r.maxMinutes&&(a=r.maxMinutes+"")}n+=a,e=c}}),this.getFixedTimeString(n)},getFixedTimeString:function(e){var t,n,r,i=this,o=i.timePattern,a=[],s=0,c=0,l=0,u=0,p=0,d=0;return 6===e.length&&(o.forEach(function(e,t){switch(e){case"s":s=2*t;break;case"m":c=2*t;break;case"h":l=2*t}}),d=l,p=c,u=s,t=parseInt(e.slice(u,u+2),10),n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+2),10),a=this.getFixedTime(r,n,t)),4===e.length&&i.timePattern.indexOf("s")<0&&(o.forEach(function(e,t){switch(e){case"m":c=2*t;break;case"h":l=2*t}}),d=l,p=c,t=0,n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+2),10),a=this.getFixedTime(r,n,t)),i.time=a,0===a.length?e:o.reduce(function(e,t){switch(t){case"s":return e+i.addLeadingZero(a[2]);case"m":return e+i.addLeadingZero(a[1]);case"h":return e+i.addLeadingZero(a[0])}},"")},getFixedTime:function(e,t,n){return n=Math.min(parseInt(n||0,10),60),t=Math.min(t,60),e=Math.min(e,60),[e,t,n]},addLeadingZero:function(e){return(e<10?"0":"")+e}},e.exports=n},function(e,t){"use strict";var n=function(e,t){var n=this;n.delimiter=t||""===t?t:" ",n.delimiterRE=t?new RegExp("\\"+t,"g"):"",n.formatter=e};n.prototype={setFormatter:function(e){this.formatter=e},format:function(e){var t=this;t.formatter.clear(),e=e.replace(/[^\d+]/g,""),e=e.replace(/^\+/,"B").replace(/\+/g,"").replace("B","+"),e=e.replace(t.delimiterRE,"");for(var n,r="",i=!1,o=0,a=e.length;o0;return 0===n?e:(t.forEach(function(t,l){if(e.length>0){var u=e.slice(0,t),p=e.slice(t);a=c?i[o?l-1:l]||a:r,o?(l>0&&(s+=a),s+=u):(s+=u,u.length===t&&l0?t.numeralIntegerScale:0,e.numeralDecimalScale=t.numeralDecimalScale>=0?t.numeralDecimalScale:2,e.numeralDecimalMark=t.numeralDecimalMark||".",e.numeralThousandsGroupStyle=t.numeralThousandsGroupStyle||"thousand",e.numeralPositiveOnly=!!t.numeralPositiveOnly,e.stripLeadingZeroes=t.stripLeadingZeroes!==!1,e.signBeforePrefix=!!t.signBeforePrefix,e.tailPrefix=!!t.tailPrefix,e.swapHiddenInput=!!t.swapHiddenInput,e.numericOnly=e.creditCard||e.date||!!t.numericOnly,e.uppercase=!!t.uppercase,e.lowercase=!!t.lowercase,e.prefix=e.creditCard||e.date?"":t.prefix||"",e.noImmediatePrefix=!!t.noImmediatePrefix,e.prefixLength=e.prefix.length,e.rawValueTrimPrefix=!!t.rawValueTrimPrefix,e.copyDelimiter=!!t.copyDelimiter,e.initValue=void 0!==t.initValue&&null!==t.initValue?t.initValue.toString():"",e.delimiter=t.delimiter||""===t.delimiter?t.delimiter:t.date?"/":t.time?":":t.numeral?",":(t.phone," "),e.delimiterLength=e.delimiter.length,e.delimiterLazyShow=!!t.delimiterLazyShow,e.delimiters=t.delimiters||[],e.blocks=t.blocks||[],e.blocksLength=e.blocks.length,e.root="object"===("undefined"==typeof global?"undefined":n(global))&&global?global:window,e.document=t.document||e.root.document,e.maxLength=0,e.backspace=!1,e.result="",e.onValueChanged=t.onValueChanged||function(){},e}};e.exports=r}])}); \ No newline at end of file diff --git a/dist/cleave-react.js b/dist/cleave-react.js index 6659f061..3b1978e8 100644 --- a/dist/cleave-react.js +++ b/dist/cleave-react.js @@ -425,7 +425,7 @@ return /******/ (function(modules) { // webpackBootstrap if (pps.prefix && (!pps.noImmediatePrefix || value.length)) { if (pps.tailPrefix) { value = value + pps.prefix; - } else { + } else if (value !== pps.prefix) { value = pps.prefix + value; } diff --git a/dist/cleave-react.min.js b/dist/cleave-react.min.js index db105000..138a090d 100644 --- a/dist/cleave-react.min.js +++ b/dist/cleave-react.min.js @@ -5,5 +5,5 @@ * * Copyright (C) 2012-2020 Max Huang https://github.com/nosir/ */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.Cleave=t(require("react")):e.Cleave=t(e.React)}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return e[r].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}var i=Object.assign||function(e){for(var t=1;t0?d.headStr(e,r.maxLength):e,r.result=d.getFormattedValue(e,r.blocks,r.blocksLength,r.delimiter,r.delimiters,r.delimiterLazyShow),void n.updateValueState()):(r.result=e,void n.updateValueState()))},updateCreditCardPropsByValue:function(e){var t,n=this,r=n.properties;d.headStr(r.result,4)!==d.headStr(e,4)&&(t=p.getInfo(e,r.creditCardStrictMode),r.blocks=t.blocks,r.blocksLength=r.blocks.length,r.maxLength=d.getMaxLength(r.blocks),r.creditCardType!==t.type&&(r.creditCardType=t.type,r.onCreditCardTypeChanged.call(n,r.creditCardType)))},updateValueState:function(){var e=this,t=e.properties;if(!e.element)return void e.setState({value:t.result});var n=e.element.selectionEnd,r=e.element.value,i=t.result;return e.lastInputValue=i,n=d.getNextCursorPosition(n,r,i,t.delimiter,t.delimiters),e.isAndroid?void window.setTimeout(function(){e.setState({value:i,cursorPosition:n})},1):void e.setState({value:i,cursorPosition:n})},render:function(){var e=this,t=e.props,n=(t.value,t.options,t.onKeyDown,t.onFocus,t.onBlur,t.onChange,t.onInit,t.htmlRef),a=r(t,["value","options","onKeyDown","onFocus","onBlur","onChange","onInit","htmlRef"]);return o.createElement("input",i({type:"text",ref:function(t){e.element=t,n&&n.apply(this,arguments)},value:e.state.value,onKeyDown:e.onKeyDown,onChange:e.onChange,onFocus:e.onFocus,onBlur:e.onBlur},a))}});e.exports=f},function(t,n){t.exports=e},function(e,t,n){"use strict";var r=n(1),i=n(3);if("undefined"==typeof r)throw Error("create-react-class could not find the React object. If you are using script tags, make sure that React is being loaded before create-react-class.");var o=(new r.Component).updater;e.exports=i(r.Component,r.isValidElement,o)},function(e,t,n){(function(t){"use strict";function r(e){return e}function i(e,n,i){function p(e,n,r){for(var i in n)n.hasOwnProperty(i)&&"production"!==t.env.NODE_ENV&&c("function"==typeof n[i],"%s: %s type `%s` is invalid; it must be a function, usually from React.PropTypes.",e.displayName||"ReactClass",u[r],i)}function d(e,t){var n=b.hasOwnProperty(t)?b[t]:null;F.hasOwnProperty(t)&&s("OVERRIDE_BASE"===n,"ReactClassInterface: You are attempting to override `%s` from your class specification. Ensure that your method names do not overlap with React methods.",t),e&&s("DEFINE_MANY"===n||"DEFINE_MANY_MERGED"===n,"ReactClassInterface: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.",t)}function m(e,r){if(r){s("function"!=typeof r,"ReactClass: You're attempting to use a component class or function as a mixin. Instead, just use a regular object."),s(!n(r),"ReactClass: You're attempting to use a component as a mixin. Instead, just use a regular object.");var i=e.prototype,o=i.__reactAutoBindPairs;r.hasOwnProperty(l)&&I.mixins(e,r.mixins);for(var a in r)if(r.hasOwnProperty(a)&&a!==l){var u=r[a],p=i.hasOwnProperty(a);if(d(p,a),I.hasOwnProperty(a))I[a](e,u);else{var m=b.hasOwnProperty(a),f="function"==typeof u,h=f&&!m&&!p&&r.autobind!==!1;if(h)o.push(a,u),i[a]=u;else if(p){var y=b[a];s(m&&("DEFINE_MANY_MERGED"===y||"DEFINE_MANY"===y),"ReactClass: Unexpected spec policy %s for key %s when mixing in component specs.",y,a),"DEFINE_MANY_MERGED"===y?i[a]=g(i[a],u):"DEFINE_MANY"===y&&(i[a]=v(i[a],u))}else i[a]=u,"production"!==t.env.NODE_ENV&&"function"==typeof u&&r.displayName&&(i[a].displayName=r.displayName+"_"+a)}}}else if("production"!==t.env.NODE_ENV){var x=typeof r,E="object"===x&&null!==r;"production"!==t.env.NODE_ENV&&c(E,"%s: You're attempting to include a mixin that is either null or not an object. Check the mixins included by the component, as well as any mixins they include themselves. Expected object but got %s.",e.displayName||"ReactClass",null===r?null:x)}}function f(e,t){if(t)for(var n in t){var r=t[n];if(t.hasOwnProperty(n)){var i=n in I;s(!i,'ReactClass: You are attempting to define a reserved property, `%s`, that shouldn\'t be on the "statics" key. Define it as an instance property instead; it will still be accessible on the constructor.',n);var o=n in e;if(o){var a=w.hasOwnProperty(n)?w[n]:null;return s("DEFINE_MANY_MERGED"===a,"ReactClass: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.",n),void(e[n]=g(e[n],r))}e[n]=r}}}function h(e,t){s(e&&t&&"object"==typeof e&&"object"==typeof t,"mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.");for(var n in t)t.hasOwnProperty(n)&&(s(void 0===e[n],"mergeIntoWithNoDuplicateKeys(): Tried to merge two objects with the same key: `%s`. This conflict may be due to a mixin; in particular, this may be caused by two getInitialState() or getDefaultProps() methods returning objects with clashing keys.",n),e[n]=t[n]);return e}function g(e,t){return function(){var n=e.apply(this,arguments),r=t.apply(this,arguments);if(null==n)return r;if(null==r)return n;var i={};return h(i,n),h(i,r),i}}function v(e,t){return function(){e.apply(this,arguments),t.apply(this,arguments)}}function y(e,n){var r=n.bind(e);if("production"!==t.env.NODE_ENV){r.__reactBoundContext=e,r.__reactBoundMethod=n,r.__reactBoundArguments=null;var i=e.constructor.displayName,o=r.bind;r.bind=function(a){for(var s=arguments.length,u=Array(s>1?s-1:0),l=1;l1)for(var n=1;n1?t-1:0),r=1;r2?n-2:0),i=2;i0?t:0,p.numeralDecimalScale=n>=0?n:2,p.numeralThousandsGroupStyle=i||r.groupStyle.thousand,p.numeralPositiveOnly=!!o,p.stripLeadingZeroes=a!==!1,p.prefix=s||""===s?s:"",p.signBeforePrefix=!!c,p.tailPrefix=!!u,p.delimiter=l||""===l?l:",",p.delimiterRE=l?new RegExp("\\"+l,"g"):""};n.groupStyle={thousand:"thousand",lakh:"lakh",wan:"wan",none:"none"},n.prototype={getRawValue:function(e){return e.replace(this.delimiterRE,"").replace(this.numeralDecimalMark,".")},format:function(e){var t,r,i,o,a=this,s="";switch(e=e.replace(/[A-Za-z]/g,"").replace(a.numeralDecimalMark,"M").replace(/[^\dM-]/g,"").replace(/^\-/,"N").replace(/\-/g,"").replace("N",a.numeralPositiveOnly?"":"-").replace("M",a.numeralDecimalMark),a.stripLeadingZeroes&&(e=e.replace(/^(-)?0+(?=\d)/,"$1")),r="-"===e.slice(0,1)?"-":"",i="undefined"!=typeof a.prefix?a.signBeforePrefix?r+a.prefix:a.prefix+r:r,o=e,e.indexOf(a.numeralDecimalMark)>=0&&(t=e.split(a.numeralDecimalMark),o=t[0],s=a.numeralDecimalMark+t[1].slice(0,a.numeralDecimalScale)),"-"===r&&(o=o.slice(1)),a.numeralIntegerScale>0&&(o=o.slice(0,a.numeralIntegerScale)),a.numeralThousandsGroupStyle){case n.groupStyle.lakh:o=o.replace(/(\d)(?=(\d\d)+\d$)/g,"$1"+a.delimiter);break;case n.groupStyle.wan:o=o.replace(/(\d)(?=(\d{4})+$)/g,"$1"+a.delimiter);break;case n.groupStyle.thousand:o=o.replace(/(\d)(?=(\d{3})+$)/g,"$1"+a.delimiter)}return a.tailPrefix?r+o.toString()+(a.numeralDecimalScale>0?s.toString():"")+a.prefix:i+o.toString()+(a.numeralDecimalScale>0?s.toString():"")}},e.exports=n},function(e,t){"use strict";var n=function(e,t,n){var r=this;r.date=[],r.blocks=[],r.datePattern=e,r.dateMin=t.split("-").reverse().map(function(e){return parseInt(e,10)}),2===r.dateMin.length&&r.dateMin.unshift(0),r.dateMax=n.split("-").reverse().map(function(e){return parseInt(e,10)}),2===r.dateMax.length&&r.dateMax.unshift(0),r.initBlocks()};n.prototype={initBlocks:function(){var e=this;e.datePattern.forEach(function(t){"Y"===t?e.blocks.push(4):e.blocks.push(2)})},getISOFormatDate:function(){var e=this,t=e.date;return t[2]?t[2]+"-"+e.addLeadingZero(t[1])+"-"+e.addLeadingZero(t[0]):""},getBlocks:function(){return this.blocks},getValidatedDate:function(e){var t=this,n="";return e=e.replace(/[^\d]/g,""),t.blocks.forEach(function(r,i){if(e.length>0){var o=e.slice(0,r),a=o.slice(0,1),s=e.slice(r);switch(t.datePattern[i]){case"d":"00"===o?o="01":parseInt(a,10)>3?o="0"+a:parseInt(o,10)>31&&(o="31");break;case"m":"00"===o?o="01":parseInt(a,10)>1?o="0"+a:parseInt(o,10)>12&&(o="12")}n+=o,e=s}}),this.getFixedDateString(n)},getFixedDateString:function(e){var t,n,r,i=this,o=i.datePattern,a=[],s=0,c=0,u=0,l=0,p=0,d=0,m=!1;4===e.length&&"y"!==o[0].toLowerCase()&&"y"!==o[1].toLowerCase()&&(l="d"===o[0]?0:2,p=2-l,t=parseInt(e.slice(l,l+2),10),n=parseInt(e.slice(p,p+2),10),a=this.getFixedDate(t,n,0)),8===e.length&&(o.forEach(function(e,t){switch(e){case"d":s=t;break;case"m":c=t;break;default:u=t}}),d=2*u,l=s<=u?2*s:2*s+2,p=c<=u?2*c:2*c+2,t=parseInt(e.slice(l,l+2),10),n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+4),10),m=4===e.slice(d,d+4).length,a=this.getFixedDate(t,n,r)),4!==e.length||"y"!==o[0]&&"y"!==o[1]||(p="m"===o[0]?0:2,d=2-p,n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+2),10),m=2===e.slice(d,d+2).length,a=[0,n,r]),6!==e.length||"Y"!==o[0]&&"Y"!==o[1]||(p="m"===o[0]?0:4,d=2-.5*p,n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+4),10),m=4===e.slice(d,d+4).length,a=[0,n,r]),a=i.getRangeFixedDate(a),i.date=a;var f=0===a.length?e:o.reduce(function(e,t){switch(t){case"d":return e+(0===a[0]?"":i.addLeadingZero(a[0]));case"m":return e+(0===a[1]?"":i.addLeadingZero(a[1]));case"y":return e+(m?i.addLeadingZeroForYear(a[2],!1):"");case"Y":return e+(m?i.addLeadingZeroForYear(a[2],!0):"")}},"");return f},getRangeFixedDate:function(e){var t=this,n=t.datePattern,r=t.dateMin||[],i=t.dateMax||[];return!e.length||r.length<3&&i.length<3?e:n.find(function(e){return"y"===e.toLowerCase()})&&0===e[2]?e:i.length&&(i[2]e[2]||r[2]===e[2]&&(r[1]>e[1]||r[1]===e[1]&&r[0]>e[0]))?r:e},getFixedDate:function(e,t,n){return e=Math.min(e,31),t=Math.min(t,12),n=parseInt(n||0,10),(t<7&&t%2===0||t>8&&t%2===1)&&(e=Math.min(e,2===t?this.isLeapYear(n)?29:28:30)),[e,t,n]},isLeapYear:function(e){return e%4===0&&e%100!==0||e%400===0},addLeadingZero:function(e){return(e<10?"0":"")+e},addLeadingZeroForYear:function(e,t){return t?(e<10?"000":e<100?"00":e<1e3?"0":"")+e:(e<10?"0":"")+e}},e.exports=n},function(e,t){"use strict";var n=function(e,t){var n=this;n.time=[],n.blocks=[],n.timePattern=e,n.timeFormat=t,n.initBlocks()};n.prototype={initBlocks:function(){var e=this;e.timePattern.forEach(function(){e.blocks.push(2)})},getISOFormatTime:function(){var e=this,t=e.time;return t[2]?e.addLeadingZero(t[0])+":"+e.addLeadingZero(t[1])+":"+e.addLeadingZero(t[2]):""},getBlocks:function(){return this.blocks},getTimeFormatOptions:function(){var e=this;return"12"===String(e.timeFormat)?{maxHourFirstDigit:1,maxHours:12,maxMinutesFirstDigit:5,maxMinutes:60}:{maxHourFirstDigit:2,maxHours:23,maxMinutesFirstDigit:5,maxMinutes:60}},getValidatedTime:function(e){var t=this,n="";e=e.replace(/[^\d]/g,"");var r=t.getTimeFormatOptions();return t.blocks.forEach(function(i,o){if(e.length>0){var a=e.slice(0,i),s=a.slice(0,1),c=e.slice(i);switch(t.timePattern[o]){case"h":parseInt(s,10)>r.maxHourFirstDigit?a="0"+s:parseInt(a,10)>r.maxHours&&(a=r.maxHours+"");break;case"m":case"s":parseInt(s,10)>r.maxMinutesFirstDigit?a="0"+s:parseInt(a,10)>r.maxMinutes&&(a=r.maxMinutes+"")}n+=a,e=c}}),this.getFixedTimeString(n)},getFixedTimeString:function(e){var t,n,r,i=this,o=i.timePattern,a=[],s=0,c=0,u=0,l=0,p=0,d=0;return 6===e.length&&(o.forEach(function(e,t){switch(e){case"s":s=2*t;break;case"m":c=2*t;break;case"h":u=2*t}}),d=u,p=c,l=s,t=parseInt(e.slice(l,l+2),10),n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+2),10),a=this.getFixedTime(r,n,t)),4===e.length&&i.timePattern.indexOf("s")<0&&(o.forEach(function(e,t){switch(e){case"m":c=2*t;break;case"h":u=2*t}}),d=u,p=c,t=0,n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+2),10),a=this.getFixedTime(r,n,t)),i.time=a,0===a.length?e:o.reduce(function(e,t){switch(t){case"s":return e+i.addLeadingZero(a[2]);case"m":return e+i.addLeadingZero(a[1]);case"h":return e+i.addLeadingZero(a[0])}},"")},getFixedTime:function(e,t,n){return n=Math.min(parseInt(n||0,10),60),t=Math.min(t,60),e=Math.min(e,60),[e,t,n]},addLeadingZero:function(e){return(e<10?"0":"")+e}},e.exports=n},function(e,t){"use strict";var n=function(e,t){var n=this;n.delimiter=t||""===t?t:" ",n.delimiterRE=t?new RegExp("\\"+t,"g"):"",n.formatter=e};n.prototype={setFormatter:function(e){this.formatter=e},format:function(e){var t=this;t.formatter.clear(),e=e.replace(/[^\d+]/g,""),e=e.replace(/^\+/,"B").replace(/\+/g,"").replace("B","+"),e=e.replace(t.delimiterRE,"");for(var n,r="",i=!1,o=0,a=e.length;o0;return 0===n?e:(t.forEach(function(t,u){if(e.length>0){var l=e.slice(0,t),p=e.slice(t);a=c?i[o?u-1:u]||a:r,o?(u>0&&(s+=a),s+=l):(s+=l,l.length===t&&u0?r.numeralIntegerScale:0,e.numeralDecimalScale=r.numeralDecimalScale>=0?r.numeralDecimalScale:2,e.numeralDecimalMark=r.numeralDecimalMark||".",e.numeralThousandsGroupStyle=r.numeralThousandsGroupStyle||"thousand",e.numeralPositiveOnly=!!r.numeralPositiveOnly,e.stripLeadingZeroes=r.stripLeadingZeroes!==!1,e.signBeforePrefix=!!r.signBeforePrefix,e.tailPrefix=!!r.tailPrefix,e.swapHiddenInput=!!r.swapHiddenInput,e.numericOnly=e.creditCard||e.date||!!r.numericOnly,e.uppercase=!!r.uppercase,e.lowercase=!!r.lowercase,e.prefix=e.creditCard||e.date?"":r.prefix||"",e.noImmediatePrefix=!!r.noImmediatePrefix,e.prefixLength=e.prefix.length,e.rawValueTrimPrefix=!!r.rawValueTrimPrefix,e.copyDelimiter=!!r.copyDelimiter,e.initValue=void 0!==r.initValue&&null!==r.initValue?r.initValue.toString():"",e.delimiter=r.delimiter||""===r.delimiter?r.delimiter:r.date?"/":r.time?":":r.numeral?",":(r.phone," "),e.delimiterLength=e.delimiter.length,e.delimiterLazyShow=!!r.delimiterLazyShow,e.delimiters=r.delimiters||[],e.blocks=r.blocks||[],e.blocksLength=e.blocks.length,e.root="object"===("undefined"==typeof t?"undefined":n(t))&&t?t:window,e.document=r.document||e.root.document,e.maxLength=0,e.backspace=!1,e.result="",e.onValueChanged=r.onValueChanged||function(){},e}};e.exports=r}).call(t,function(){return this}())}])}); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.Cleave=t(require("react")):e.Cleave=t(e.React)}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return e[r].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}var i=Object.assign||function(e){for(var t=1;t0?d.headStr(e,r.maxLength):e,r.result=d.getFormattedValue(e,r.blocks,r.blocksLength,r.delimiter,r.delimiters,r.delimiterLazyShow),void n.updateValueState()):(r.result=e,void n.updateValueState()))},updateCreditCardPropsByValue:function(e){var t,n=this,r=n.properties;d.headStr(r.result,4)!==d.headStr(e,4)&&(t=p.getInfo(e,r.creditCardStrictMode),r.blocks=t.blocks,r.blocksLength=r.blocks.length,r.maxLength=d.getMaxLength(r.blocks),r.creditCardType!==t.type&&(r.creditCardType=t.type,r.onCreditCardTypeChanged.call(n,r.creditCardType)))},updateValueState:function(){var e=this,t=e.properties;if(!e.element)return void e.setState({value:t.result});var n=e.element.selectionEnd,r=e.element.value,i=t.result;return e.lastInputValue=i,n=d.getNextCursorPosition(n,r,i,t.delimiter,t.delimiters),e.isAndroid?void window.setTimeout(function(){e.setState({value:i,cursorPosition:n})},1):void e.setState({value:i,cursorPosition:n})},render:function(){var e=this,t=e.props,n=(t.value,t.options,t.onKeyDown,t.onFocus,t.onBlur,t.onChange,t.onInit,t.htmlRef),a=r(t,["value","options","onKeyDown","onFocus","onBlur","onChange","onInit","htmlRef"]);return o.createElement("input",i({type:"text",ref:function(t){e.element=t,n&&n.apply(this,arguments)},value:e.state.value,onKeyDown:e.onKeyDown,onChange:e.onChange,onFocus:e.onFocus,onBlur:e.onBlur},a))}});e.exports=f},function(t,n){t.exports=e},function(e,t,n){"use strict";var r=n(1),i=n(3);if("undefined"==typeof r)throw Error("create-react-class could not find the React object. If you are using script tags, make sure that React is being loaded before create-react-class.");var o=(new r.Component).updater;e.exports=i(r.Component,r.isValidElement,o)},function(e,t,n){(function(t){"use strict";function r(e){return e}function i(e,n,i){function p(e,n,r){for(var i in n)n.hasOwnProperty(i)&&"production"!==t.env.NODE_ENV&&c("function"==typeof n[i],"%s: %s type `%s` is invalid; it must be a function, usually from React.PropTypes.",e.displayName||"ReactClass",u[r],i)}function d(e,t){var n=b.hasOwnProperty(t)?b[t]:null;F.hasOwnProperty(t)&&s("OVERRIDE_BASE"===n,"ReactClassInterface: You are attempting to override `%s` from your class specification. Ensure that your method names do not overlap with React methods.",t),e&&s("DEFINE_MANY"===n||"DEFINE_MANY_MERGED"===n,"ReactClassInterface: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.",t)}function m(e,r){if(r){s("function"!=typeof r,"ReactClass: You're attempting to use a component class or function as a mixin. Instead, just use a regular object."),s(!n(r),"ReactClass: You're attempting to use a component as a mixin. Instead, just use a regular object.");var i=e.prototype,o=i.__reactAutoBindPairs;r.hasOwnProperty(l)&&I.mixins(e,r.mixins);for(var a in r)if(r.hasOwnProperty(a)&&a!==l){var u=r[a],p=i.hasOwnProperty(a);if(d(p,a),I.hasOwnProperty(a))I[a](e,u);else{var m=b.hasOwnProperty(a),f="function"==typeof u,h=f&&!m&&!p&&r.autobind!==!1;if(h)o.push(a,u),i[a]=u;else if(p){var y=b[a];s(m&&("DEFINE_MANY_MERGED"===y||"DEFINE_MANY"===y),"ReactClass: Unexpected spec policy %s for key %s when mixing in component specs.",y,a),"DEFINE_MANY_MERGED"===y?i[a]=g(i[a],u):"DEFINE_MANY"===y&&(i[a]=v(i[a],u))}else i[a]=u,"production"!==t.env.NODE_ENV&&"function"==typeof u&&r.displayName&&(i[a].displayName=r.displayName+"_"+a)}}}else if("production"!==t.env.NODE_ENV){var x=typeof r,E="object"===x&&null!==r;"production"!==t.env.NODE_ENV&&c(E,"%s: You're attempting to include a mixin that is either null or not an object. Check the mixins included by the component, as well as any mixins they include themselves. Expected object but got %s.",e.displayName||"ReactClass",null===r?null:x)}}function f(e,t){if(t)for(var n in t){var r=t[n];if(t.hasOwnProperty(n)){var i=n in I;s(!i,'ReactClass: You are attempting to define a reserved property, `%s`, that shouldn\'t be on the "statics" key. Define it as an instance property instead; it will still be accessible on the constructor.',n);var o=n in e;if(o){var a=w.hasOwnProperty(n)?w[n]:null;return s("DEFINE_MANY_MERGED"===a,"ReactClass: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.",n),void(e[n]=g(e[n],r))}e[n]=r}}}function h(e,t){s(e&&t&&"object"==typeof e&&"object"==typeof t,"mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.");for(var n in t)t.hasOwnProperty(n)&&(s(void 0===e[n],"mergeIntoWithNoDuplicateKeys(): Tried to merge two objects with the same key: `%s`. This conflict may be due to a mixin; in particular, this may be caused by two getInitialState() or getDefaultProps() methods returning objects with clashing keys.",n),e[n]=t[n]);return e}function g(e,t){return function(){var n=e.apply(this,arguments),r=t.apply(this,arguments);if(null==n)return r;if(null==r)return n;var i={};return h(i,n),h(i,r),i}}function v(e,t){return function(){e.apply(this,arguments),t.apply(this,arguments)}}function y(e,n){var r=n.bind(e);if("production"!==t.env.NODE_ENV){r.__reactBoundContext=e,r.__reactBoundMethod=n,r.__reactBoundArguments=null;var i=e.constructor.displayName,o=r.bind;r.bind=function(a){for(var s=arguments.length,u=Array(s>1?s-1:0),l=1;l1)for(var n=1;n1?t-1:0),r=1;r2?n-2:0),i=2;i0?t:0,p.numeralDecimalScale=n>=0?n:2,p.numeralThousandsGroupStyle=i||r.groupStyle.thousand,p.numeralPositiveOnly=!!o,p.stripLeadingZeroes=a!==!1,p.prefix=s||""===s?s:"",p.signBeforePrefix=!!c,p.tailPrefix=!!u,p.delimiter=l||""===l?l:",",p.delimiterRE=l?new RegExp("\\"+l,"g"):""};n.groupStyle={thousand:"thousand",lakh:"lakh",wan:"wan",none:"none"},n.prototype={getRawValue:function(e){return e.replace(this.delimiterRE,"").replace(this.numeralDecimalMark,".")},format:function(e){var t,r,i,o,a=this,s="";switch(e=e.replace(/[A-Za-z]/g,"").replace(a.numeralDecimalMark,"M").replace(/[^\dM-]/g,"").replace(/^\-/,"N").replace(/\-/g,"").replace("N",a.numeralPositiveOnly?"":"-").replace("M",a.numeralDecimalMark),a.stripLeadingZeroes&&(e=e.replace(/^(-)?0+(?=\d)/,"$1")),r="-"===e.slice(0,1)?"-":"",i="undefined"!=typeof a.prefix?a.signBeforePrefix?r+a.prefix:a.prefix+r:r,o=e,e.indexOf(a.numeralDecimalMark)>=0&&(t=e.split(a.numeralDecimalMark),o=t[0],s=a.numeralDecimalMark+t[1].slice(0,a.numeralDecimalScale)),"-"===r&&(o=o.slice(1)),a.numeralIntegerScale>0&&(o=o.slice(0,a.numeralIntegerScale)),a.numeralThousandsGroupStyle){case n.groupStyle.lakh:o=o.replace(/(\d)(?=(\d\d)+\d$)/g,"$1"+a.delimiter);break;case n.groupStyle.wan:o=o.replace(/(\d)(?=(\d{4})+$)/g,"$1"+a.delimiter);break;case n.groupStyle.thousand:o=o.replace(/(\d)(?=(\d{3})+$)/g,"$1"+a.delimiter)}return a.tailPrefix?r+o.toString()+(a.numeralDecimalScale>0?s.toString():"")+a.prefix:i+o.toString()+(a.numeralDecimalScale>0?s.toString():"")}},e.exports=n},function(e,t){"use strict";var n=function(e,t,n){var r=this;r.date=[],r.blocks=[],r.datePattern=e,r.dateMin=t.split("-").reverse().map(function(e){return parseInt(e,10)}),2===r.dateMin.length&&r.dateMin.unshift(0),r.dateMax=n.split("-").reverse().map(function(e){return parseInt(e,10)}),2===r.dateMax.length&&r.dateMax.unshift(0),r.initBlocks()};n.prototype={initBlocks:function(){var e=this;e.datePattern.forEach(function(t){"Y"===t?e.blocks.push(4):e.blocks.push(2)})},getISOFormatDate:function(){var e=this,t=e.date;return t[2]?t[2]+"-"+e.addLeadingZero(t[1])+"-"+e.addLeadingZero(t[0]):""},getBlocks:function(){return this.blocks},getValidatedDate:function(e){var t=this,n="";return e=e.replace(/[^\d]/g,""),t.blocks.forEach(function(r,i){if(e.length>0){var o=e.slice(0,r),a=o.slice(0,1),s=e.slice(r);switch(t.datePattern[i]){case"d":"00"===o?o="01":parseInt(a,10)>3?o="0"+a:parseInt(o,10)>31&&(o="31");break;case"m":"00"===o?o="01":parseInt(a,10)>1?o="0"+a:parseInt(o,10)>12&&(o="12")}n+=o,e=s}}),this.getFixedDateString(n)},getFixedDateString:function(e){var t,n,r,i=this,o=i.datePattern,a=[],s=0,c=0,u=0,l=0,p=0,d=0,m=!1;4===e.length&&"y"!==o[0].toLowerCase()&&"y"!==o[1].toLowerCase()&&(l="d"===o[0]?0:2,p=2-l,t=parseInt(e.slice(l,l+2),10),n=parseInt(e.slice(p,p+2),10),a=this.getFixedDate(t,n,0)),8===e.length&&(o.forEach(function(e,t){switch(e){case"d":s=t;break;case"m":c=t;break;default:u=t}}),d=2*u,l=s<=u?2*s:2*s+2,p=c<=u?2*c:2*c+2,t=parseInt(e.slice(l,l+2),10),n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+4),10),m=4===e.slice(d,d+4).length,a=this.getFixedDate(t,n,r)),4!==e.length||"y"!==o[0]&&"y"!==o[1]||(p="m"===o[0]?0:2,d=2-p,n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+2),10),m=2===e.slice(d,d+2).length,a=[0,n,r]),6!==e.length||"Y"!==o[0]&&"Y"!==o[1]||(p="m"===o[0]?0:4,d=2-.5*p,n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+4),10),m=4===e.slice(d,d+4).length,a=[0,n,r]),a=i.getRangeFixedDate(a),i.date=a;var f=0===a.length?e:o.reduce(function(e,t){switch(t){case"d":return e+(0===a[0]?"":i.addLeadingZero(a[0]));case"m":return e+(0===a[1]?"":i.addLeadingZero(a[1]));case"y":return e+(m?i.addLeadingZeroForYear(a[2],!1):"");case"Y":return e+(m?i.addLeadingZeroForYear(a[2],!0):"")}},"");return f},getRangeFixedDate:function(e){var t=this,n=t.datePattern,r=t.dateMin||[],i=t.dateMax||[];return!e.length||r.length<3&&i.length<3?e:n.find(function(e){return"y"===e.toLowerCase()})&&0===e[2]?e:i.length&&(i[2]e[2]||r[2]===e[2]&&(r[1]>e[1]||r[1]===e[1]&&r[0]>e[0]))?r:e},getFixedDate:function(e,t,n){return e=Math.min(e,31),t=Math.min(t,12),n=parseInt(n||0,10),(t<7&&t%2===0||t>8&&t%2===1)&&(e=Math.min(e,2===t?this.isLeapYear(n)?29:28:30)),[e,t,n]},isLeapYear:function(e){return e%4===0&&e%100!==0||e%400===0},addLeadingZero:function(e){return(e<10?"0":"")+e},addLeadingZeroForYear:function(e,t){return t?(e<10?"000":e<100?"00":e<1e3?"0":"")+e:(e<10?"0":"")+e}},e.exports=n},function(e,t){"use strict";var n=function(e,t){var n=this;n.time=[],n.blocks=[],n.timePattern=e,n.timeFormat=t,n.initBlocks()};n.prototype={initBlocks:function(){var e=this;e.timePattern.forEach(function(){e.blocks.push(2)})},getISOFormatTime:function(){var e=this,t=e.time;return t[2]?e.addLeadingZero(t[0])+":"+e.addLeadingZero(t[1])+":"+e.addLeadingZero(t[2]):""},getBlocks:function(){return this.blocks},getTimeFormatOptions:function(){var e=this;return"12"===String(e.timeFormat)?{maxHourFirstDigit:1,maxHours:12,maxMinutesFirstDigit:5,maxMinutes:60}:{maxHourFirstDigit:2,maxHours:23,maxMinutesFirstDigit:5,maxMinutes:60}},getValidatedTime:function(e){var t=this,n="";e=e.replace(/[^\d]/g,"");var r=t.getTimeFormatOptions();return t.blocks.forEach(function(i,o){if(e.length>0){var a=e.slice(0,i),s=a.slice(0,1),c=e.slice(i);switch(t.timePattern[o]){case"h":parseInt(s,10)>r.maxHourFirstDigit?a="0"+s:parseInt(a,10)>r.maxHours&&(a=r.maxHours+"");break;case"m":case"s":parseInt(s,10)>r.maxMinutesFirstDigit?a="0"+s:parseInt(a,10)>r.maxMinutes&&(a=r.maxMinutes+"")}n+=a,e=c}}),this.getFixedTimeString(n)},getFixedTimeString:function(e){var t,n,r,i=this,o=i.timePattern,a=[],s=0,c=0,u=0,l=0,p=0,d=0;return 6===e.length&&(o.forEach(function(e,t){switch(e){case"s":s=2*t;break;case"m":c=2*t;break;case"h":u=2*t}}),d=u,p=c,l=s,t=parseInt(e.slice(l,l+2),10),n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+2),10),a=this.getFixedTime(r,n,t)),4===e.length&&i.timePattern.indexOf("s")<0&&(o.forEach(function(e,t){switch(e){case"m":c=2*t;break;case"h":u=2*t}}),d=u,p=c,t=0,n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+2),10),a=this.getFixedTime(r,n,t)),i.time=a,0===a.length?e:o.reduce(function(e,t){switch(t){case"s":return e+i.addLeadingZero(a[2]);case"m":return e+i.addLeadingZero(a[1]);case"h":return e+i.addLeadingZero(a[0])}},"")},getFixedTime:function(e,t,n){return n=Math.min(parseInt(n||0,10),60),t=Math.min(t,60),e=Math.min(e,60),[e,t,n]},addLeadingZero:function(e){return(e<10?"0":"")+e}},e.exports=n},function(e,t){"use strict";var n=function(e,t){var n=this;n.delimiter=t||""===t?t:" ",n.delimiterRE=t?new RegExp("\\"+t,"g"):"",n.formatter=e};n.prototype={setFormatter:function(e){this.formatter=e},format:function(e){var t=this;t.formatter.clear(),e=e.replace(/[^\d+]/g,""),e=e.replace(/^\+/,"B").replace(/\+/g,"").replace("B","+"),e=e.replace(t.delimiterRE,"");for(var n,r="",i=!1,o=0,a=e.length;o0;return 0===n?e:(t.forEach(function(t,u){if(e.length>0){var l=e.slice(0,t),p=e.slice(t);a=c?i[o?u-1:u]||a:r,o?(u>0&&(s+=a),s+=l):(s+=l,l.length===t&&u0?r.numeralIntegerScale:0,e.numeralDecimalScale=r.numeralDecimalScale>=0?r.numeralDecimalScale:2,e.numeralDecimalMark=r.numeralDecimalMark||".",e.numeralThousandsGroupStyle=r.numeralThousandsGroupStyle||"thousand",e.numeralPositiveOnly=!!r.numeralPositiveOnly,e.stripLeadingZeroes=r.stripLeadingZeroes!==!1,e.signBeforePrefix=!!r.signBeforePrefix,e.tailPrefix=!!r.tailPrefix,e.swapHiddenInput=!!r.swapHiddenInput,e.numericOnly=e.creditCard||e.date||!!r.numericOnly,e.uppercase=!!r.uppercase,e.lowercase=!!r.lowercase,e.prefix=e.creditCard||e.date?"":r.prefix||"",e.noImmediatePrefix=!!r.noImmediatePrefix,e.prefixLength=e.prefix.length,e.rawValueTrimPrefix=!!r.rawValueTrimPrefix,e.copyDelimiter=!!r.copyDelimiter,e.initValue=void 0!==r.initValue&&null!==r.initValue?r.initValue.toString():"",e.delimiter=r.delimiter||""===r.delimiter?r.delimiter:r.date?"/":r.time?":":r.numeral?",":(r.phone," "),e.delimiterLength=e.delimiter.length,e.delimiterLazyShow=!!r.delimiterLazyShow,e.delimiters=r.delimiters||[],e.blocks=r.blocks||[],e.blocksLength=e.blocks.length,e.root="object"===("undefined"==typeof t?"undefined":n(t))&&t?t:window,e.document=r.document||e.root.document,e.maxLength=0,e.backspace=!1,e.result="",e.onValueChanged=r.onValueChanged||function(){},e}};e.exports=r}).call(t,function(){return this}())}])}); \ No newline at end of file diff --git a/dist/cleave.js b/dist/cleave.js index e210c711..879b4c27 100644 --- a/dist/cleave.js +++ b/dist/cleave.js @@ -366,7 +366,7 @@ return /******/ (function(modules) { // webpackBootstrap if (pps.prefix && (!pps.noImmediatePrefix || value.length)) { if (pps.tailPrefix) { value = value + pps.prefix; - } else { + } else if(value !== pps.prefix) { value = pps.prefix + value; } diff --git a/dist/cleave.min.js b/dist/cleave.min.js index 11a8b47e..195d0ec0 100644 --- a/dist/cleave.min.js +++ b/dist/cleave.min.js @@ -5,4 +5,4 @@ * * Copyright (C) 2012-2020 Max Huang https://github.com/nosir/ */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Cleave=t():e.Cleave=t()}(this,function(){return function(e){function t(i){if(r[i])return r[i].exports;var n=r[i]={exports:{},id:i,loaded:!1};return e[i].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){(function(t){"use strict";var i=function(e,t){var r=this,n=!1;if("string"==typeof e?(r.element=document.querySelector(e),n=document.querySelectorAll(e).length>1):"undefined"!=typeof e.length&&e.length>0?(r.element=e[0],n=e.length>1):r.element=e,!r.element)throw new Error("[cleave.js] Please check the element");if(n)try{console.warn("[cleave.js] Multiple input fields matched, cleave.js will only take the first one.")}catch(a){}t.initValue=r.element.value,r.properties=i.DefaultProperties.assign({},t),r.init()};i.prototype={init:function(){var e=this,t=e.properties;return t.numeral||t.phone||t.creditCard||t.time||t.date||0!==t.blocksLength||t.prefix?(t.maxLength=i.Util.getMaxLength(t.blocks),e.isAndroid=i.Util.isAndroid(),e.lastInputValue="",e.onChangeListener=e.onChange.bind(e),e.onKeyDownListener=e.onKeyDown.bind(e),e.onFocusListener=e.onFocus.bind(e),e.onCutListener=e.onCut.bind(e),e.onCopyListener=e.onCopy.bind(e),e.initSwapHiddenInput(),e.element.addEventListener("input",e.onChangeListener),e.element.addEventListener("keydown",e.onKeyDownListener),e.element.addEventListener("focus",e.onFocusListener),e.element.addEventListener("cut",e.onCutListener),e.element.addEventListener("copy",e.onCopyListener),e.initPhoneFormatter(),e.initDateFormatter(),e.initTimeFormatter(),e.initNumeralFormatter(),void((t.initValue||t.prefix&&!t.noImmediatePrefix)&&e.onInput(t.initValue))):void e.onInput(t.initValue)},initSwapHiddenInput:function(){var e=this,t=e.properties;if(t.swapHiddenInput){var r=e.element.cloneNode(!0);e.element.parentNode.insertBefore(r,e.element),e.elementSwapHidden=e.element,e.elementSwapHidden.type="hidden",e.element=r,e.element.id=""}},initNumeralFormatter:function(){var e=this,t=e.properties;t.numeral&&(t.numeralFormatter=new i.NumeralFormatter(t.numeralDecimalMark,t.numeralIntegerScale,t.numeralDecimalScale,t.numeralThousandsGroupStyle,t.numeralPositiveOnly,t.stripLeadingZeroes,t.prefix,t.signBeforePrefix,t.tailPrefix,t.delimiter))},initTimeFormatter:function(){var e=this,t=e.properties;t.time&&(t.timeFormatter=new i.TimeFormatter(t.timePattern,t.timeFormat),t.blocks=t.timeFormatter.getBlocks(),t.blocksLength=t.blocks.length,t.maxLength=i.Util.getMaxLength(t.blocks))},initDateFormatter:function(){var e=this,t=e.properties;t.date&&(t.dateFormatter=new i.DateFormatter(t.datePattern,t.dateMin,t.dateMax),t.blocks=t.dateFormatter.getBlocks(),t.blocksLength=t.blocks.length,t.maxLength=i.Util.getMaxLength(t.blocks))},initPhoneFormatter:function(){var e=this,t=e.properties;if(t.phone)try{t.phoneFormatter=new i.PhoneFormatter(new t.root.Cleave.AsYouTypeFormatter(t.phoneRegionCode),t.delimiter)}catch(r){throw new Error("[cleave.js] Please include phone-type-formatter.{country}.js lib")}},onKeyDown:function(e){var t=this,r=t.properties,n=e.which||e.keyCode,a=i.Util,o=t.element.value;t.hasBackspaceSupport=t.hasBackspaceSupport||8===n,!t.hasBackspaceSupport&&a.isAndroidBackspaceKeydown(t.lastInputValue,o)&&(n=8),t.lastInputValue=o;var l=a.getPostDelimiter(o,r.delimiter,r.delimiters);8===n&&l?r.postDelimiterBackspace=l:r.postDelimiterBackspace=!1},onChange:function(){this.onInput(this.element.value)},onFocus:function(){var e=this,t=e.properties;t.prefix&&t.noImmediatePrefix&&!e.element.value&&this.onInput(t.prefix),i.Util.fixPrefixCursor(e.element,t.prefix,t.delimiter,t.delimiters)},onCut:function(e){i.Util.checkFullSelection(this.element.value)&&(this.copyClipboardData(e),this.onInput(""))},onCopy:function(e){i.Util.checkFullSelection(this.element.value)&&this.copyClipboardData(e)},copyClipboardData:function(e){var t=this,r=t.properties,n=i.Util,a=t.element.value,o="";o=r.copyDelimiter?a:n.stripDelimiters(a,r.delimiter,r.delimiters);try{e.clipboardData?e.clipboardData.setData("Text",o):window.clipboardData.setData("Text",o),e.preventDefault()}catch(l){}},onInput:function(e){var t=this,r=t.properties,n=i.Util,a=n.getPostDelimiter(e,r.delimiter,r.delimiters);return r.numeral||!r.postDelimiterBackspace||a||(e=n.headStr(e,e.length-r.postDelimiterBackspace.length)),r.phone?(!r.prefix||r.noImmediatePrefix&&!e.length?r.result=r.phoneFormatter.format(e):r.result=r.prefix+r.phoneFormatter.format(e).slice(r.prefix.length),void t.updateValueState()):r.numeral?(r.prefix&&r.noImmediatePrefix&&0===e.length?r.result="":r.result=r.numeralFormatter.format(e),void t.updateValueState()):(r.date&&(e=r.dateFormatter.getValidatedDate(e)),r.time&&(e=r.timeFormatter.getValidatedTime(e)),e=n.stripDelimiters(e,r.delimiter,r.delimiters),e=n.getPrefixStrippedValue(e,r.prefix,r.prefixLength,r.result,r.delimiter,r.delimiters,r.noImmediatePrefix,r.tailPrefix,r.signBeforePrefix),e=r.numericOnly?n.strip(e,/[^\d]/g):e,e=r.uppercase?e.toUpperCase():e,e=r.lowercase?e.toLowerCase():e,!r.prefix||r.noImmediatePrefix&&!e.length||(r.tailPrefix?e+=r.prefix:e=r.prefix+e,0!==r.blocksLength)?(r.creditCard&&t.updateCreditCardPropsByValue(e),e=n.headStr(e,r.maxLength),r.result=n.getFormattedValue(e,r.blocks,r.blocksLength,r.delimiter,r.delimiters,r.delimiterLazyShow),void t.updateValueState()):(r.result=e,void t.updateValueState()))},updateCreditCardPropsByValue:function(e){var t,r=this,n=r.properties,a=i.Util;a.headStr(n.result,4)!==a.headStr(e,4)&&(t=i.CreditCardDetector.getInfo(e,n.creditCardStrictMode),n.blocks=t.blocks,n.blocksLength=n.blocks.length,n.maxLength=a.getMaxLength(n.blocks),n.creditCardType!==t.type&&(n.creditCardType=t.type,n.onCreditCardTypeChanged.call(r,n.creditCardType)))},updateValueState:function(){var e=this,t=i.Util,r=e.properties;if(e.element){var n=e.element.selectionEnd,a=e.element.value,o=r.result;if(n=t.getNextCursorPosition(n,a,o,r.delimiter,r.delimiters),e.isAndroid)return void window.setTimeout(function(){e.element.value=o,t.setSelection(e.element,n,r.document,!1),e.callOnValueChanged()},1);e.element.value=o,r.swapHiddenInput&&(e.elementSwapHidden.value=e.getRawValue()),t.setSelection(e.element,n,r.document,!1),e.callOnValueChanged()}},callOnValueChanged:function(){var e=this,t=e.properties;t.onValueChanged.call(e,{target:{name:e.element.name,value:t.result,rawValue:e.getRawValue()}})},setPhoneRegionCode:function(e){var t=this,r=t.properties;r.phoneRegionCode=e,t.initPhoneFormatter(),t.onChange()},setRawValue:function(e){var t=this,r=t.properties;e=void 0!==e&&null!==e?e.toString():"",r.numeral&&(e=e.replace(".",r.numeralDecimalMark)),r.postDelimiterBackspace=!1,t.element.value=e,t.onInput(e)},getRawValue:function(){var e=this,t=e.properties,r=i.Util,n=e.element.value;return t.rawValueTrimPrefix&&(n=r.getPrefixStrippedValue(n,t.prefix,t.prefixLength,t.result,t.delimiter,t.delimiters,t.noImmediatePrefix,t.tailPrefix,t.signBeforePrefix)),n=t.numeral?t.numeralFormatter.getRawValue(n):r.stripDelimiters(n,t.delimiter,t.delimiters)},getISOFormatDate:function(){var e=this,t=e.properties;return t.date?t.dateFormatter.getISOFormatDate():""},getISOFormatTime:function(){var e=this,t=e.properties;return t.time?t.timeFormatter.getISOFormatTime():""},getFormattedValue:function(){return this.element.value},destroy:function(){var e=this;e.element.removeEventListener("input",e.onChangeListener),e.element.removeEventListener("keydown",e.onKeyDownListener),e.element.removeEventListener("focus",e.onFocusListener),e.element.removeEventListener("cut",e.onCutListener),e.element.removeEventListener("copy",e.onCopyListener)},toString:function(){return"[Cleave Object]"}},i.NumeralFormatter=r(1),i.DateFormatter=r(2),i.TimeFormatter=r(3),i.PhoneFormatter=r(4),i.CreditCardDetector=r(5),i.Util=r(6),i.DefaultProperties=r(7),("object"==typeof t&&t?t:window).Cleave=i,e.exports=i}).call(t,function(){return this}())},function(e,t){"use strict";var r=function(e,t,i,n,a,o,l,s,c,u){var d=this;d.numeralDecimalMark=e||".",d.numeralIntegerScale=t>0?t:0,d.numeralDecimalScale=i>=0?i:2,d.numeralThousandsGroupStyle=n||r.groupStyle.thousand,d.numeralPositiveOnly=!!a,d.stripLeadingZeroes=o!==!1,d.prefix=l||""===l?l:"",d.signBeforePrefix=!!s,d.tailPrefix=!!c,d.delimiter=u||""===u?u:",",d.delimiterRE=u?new RegExp("\\"+u,"g"):""};r.groupStyle={thousand:"thousand",lakh:"lakh",wan:"wan",none:"none"},r.prototype={getRawValue:function(e){return e.replace(this.delimiterRE,"").replace(this.numeralDecimalMark,".")},format:function(e){var t,i,n,a,o=this,l="";switch(e=e.replace(/[A-Za-z]/g,"").replace(o.numeralDecimalMark,"M").replace(/[^\dM-]/g,"").replace(/^\-/,"N").replace(/\-/g,"").replace("N",o.numeralPositiveOnly?"":"-").replace("M",o.numeralDecimalMark),o.stripLeadingZeroes&&(e=e.replace(/^(-)?0+(?=\d)/,"$1")),i="-"===e.slice(0,1)?"-":"",n="undefined"!=typeof o.prefix?o.signBeforePrefix?i+o.prefix:o.prefix+i:i,a=e,e.indexOf(o.numeralDecimalMark)>=0&&(t=e.split(o.numeralDecimalMark),a=t[0],l=o.numeralDecimalMark+t[1].slice(0,o.numeralDecimalScale)),"-"===i&&(a=a.slice(1)),o.numeralIntegerScale>0&&(a=a.slice(0,o.numeralIntegerScale)),o.numeralThousandsGroupStyle){case r.groupStyle.lakh:a=a.replace(/(\d)(?=(\d\d)+\d$)/g,"$1"+o.delimiter);break;case r.groupStyle.wan:a=a.replace(/(\d)(?=(\d{4})+$)/g,"$1"+o.delimiter);break;case r.groupStyle.thousand:a=a.replace(/(\d)(?=(\d{3})+$)/g,"$1"+o.delimiter)}return o.tailPrefix?i+a.toString()+(o.numeralDecimalScale>0?l.toString():"")+o.prefix:n+a.toString()+(o.numeralDecimalScale>0?l.toString():"")}},e.exports=r},function(e,t){"use strict";var r=function(e,t,r){var i=this;i.date=[],i.blocks=[],i.datePattern=e,i.dateMin=t.split("-").reverse().map(function(e){return parseInt(e,10)}),2===i.dateMin.length&&i.dateMin.unshift(0),i.dateMax=r.split("-").reverse().map(function(e){return parseInt(e,10)}),2===i.dateMax.length&&i.dateMax.unshift(0),i.initBlocks()};r.prototype={initBlocks:function(){var e=this;e.datePattern.forEach(function(t){"Y"===t?e.blocks.push(4):e.blocks.push(2)})},getISOFormatDate:function(){var e=this,t=e.date;return t[2]?t[2]+"-"+e.addLeadingZero(t[1])+"-"+e.addLeadingZero(t[0]):""},getBlocks:function(){return this.blocks},getValidatedDate:function(e){var t=this,r="";return e=e.replace(/[^\d]/g,""),t.blocks.forEach(function(i,n){if(e.length>0){var a=e.slice(0,i),o=a.slice(0,1),l=e.slice(i);switch(t.datePattern[n]){case"d":"00"===a?a="01":parseInt(o,10)>3?a="0"+o:parseInt(a,10)>31&&(a="31");break;case"m":"00"===a?a="01":parseInt(o,10)>1?a="0"+o:parseInt(a,10)>12&&(a="12")}r+=a,e=l}}),this.getFixedDateString(r)},getFixedDateString:function(e){var t,r,i,n=this,a=n.datePattern,o=[],l=0,s=0,c=0,u=0,d=0,m=0,p=!1;4===e.length&&"y"!==a[0].toLowerCase()&&"y"!==a[1].toLowerCase()&&(u="d"===a[0]?0:2,d=2-u,t=parseInt(e.slice(u,u+2),10),r=parseInt(e.slice(d,d+2),10),o=this.getFixedDate(t,r,0)),8===e.length&&(a.forEach(function(e,t){switch(e){case"d":l=t;break;case"m":s=t;break;default:c=t}}),m=2*c,u=l<=c?2*l:2*l+2,d=s<=c?2*s:2*s+2,t=parseInt(e.slice(u,u+2),10),r=parseInt(e.slice(d,d+2),10),i=parseInt(e.slice(m,m+4),10),p=4===e.slice(m,m+4).length,o=this.getFixedDate(t,r,i)),4!==e.length||"y"!==a[0]&&"y"!==a[1]||(d="m"===a[0]?0:2,m=2-d,r=parseInt(e.slice(d,d+2),10),i=parseInt(e.slice(m,m+2),10),p=2===e.slice(m,m+2).length,o=[0,r,i]),6!==e.length||"Y"!==a[0]&&"Y"!==a[1]||(d="m"===a[0]?0:4,m=2-.5*d,r=parseInt(e.slice(d,d+2),10),i=parseInt(e.slice(m,m+4),10),p=4===e.slice(m,m+4).length,o=[0,r,i]),o=n.getRangeFixedDate(o),n.date=o;var h=0===o.length?e:a.reduce(function(e,t){switch(t){case"d":return e+(0===o[0]?"":n.addLeadingZero(o[0]));case"m":return e+(0===o[1]?"":n.addLeadingZero(o[1]));case"y":return e+(p?n.addLeadingZeroForYear(o[2],!1):"");case"Y":return e+(p?n.addLeadingZeroForYear(o[2],!0):"")}},"");return h},getRangeFixedDate:function(e){var t=this,r=t.datePattern,i=t.dateMin||[],n=t.dateMax||[];return!e.length||i.length<3&&n.length<3?e:r.find(function(e){return"y"===e.toLowerCase()})&&0===e[2]?e:n.length&&(n[2]e[2]||i[2]===e[2]&&(i[1]>e[1]||i[1]===e[1]&&i[0]>e[0]))?i:e},getFixedDate:function(e,t,r){return e=Math.min(e,31),t=Math.min(t,12),r=parseInt(r||0,10),(t<7&&t%2===0||t>8&&t%2===1)&&(e=Math.min(e,2===t?this.isLeapYear(r)?29:28:30)),[e,t,r]},isLeapYear:function(e){return e%4===0&&e%100!==0||e%400===0},addLeadingZero:function(e){return(e<10?"0":"")+e},addLeadingZeroForYear:function(e,t){return t?(e<10?"000":e<100?"00":e<1e3?"0":"")+e:(e<10?"0":"")+e}},e.exports=r},function(e,t){"use strict";var r=function(e,t){var r=this;r.time=[],r.blocks=[],r.timePattern=e,r.timeFormat=t,r.initBlocks()};r.prototype={initBlocks:function(){var e=this;e.timePattern.forEach(function(){e.blocks.push(2)})},getISOFormatTime:function(){var e=this,t=e.time;return t[2]?e.addLeadingZero(t[0])+":"+e.addLeadingZero(t[1])+":"+e.addLeadingZero(t[2]):""},getBlocks:function(){return this.blocks},getTimeFormatOptions:function(){var e=this;return"12"===String(e.timeFormat)?{maxHourFirstDigit:1,maxHours:12,maxMinutesFirstDigit:5,maxMinutes:60}:{maxHourFirstDigit:2,maxHours:23,maxMinutesFirstDigit:5,maxMinutes:60}},getValidatedTime:function(e){var t=this,r="";e=e.replace(/[^\d]/g,"");var i=t.getTimeFormatOptions();return t.blocks.forEach(function(n,a){if(e.length>0){var o=e.slice(0,n),l=o.slice(0,1),s=e.slice(n);switch(t.timePattern[a]){case"h":parseInt(l,10)>i.maxHourFirstDigit?o="0"+l:parseInt(o,10)>i.maxHours&&(o=i.maxHours+"");break;case"m":case"s":parseInt(l,10)>i.maxMinutesFirstDigit?o="0"+l:parseInt(o,10)>i.maxMinutes&&(o=i.maxMinutes+"")}r+=o,e=s}}),this.getFixedTimeString(r)},getFixedTimeString:function(e){var t,r,i,n=this,a=n.timePattern,o=[],l=0,s=0,c=0,u=0,d=0,m=0;return 6===e.length&&(a.forEach(function(e,t){switch(e){case"s":l=2*t;break;case"m":s=2*t;break;case"h":c=2*t}}),m=c,d=s,u=l,t=parseInt(e.slice(u,u+2),10),r=parseInt(e.slice(d,d+2),10),i=parseInt(e.slice(m,m+2),10),o=this.getFixedTime(i,r,t)),4===e.length&&n.timePattern.indexOf("s")<0&&(a.forEach(function(e,t){switch(e){case"m":s=2*t;break;case"h":c=2*t}}),m=c,d=s,t=0,r=parseInt(e.slice(d,d+2),10),i=parseInt(e.slice(m,m+2),10),o=this.getFixedTime(i,r,t)),n.time=o,0===o.length?e:a.reduce(function(e,t){switch(t){case"s":return e+n.addLeadingZero(o[2]);case"m":return e+n.addLeadingZero(o[1]);case"h":return e+n.addLeadingZero(o[0])}},"")},getFixedTime:function(e,t,r){return r=Math.min(parseInt(r||0,10),60),t=Math.min(t,60),e=Math.min(e,60),[e,t,r]},addLeadingZero:function(e){return(e<10?"0":"")+e}},e.exports=r},function(e,t){"use strict";var r=function(e,t){var r=this;r.delimiter=t||""===t?t:" ",r.delimiterRE=t?new RegExp("\\"+t,"g"):"",r.formatter=e};r.prototype={setFormatter:function(e){this.formatter=e},format:function(e){var t=this;t.formatter.clear(),e=e.replace(/[^\d+]/g,""),e=e.replace(/^\+/,"B").replace(/\+/g,"").replace("B","+"),e=e.replace(t.delimiterRE,"");for(var r,i="",n=!1,a=0,o=e.length;a0;return 0===r?e:(t.forEach(function(t,c){if(e.length>0){var u=e.slice(0,t),d=e.slice(t);o=s?n[a?c-1:c]||o:i,a?(c>0&&(l+=o),l+=u):(l+=u,u.length===t&&c0?r.numeralIntegerScale:0,e.numeralDecimalScale=r.numeralDecimalScale>=0?r.numeralDecimalScale:2,e.numeralDecimalMark=r.numeralDecimalMark||".",e.numeralThousandsGroupStyle=r.numeralThousandsGroupStyle||"thousand",e.numeralPositiveOnly=!!r.numeralPositiveOnly,e.stripLeadingZeroes=r.stripLeadingZeroes!==!1,e.signBeforePrefix=!!r.signBeforePrefix,e.tailPrefix=!!r.tailPrefix,e.swapHiddenInput=!!r.swapHiddenInput,e.numericOnly=e.creditCard||e.date||!!r.numericOnly,e.uppercase=!!r.uppercase,e.lowercase=!!r.lowercase,e.prefix=e.creditCard||e.date?"":r.prefix||"",e.noImmediatePrefix=!!r.noImmediatePrefix,e.prefixLength=e.prefix.length,e.rawValueTrimPrefix=!!r.rawValueTrimPrefix,e.copyDelimiter=!!r.copyDelimiter,e.initValue=void 0!==r.initValue&&null!==r.initValue?r.initValue.toString():"",e.delimiter=r.delimiter||""===r.delimiter?r.delimiter:r.date?"/":r.time?":":r.numeral?",":(r.phone," "),e.delimiterLength=e.delimiter.length,e.delimiterLazyShow=!!r.delimiterLazyShow,e.delimiters=r.delimiters||[],e.blocks=r.blocks||[],e.blocksLength=e.blocks.length,e.root="object"==typeof t&&t?t:window,e.document=r.document||e.root.document,e.maxLength=0,e.backspace=!1,e.result="",e.onValueChanged=r.onValueChanged||function(){},e}};e.exports=r}).call(t,function(){return this}())}])}); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Cleave=t():e.Cleave=t()}(this,function(){return function(e){function t(i){if(r[i])return r[i].exports;var n=r[i]={exports:{},id:i,loaded:!1};return e[i].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){(function(t){"use strict";var i=function(e,t){var r=this,n=!1;if("string"==typeof e?(r.element=document.querySelector(e),n=document.querySelectorAll(e).length>1):"undefined"!=typeof e.length&&e.length>0?(r.element=e[0],n=e.length>1):r.element=e,!r.element)throw new Error("[cleave.js] Please check the element");if(n)try{console.warn("[cleave.js] Multiple input fields matched, cleave.js will only take the first one.")}catch(a){}t.initValue=r.element.value,r.properties=i.DefaultProperties.assign({},t),r.init()};i.prototype={init:function(){var e=this,t=e.properties;return t.numeral||t.phone||t.creditCard||t.time||t.date||0!==t.blocksLength||t.prefix?(t.maxLength=i.Util.getMaxLength(t.blocks),e.isAndroid=i.Util.isAndroid(),e.lastInputValue="",e.onChangeListener=e.onChange.bind(e),e.onKeyDownListener=e.onKeyDown.bind(e),e.onFocusListener=e.onFocus.bind(e),e.onCutListener=e.onCut.bind(e),e.onCopyListener=e.onCopy.bind(e),e.initSwapHiddenInput(),e.element.addEventListener("input",e.onChangeListener),e.element.addEventListener("keydown",e.onKeyDownListener),e.element.addEventListener("focus",e.onFocusListener),e.element.addEventListener("cut",e.onCutListener),e.element.addEventListener("copy",e.onCopyListener),e.initPhoneFormatter(),e.initDateFormatter(),e.initTimeFormatter(),e.initNumeralFormatter(),void((t.initValue||t.prefix&&!t.noImmediatePrefix)&&e.onInput(t.initValue))):void e.onInput(t.initValue)},initSwapHiddenInput:function(){var e=this,t=e.properties;if(t.swapHiddenInput){var r=e.element.cloneNode(!0);e.element.parentNode.insertBefore(r,e.element),e.elementSwapHidden=e.element,e.elementSwapHidden.type="hidden",e.element=r,e.element.id=""}},initNumeralFormatter:function(){var e=this,t=e.properties;t.numeral&&(t.numeralFormatter=new i.NumeralFormatter(t.numeralDecimalMark,t.numeralIntegerScale,t.numeralDecimalScale,t.numeralThousandsGroupStyle,t.numeralPositiveOnly,t.stripLeadingZeroes,t.prefix,t.signBeforePrefix,t.tailPrefix,t.delimiter))},initTimeFormatter:function(){var e=this,t=e.properties;t.time&&(t.timeFormatter=new i.TimeFormatter(t.timePattern,t.timeFormat),t.blocks=t.timeFormatter.getBlocks(),t.blocksLength=t.blocks.length,t.maxLength=i.Util.getMaxLength(t.blocks))},initDateFormatter:function(){var e=this,t=e.properties;t.date&&(t.dateFormatter=new i.DateFormatter(t.datePattern,t.dateMin,t.dateMax),t.blocks=t.dateFormatter.getBlocks(),t.blocksLength=t.blocks.length,t.maxLength=i.Util.getMaxLength(t.blocks))},initPhoneFormatter:function(){var e=this,t=e.properties;if(t.phone)try{t.phoneFormatter=new i.PhoneFormatter(new t.root.Cleave.AsYouTypeFormatter(t.phoneRegionCode),t.delimiter)}catch(r){throw new Error("[cleave.js] Please include phone-type-formatter.{country}.js lib")}},onKeyDown:function(e){var t=this,r=t.properties,n=e.which||e.keyCode,a=i.Util,o=t.element.value;t.hasBackspaceSupport=t.hasBackspaceSupport||8===n,!t.hasBackspaceSupport&&a.isAndroidBackspaceKeydown(t.lastInputValue,o)&&(n=8),t.lastInputValue=o;var l=a.getPostDelimiter(o,r.delimiter,r.delimiters);8===n&&l?r.postDelimiterBackspace=l:r.postDelimiterBackspace=!1},onChange:function(){this.onInput(this.element.value)},onFocus:function(){var e=this,t=e.properties;t.prefix&&t.noImmediatePrefix&&!e.element.value&&this.onInput(t.prefix),i.Util.fixPrefixCursor(e.element,t.prefix,t.delimiter,t.delimiters)},onCut:function(e){i.Util.checkFullSelection(this.element.value)&&(this.copyClipboardData(e),this.onInput(""))},onCopy:function(e){i.Util.checkFullSelection(this.element.value)&&this.copyClipboardData(e)},copyClipboardData:function(e){var t=this,r=t.properties,n=i.Util,a=t.element.value,o="";o=r.copyDelimiter?a:n.stripDelimiters(a,r.delimiter,r.delimiters);try{e.clipboardData?e.clipboardData.setData("Text",o):window.clipboardData.setData("Text",o),e.preventDefault()}catch(l){}},onInput:function(e){var t=this,r=t.properties,n=i.Util,a=n.getPostDelimiter(e,r.delimiter,r.delimiters);return r.numeral||!r.postDelimiterBackspace||a||(e=n.headStr(e,e.length-r.postDelimiterBackspace.length)),r.phone?(!r.prefix||r.noImmediatePrefix&&!e.length?r.result=r.phoneFormatter.format(e):r.result=r.prefix+r.phoneFormatter.format(e).slice(r.prefix.length),void t.updateValueState()):r.numeral?(r.prefix&&r.noImmediatePrefix&&0===e.length?r.result="":r.result=r.numeralFormatter.format(e),void t.updateValueState()):(r.date&&(e=r.dateFormatter.getValidatedDate(e)),r.time&&(e=r.timeFormatter.getValidatedTime(e)),e=n.stripDelimiters(e,r.delimiter,r.delimiters),e=n.getPrefixStrippedValue(e,r.prefix,r.prefixLength,r.result,r.delimiter,r.delimiters,r.noImmediatePrefix,r.tailPrefix,r.signBeforePrefix),e=r.numericOnly?n.strip(e,/[^\d]/g):e,e=r.uppercase?e.toUpperCase():e,e=r.lowercase?e.toLowerCase():e,!r.prefix||r.noImmediatePrefix&&!e.length||(r.tailPrefix?e+=r.prefix:e!==r.prefix&&(e=r.prefix+e),0!==r.blocksLength)?(r.creditCard&&t.updateCreditCardPropsByValue(e),e=n.headStr(e,r.maxLength),r.result=n.getFormattedValue(e,r.blocks,r.blocksLength,r.delimiter,r.delimiters,r.delimiterLazyShow),void t.updateValueState()):(r.result=e,void t.updateValueState()))},updateCreditCardPropsByValue:function(e){var t,r=this,n=r.properties,a=i.Util;a.headStr(n.result,4)!==a.headStr(e,4)&&(t=i.CreditCardDetector.getInfo(e,n.creditCardStrictMode),n.blocks=t.blocks,n.blocksLength=n.blocks.length,n.maxLength=a.getMaxLength(n.blocks),n.creditCardType!==t.type&&(n.creditCardType=t.type,n.onCreditCardTypeChanged.call(r,n.creditCardType)))},updateValueState:function(){var e=this,t=i.Util,r=e.properties;if(e.element){var n=e.element.selectionEnd,a=e.element.value,o=r.result;if(n=t.getNextCursorPosition(n,a,o,r.delimiter,r.delimiters),e.isAndroid)return void window.setTimeout(function(){e.element.value=o,t.setSelection(e.element,n,r.document,!1),e.callOnValueChanged()},1);e.element.value=o,r.swapHiddenInput&&(e.elementSwapHidden.value=e.getRawValue()),t.setSelection(e.element,n,r.document,!1),e.callOnValueChanged()}},callOnValueChanged:function(){var e=this,t=e.properties;t.onValueChanged.call(e,{target:{name:e.element.name,value:t.result,rawValue:e.getRawValue()}})},setPhoneRegionCode:function(e){var t=this,r=t.properties;r.phoneRegionCode=e,t.initPhoneFormatter(),t.onChange()},setRawValue:function(e){var t=this,r=t.properties;e=void 0!==e&&null!==e?e.toString():"",r.numeral&&(e=e.replace(".",r.numeralDecimalMark)),r.postDelimiterBackspace=!1,t.element.value=e,t.onInput(e)},getRawValue:function(){var e=this,t=e.properties,r=i.Util,n=e.element.value;return t.rawValueTrimPrefix&&(n=r.getPrefixStrippedValue(n,t.prefix,t.prefixLength,t.result,t.delimiter,t.delimiters,t.noImmediatePrefix,t.tailPrefix,t.signBeforePrefix)),n=t.numeral?t.numeralFormatter.getRawValue(n):r.stripDelimiters(n,t.delimiter,t.delimiters)},getISOFormatDate:function(){var e=this,t=e.properties;return t.date?t.dateFormatter.getISOFormatDate():""},getISOFormatTime:function(){var e=this,t=e.properties;return t.time?t.timeFormatter.getISOFormatTime():""},getFormattedValue:function(){return this.element.value},destroy:function(){var e=this;e.element.removeEventListener("input",e.onChangeListener),e.element.removeEventListener("keydown",e.onKeyDownListener),e.element.removeEventListener("focus",e.onFocusListener),e.element.removeEventListener("cut",e.onCutListener),e.element.removeEventListener("copy",e.onCopyListener)},toString:function(){return"[Cleave Object]"}},i.NumeralFormatter=r(1),i.DateFormatter=r(2),i.TimeFormatter=r(3),i.PhoneFormatter=r(4),i.CreditCardDetector=r(5),i.Util=r(6),i.DefaultProperties=r(7),("object"==typeof t&&t?t:window).Cleave=i,e.exports=i}).call(t,function(){return this}())},function(e,t){"use strict";var r=function(e,t,i,n,a,o,l,s,c,u){var d=this;d.numeralDecimalMark=e||".",d.numeralIntegerScale=t>0?t:0,d.numeralDecimalScale=i>=0?i:2,d.numeralThousandsGroupStyle=n||r.groupStyle.thousand,d.numeralPositiveOnly=!!a,d.stripLeadingZeroes=o!==!1,d.prefix=l||""===l?l:"",d.signBeforePrefix=!!s,d.tailPrefix=!!c,d.delimiter=u||""===u?u:",",d.delimiterRE=u?new RegExp("\\"+u,"g"):""};r.groupStyle={thousand:"thousand",lakh:"lakh",wan:"wan",none:"none"},r.prototype={getRawValue:function(e){return e.replace(this.delimiterRE,"").replace(this.numeralDecimalMark,".")},format:function(e){var t,i,n,a,o=this,l="";switch(e=e.replace(/[A-Za-z]/g,"").replace(o.numeralDecimalMark,"M").replace(/[^\dM-]/g,"").replace(/^\-/,"N").replace(/\-/g,"").replace("N",o.numeralPositiveOnly?"":"-").replace("M",o.numeralDecimalMark),o.stripLeadingZeroes&&(e=e.replace(/^(-)?0+(?=\d)/,"$1")),i="-"===e.slice(0,1)?"-":"",n="undefined"!=typeof o.prefix?o.signBeforePrefix?i+o.prefix:o.prefix+i:i,a=e,e.indexOf(o.numeralDecimalMark)>=0&&(t=e.split(o.numeralDecimalMark),a=t[0],l=o.numeralDecimalMark+t[1].slice(0,o.numeralDecimalScale)),"-"===i&&(a=a.slice(1)),o.numeralIntegerScale>0&&(a=a.slice(0,o.numeralIntegerScale)),o.numeralThousandsGroupStyle){case r.groupStyle.lakh:a=a.replace(/(\d)(?=(\d\d)+\d$)/g,"$1"+o.delimiter);break;case r.groupStyle.wan:a=a.replace(/(\d)(?=(\d{4})+$)/g,"$1"+o.delimiter);break;case r.groupStyle.thousand:a=a.replace(/(\d)(?=(\d{3})+$)/g,"$1"+o.delimiter)}return o.tailPrefix?i+a.toString()+(o.numeralDecimalScale>0?l.toString():"")+o.prefix:n+a.toString()+(o.numeralDecimalScale>0?l.toString():"")}},e.exports=r},function(e,t){"use strict";var r=function(e,t,r){var i=this;i.date=[],i.blocks=[],i.datePattern=e,i.dateMin=t.split("-").reverse().map(function(e){return parseInt(e,10)}),2===i.dateMin.length&&i.dateMin.unshift(0),i.dateMax=r.split("-").reverse().map(function(e){return parseInt(e,10)}),2===i.dateMax.length&&i.dateMax.unshift(0),i.initBlocks()};r.prototype={initBlocks:function(){var e=this;e.datePattern.forEach(function(t){"Y"===t?e.blocks.push(4):e.blocks.push(2)})},getISOFormatDate:function(){var e=this,t=e.date;return t[2]?t[2]+"-"+e.addLeadingZero(t[1])+"-"+e.addLeadingZero(t[0]):""},getBlocks:function(){return this.blocks},getValidatedDate:function(e){var t=this,r="";return e=e.replace(/[^\d]/g,""),t.blocks.forEach(function(i,n){if(e.length>0){var a=e.slice(0,i),o=a.slice(0,1),l=e.slice(i);switch(t.datePattern[n]){case"d":"00"===a?a="01":parseInt(o,10)>3?a="0"+o:parseInt(a,10)>31&&(a="31");break;case"m":"00"===a?a="01":parseInt(o,10)>1?a="0"+o:parseInt(a,10)>12&&(a="12")}r+=a,e=l}}),this.getFixedDateString(r)},getFixedDateString:function(e){var t,r,i,n=this,a=n.datePattern,o=[],l=0,s=0,c=0,u=0,d=0,m=0,p=!1;4===e.length&&"y"!==a[0].toLowerCase()&&"y"!==a[1].toLowerCase()&&(u="d"===a[0]?0:2,d=2-u,t=parseInt(e.slice(u,u+2),10),r=parseInt(e.slice(d,d+2),10),o=this.getFixedDate(t,r,0)),8===e.length&&(a.forEach(function(e,t){switch(e){case"d":l=t;break;case"m":s=t;break;default:c=t}}),m=2*c,u=l<=c?2*l:2*l+2,d=s<=c?2*s:2*s+2,t=parseInt(e.slice(u,u+2),10),r=parseInt(e.slice(d,d+2),10),i=parseInt(e.slice(m,m+4),10),p=4===e.slice(m,m+4).length,o=this.getFixedDate(t,r,i)),4!==e.length||"y"!==a[0]&&"y"!==a[1]||(d="m"===a[0]?0:2,m=2-d,r=parseInt(e.slice(d,d+2),10),i=parseInt(e.slice(m,m+2),10),p=2===e.slice(m,m+2).length,o=[0,r,i]),6!==e.length||"Y"!==a[0]&&"Y"!==a[1]||(d="m"===a[0]?0:4,m=2-.5*d,r=parseInt(e.slice(d,d+2),10),i=parseInt(e.slice(m,m+4),10),p=4===e.slice(m,m+4).length,o=[0,r,i]),o=n.getRangeFixedDate(o),n.date=o;var h=0===o.length?e:a.reduce(function(e,t){switch(t){case"d":return e+(0===o[0]?"":n.addLeadingZero(o[0]));case"m":return e+(0===o[1]?"":n.addLeadingZero(o[1]));case"y":return e+(p?n.addLeadingZeroForYear(o[2],!1):"");case"Y":return e+(p?n.addLeadingZeroForYear(o[2],!0):"")}},"");return h},getRangeFixedDate:function(e){var t=this,r=t.datePattern,i=t.dateMin||[],n=t.dateMax||[];return!e.length||i.length<3&&n.length<3?e:r.find(function(e){return"y"===e.toLowerCase()})&&0===e[2]?e:n.length&&(n[2]e[2]||i[2]===e[2]&&(i[1]>e[1]||i[1]===e[1]&&i[0]>e[0]))?i:e},getFixedDate:function(e,t,r){return e=Math.min(e,31),t=Math.min(t,12),r=parseInt(r||0,10),(t<7&&t%2===0||t>8&&t%2===1)&&(e=Math.min(e,2===t?this.isLeapYear(r)?29:28:30)),[e,t,r]},isLeapYear:function(e){return e%4===0&&e%100!==0||e%400===0},addLeadingZero:function(e){return(e<10?"0":"")+e},addLeadingZeroForYear:function(e,t){return t?(e<10?"000":e<100?"00":e<1e3?"0":"")+e:(e<10?"0":"")+e}},e.exports=r},function(e,t){"use strict";var r=function(e,t){var r=this;r.time=[],r.blocks=[],r.timePattern=e,r.timeFormat=t,r.initBlocks()};r.prototype={initBlocks:function(){var e=this;e.timePattern.forEach(function(){e.blocks.push(2)})},getISOFormatTime:function(){var e=this,t=e.time;return t[2]?e.addLeadingZero(t[0])+":"+e.addLeadingZero(t[1])+":"+e.addLeadingZero(t[2]):""},getBlocks:function(){return this.blocks},getTimeFormatOptions:function(){var e=this;return"12"===String(e.timeFormat)?{maxHourFirstDigit:1,maxHours:12,maxMinutesFirstDigit:5,maxMinutes:60}:{maxHourFirstDigit:2,maxHours:23,maxMinutesFirstDigit:5,maxMinutes:60}},getValidatedTime:function(e){var t=this,r="";e=e.replace(/[^\d]/g,"");var i=t.getTimeFormatOptions();return t.blocks.forEach(function(n,a){if(e.length>0){var o=e.slice(0,n),l=o.slice(0,1),s=e.slice(n);switch(t.timePattern[a]){case"h":parseInt(l,10)>i.maxHourFirstDigit?o="0"+l:parseInt(o,10)>i.maxHours&&(o=i.maxHours+"");break;case"m":case"s":parseInt(l,10)>i.maxMinutesFirstDigit?o="0"+l:parseInt(o,10)>i.maxMinutes&&(o=i.maxMinutes+"")}r+=o,e=s}}),this.getFixedTimeString(r)},getFixedTimeString:function(e){var t,r,i,n=this,a=n.timePattern,o=[],l=0,s=0,c=0,u=0,d=0,m=0;return 6===e.length&&(a.forEach(function(e,t){switch(e){case"s":l=2*t;break;case"m":s=2*t;break;case"h":c=2*t}}),m=c,d=s,u=l,t=parseInt(e.slice(u,u+2),10),r=parseInt(e.slice(d,d+2),10),i=parseInt(e.slice(m,m+2),10),o=this.getFixedTime(i,r,t)),4===e.length&&n.timePattern.indexOf("s")<0&&(a.forEach(function(e,t){switch(e){case"m":s=2*t;break;case"h":c=2*t}}),m=c,d=s,t=0,r=parseInt(e.slice(d,d+2),10),i=parseInt(e.slice(m,m+2),10),o=this.getFixedTime(i,r,t)),n.time=o,0===o.length?e:a.reduce(function(e,t){switch(t){case"s":return e+n.addLeadingZero(o[2]);case"m":return e+n.addLeadingZero(o[1]);case"h":return e+n.addLeadingZero(o[0])}},"")},getFixedTime:function(e,t,r){return r=Math.min(parseInt(r||0,10),60),t=Math.min(t,60),e=Math.min(e,60),[e,t,r]},addLeadingZero:function(e){return(e<10?"0":"")+e}},e.exports=r},function(e,t){"use strict";var r=function(e,t){var r=this;r.delimiter=t||""===t?t:" ",r.delimiterRE=t?new RegExp("\\"+t,"g"):"",r.formatter=e};r.prototype={setFormatter:function(e){this.formatter=e},format:function(e){var t=this;t.formatter.clear(),e=e.replace(/[^\d+]/g,""),e=e.replace(/^\+/,"B").replace(/\+/g,"").replace("B","+"),e=e.replace(t.delimiterRE,"");for(var r,i="",n=!1,a=0,o=e.length;a0;return 0===r?e:(t.forEach(function(t,c){if(e.length>0){var u=e.slice(0,t),d=e.slice(t);o=s?n[a?c-1:c]||o:i,a?(c>0&&(l+=o),l+=u):(l+=u,u.length===t&&c0?r.numeralIntegerScale:0,e.numeralDecimalScale=r.numeralDecimalScale>=0?r.numeralDecimalScale:2,e.numeralDecimalMark=r.numeralDecimalMark||".",e.numeralThousandsGroupStyle=r.numeralThousandsGroupStyle||"thousand",e.numeralPositiveOnly=!!r.numeralPositiveOnly,e.stripLeadingZeroes=r.stripLeadingZeroes!==!1,e.signBeforePrefix=!!r.signBeforePrefix,e.tailPrefix=!!r.tailPrefix,e.swapHiddenInput=!!r.swapHiddenInput,e.numericOnly=e.creditCard||e.date||!!r.numericOnly,e.uppercase=!!r.uppercase,e.lowercase=!!r.lowercase,e.prefix=e.creditCard||e.date?"":r.prefix||"",e.noImmediatePrefix=!!r.noImmediatePrefix,e.prefixLength=e.prefix.length,e.rawValueTrimPrefix=!!r.rawValueTrimPrefix,e.copyDelimiter=!!r.copyDelimiter,e.initValue=void 0!==r.initValue&&null!==r.initValue?r.initValue.toString():"",e.delimiter=r.delimiter||""===r.delimiter?r.delimiter:r.date?"/":r.time?":":r.numeral?",":(r.phone," "),e.delimiterLength=e.delimiter.length,e.delimiterLazyShow=!!r.delimiterLazyShow,e.delimiters=r.delimiters||[],e.blocks=r.blocks||[],e.blocksLength=e.blocks.length,e.root="object"==typeof t&&t?t:window,e.document=r.document||e.root.document,e.maxLength=0,e.backspace=!1,e.result="",e.onValueChanged=r.onValueChanged||function(){},e}};e.exports=r}).call(t,function(){return this}())}])}); \ No newline at end of file diff --git a/src/Cleave.js b/src/Cleave.js index 96f0c0a2..1ec4e564 100644 --- a/src/Cleave.js +++ b/src/Cleave.js @@ -310,7 +310,7 @@ Cleave.prototype = { if (pps.prefix && (!pps.noImmediatePrefix || value.length)) { if (pps.tailPrefix) { value = value + pps.prefix; - } else { + } else if(value !== pps.prefix) { value = pps.prefix + value; } diff --git a/src/Cleave.react.js b/src/Cleave.react.js index 779cd221..effadfc0 100644 --- a/src/Cleave.react.js +++ b/src/Cleave.react.js @@ -363,7 +363,7 @@ var cleaveReactClass = CreateReactClass({ if (pps.prefix && (!pps.noImmediatePrefix || value.length)) { if (pps.tailPrefix) { value = value + pps.prefix; - } else { + } else if (value !== pps.prefix) { value = pps.prefix + value; } diff --git a/test/browser/custom.js b/test/browser/custom.js index c0d9999f..e1bd2c96 100644 --- a/test/browser/custom.js +++ b/test/browser/custom.js @@ -1,6 +1,8 @@ describe('Custom input field', function () { var field = document.querySelector('.input-custom'); + beforeEach(function(){ field.value = ''; }); + it('should use custom blocks', function () { var cleave = new Cleave(field, { blocks: [3, 3, 3] @@ -82,6 +84,16 @@ describe('Custom input field', function () { assert.equal(field.value, 'UFO-123'); }); + it('should use defined prefix with noImmediatePrefix enabled', function() { + var cleave = new Cleave(field, { + prefix: 'GTM-', + noImmediatePrefix: true + }); + + cleave.setRawValue('1001'); + assert.equal(cleave.getFormattedValue(), 'GTM-1001'); + }); + it('should not trim prefix when rawValueTrimPrefix is not enabled', function () { var cleave = new Cleave(field, { prefix: '$',