react-input-mask
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -43,4 +43,5 @@ "use strict"; | ||
getFilledLength: function getFilledLength() { | ||
var value = arguments[0] === undefined ? this.state.value : arguments[0]; | ||
var i; | ||
var value = this.state.value; | ||
var maskChar = this.state.maskChar; | ||
@@ -155,3 +156,7 @@ | ||
if (i < value.length) { | ||
value = this.replaceSubstr(value, char, i); | ||
if (maskChar) { | ||
value = this.replaceSubstr(value, char, i); | ||
} else { | ||
value = this.formatValue(value.substr(0, i) + char + value.substr(i), newState); | ||
} | ||
} else if (!maskChar) { | ||
@@ -171,2 +176,21 @@ value += char; | ||
}, | ||
getRawSubstrLength: function getRawSubstrLength(value, substr, pos, newState) { | ||
var _ref3 = newState || this.state; | ||
var mask = _ref3.mask; | ||
var maskChar = _ref3.maskChar; | ||
substr = substr.split(""); | ||
for (var i = pos; i < mask.length && substr.length;) { | ||
if (!this.isPermanentChar(i, newState) || mask[i] === substr[0]) { | ||
var char = substr.shift(); | ||
if (this.isAllowedChar(char, i, newState)) { | ||
++i; | ||
} | ||
} else { | ||
++i; | ||
} | ||
} | ||
return i - pos; | ||
}, | ||
isAllowedChar: function isAllowedChar(char, pos, newState) { | ||
@@ -510,3 +534,6 @@ var mask = newState ? newState.mask : this.state.mask; | ||
var caretPos = this.getCaretPos(); | ||
var textLen = this.getRawSubstrLength(this.state.value, text, caretPos); | ||
var value = this.insertRawSubstr(this.state.value, text, caretPos); | ||
caretPos += textLen; | ||
caretPos = this.getRightEditablePos(caretPos) || caretPos; | ||
if (value !== this.state.value) { | ||
@@ -521,3 +548,3 @@ event.target.value = value; | ||
} | ||
this.setCaretPos(i); | ||
this.setCaretPos(caretPos); | ||
} | ||
@@ -524,0 +551,0 @@ event.preventDefault(); |
@@ -37,5 +37,4 @@ // https://github.com/sanniassin/react-input-mask | ||
}, | ||
getFilledLength: function() { | ||
getFilledLength: function(value = this.state.value) { | ||
var i; | ||
var value = this.state.value; | ||
var maskChar = this.state.maskChar; | ||
@@ -142,3 +141,8 @@ | ||
if (i < value.length) { | ||
value = this.replaceSubstr(value, char, i); | ||
if (maskChar) { | ||
value = this.replaceSubstr(value, char, i); | ||
} | ||
else { | ||
value = this.formatValue(value.substr(0, i) + char + value.substr(i), newState); | ||
} | ||
} | ||
@@ -160,2 +164,18 @@ else if (!maskChar) { | ||
}, | ||
getRawSubstrLength: function(value, substr, pos, newState) { | ||
var { mask, maskChar } = newState || this.state; | ||
substr = substr.split(""); | ||
for (var i = pos; i < mask.length && substr.length; ) { | ||
if (!this.isPermanentChar(i, newState) || mask[i] === substr[0]) { | ||
var char = substr.shift(); | ||
if (this.isAllowedChar(char, i, newState)) { | ||
++i; | ||
} | ||
} | ||
else { | ||
++i; | ||
} | ||
} | ||
return i - pos; | ||
}, | ||
isAllowedChar: function(char, pos, newState) { | ||
@@ -509,3 +529,6 @@ var mask = newState ? newState.mask : this.state.mask; | ||
var caretPos = this.getCaretPos(); | ||
var textLen = this.getRawSubstrLength(this.state.value, text, caretPos); | ||
var value = this.insertRawSubstr(this.state.value, text, caretPos); | ||
caretPos += textLen; | ||
caretPos = this.getRightEditablePos(caretPos) || caretPos; | ||
if (value !== this.state.value) { | ||
@@ -520,3 +543,3 @@ event.target.value = value; | ||
} | ||
this.setCaretPos(i); | ||
this.setCaretPos(caretPos); | ||
} | ||
@@ -523,0 +546,0 @@ event.preventDefault(); |
{ | ||
"name": "react-input-mask", | ||
"description": "Masked input component for React", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"homepage": "https://github.com/sanniassin/react-input-mask", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39528
1040