Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-number-format

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-number-format - npm Package Compare versions

Comparing version 2.0.0-alpha4 to 2.0.0-alpha5

18

dist/react-number-format.js
/*!
* react-number-format - 2.0.0-alpha4
* react-number-format - 2.0.0-alpha5
* Author : Sudhanshu Yadav

@@ -303,3 +303,3 @@ * Copyright (c) 2016,2017 to Sudhanshu Yadav - ignitersworld.com , released under the MIT license.

key: 'setPatchedCaretPosition',
value: function setPatchedCaretPosition(el, caretPos, lastValue) {
value: function setPatchedCaretPosition(el, caretPos, currentValue) {
var _this2 = this;

@@ -314,3 +314,3 @@

setTimeout(function () {
if (el.value === lastValue) _this2.setCaretPosition(el, caretPos);
if (el.value === currentValue) _this2.setCaretPosition(el, caretPos);
}, 0);

@@ -470,5 +470,2 @@ }

//set caret position befor setState
//this.setPatchedCaretPosition(el, cursorPos);
if (!isAllowed(formattedValue, value, this.getFloatValue(value))) {

@@ -480,5 +477,6 @@ formattedValue = lastValue;

el.value = formattedValue;
//reset again after setState so if formattedValue is other then
this.setPatchedCaretPosition(el, cursorPos, lastValue);
//set caret position
this.setPatchedCaretPosition(el, cursorPos, formattedValue);
//change the state

@@ -512,3 +510,3 @@ if (formattedValue !== lastValue) {

nextCursorPosition++;
}this.setPatchedCaretPosition(el, nextCursorPosition);
}this.setPatchedCaretPosition(el, nextCursorPosition, value);
} else if (key === 'Backspace' && !numRegex.test(value[selectionStart - 1]) && !negativeRegex.test(value[selectionStart - 1])) {

@@ -519,3 +517,3 @@ e.preventDefault();

prevCursorPosition--;
}this.setPatchedCaretPosition(el, prevCursorPosition);
}this.setPatchedCaretPosition(el, prevCursorPosition, value);
}

@@ -522,0 +520,0 @@ }

/*!
* react-number-format - 2.0.0-alpha4
* react-number-format - 2.0.0-alpha5
* Author : Sudhanshu Yadav
* Copyright (c) 2016,2017 to Sudhanshu Yadav - ignitersworld.com , released under the MIT license.
*/
!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.NumberFormat=t(require("react")):e.NumberFormat=t(e.React)}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var a=r[n]={exports:{},id:n,loaded:!1};return e[n].call(a.exports,a,a.exports,t),a.loaded=!0,a.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){e.exports=r(1)},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function u(){}function s(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function f(e){return e.replace(/^0+/,"")||"0"}function l(e,t){for(var r="",n=0;n<=t-1;n++)r+=e[n]||"0";return r}function p(e,t){var r={};return Object.keys(e).forEach(function(n){t[n]||(r[n]=e[n])}),r}var c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},d=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),h=r(2),v=n(h),m=r(7),y=n(m),g={thousandSeparator:v.default.oneOfType([v.default.string,v.default.oneOf([!0])]),decimalSeparator:v.default.string,decimalPrecision:v.default.number,displayType:v.default.oneOf(["input","text"]),prefix:v.default.string,suffix:v.default.string,format:v.default.oneOfType([v.default.string,v.default.func]),mask:v.default.string,value:v.default.oneOfType([v.default.number,v.default.string]),customInput:v.default.func,allowNegative:v.default.bool,onKeyDown:v.default.func,onChange:v.default.func,type:v.default.oneOf(["text","tel"]),isAllowed:v.default.func},b={displayType:"input",decimalSeparator:".",allowNegative:!0,type:"text",onChange:u,onKeyDown:u,isAllowed:function(){return!0}},x=function(e){function t(e){a(this,t);var r=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e)),n=r.optimizeValueProp(e);return r.state={value:r.formatInput(n).formattedValue},r.onChange=r.onChange.bind(r),r.onKeyDown=r.onKeyDown.bind(r),r}return i(t,e),d(t,[{key:"componentDidUpdate",value:function(e,t){this.updateValueIfRequired(e,t)}},{key:"updateValueIfRequired",value:function(e){var t=this.props,r=this.state;if(e!==t){var n=r.value,a=this.optimizeValueProp(t);void 0===a&&(a=n);var o=this.formatInput(a),i=o.formattedValue;i!==n&&this.setState({value:i})}}},{key:"getFloatValue",value:function(e){var t=this.props.decimalSeparator;return parseFloat(e.replace(t,"."))||0}},{key:"optimizeValueProp",value:function(e){var t=this.getSeparators(e),r=t.decimalSeparator,n=e.decimalPrecision,a=e.format,o=e.value;if(a||void 0===o)return o;var i="number"==typeof o;return i&&(o=o.toString()),r&&i&&(o=o.replace(".",r)),0===n?o.split(r)[0]:o}},{key:"getSeparators",value:function(e){e=e||this.props;var t=e,r=t.decimalSeparator,n=e,a=n.thousandSeparator;if(a===!0&&(a=","),r===a)throw new Error("\n Decimal separator can't be same as thousand separator.\n\n thousandSeparator: "+a+' (thousandSeparator = {true} is same as thousandSeparator = ",")\n decimalSeparator: '+r+" (default value for decimalSeparator is .)\n ");return{decimalSeparator:r,thousandSeparator:a}}},{key:"getNumberRegex",value:function(e,t){var r=this.props,n=r.format,a=r.decimalPrecision,o=this.getSeparators(),i=o.decimalSeparator;return new RegExp("\\d"+(!i||0===a||t||n?"":"|"+s(i)),e?"g":void 0)}},{key:"setCaretPosition",value:function(e,t){if(e.value=e.value,null!==e){if(e.createTextRange){var r=e.createTextRange();return r.move("character",t),r.select(),!0}return e.selectionStart||0===e.selectionStart?(e.focus(),e.setSelectionRange(t,t),!0):(e.focus(),!1)}}},{key:"setPatchedCaretPosition",value:function(e,t,r){var n=this;this.setCaretPosition(e,t),setTimeout(function(){e.value===r&&n.setCaretPosition(e,t)},0)}},{key:"formatWithPattern",value:function(e){var t=this.props,r=t.format,n=t.mask;if(!r)return e;for(var a=r.split("#").length-1,o=0,i=r,u=0,s=e.length;u<s;u++)u<a&&(o=i.indexOf("#"),i=i.replace("#",e[u]));var f=i.lastIndexOf("#");return n?i.replace(/#/g,n):i.substring(0,o+1)+(f!==-1?i.substring(f+1,i.length):"")}},{key:"formatInput",value:function(e){var t=this.props,r=t.prefix,n=t.suffix,a=(t.mask,t.format),o=t.allowNegative,i=t.decimalPrecision,u=this.getSeparators(),s=u.thousandSeparator,p=u.decimalSeparator,c=this.getNumberRegex(!0),d=void 0,h=void 0;"number"==typeof e&&(e+="");var v=new RegExp("(-)"),m=new RegExp("(-)(.)*(-)");o&&!a&&(d=v.test(e),h=m.test(e));var y=e&&e.match(c);if(!y&&h)return{value:"",formattedValue:""};if(!y&&d)return{value:"",formattedValue:"-"};if(!y)return{value:"",formattedValue:""};var g=e.match(c).join(""),b=g;if(a)"string"==typeof a?b=this.formatWithPattern(b):"function"==typeof a&&(b=a(b));else{var x=b.indexOf(p)!==-1||i,P=b.split(p),S=P[0],w=P[1]||"";S=f(S),void 0!==i&&(w=l(w,i)),s&&(S=S.replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+s)),r&&(S=r+S),n&&(w+=n),d&&!h&&(S="-"+S),b=S+(x&&p||"")+w}return{value:(d&&!h?"-":"")+b.match(c).join(""),formattedValue:b}}},{key:"getCursorPosition",value:function(e,t,r){var n=this.getNumberRegex(),a=void 0,o=void 0;for(a=0,o=0;o<r;o++)if((e[o].match(n)||e[o]===t[a])&&("0"!==e[o]||!(t[a]||"").match(n)||"0"===t[a])){for(;e[o]!==t[a]&&a<t.length;)a++;a++}return a}},{key:"onChange",value:function(e){e.persist();var t=e.target,r=t.value,n=this.state,a=this.props,o=a.isAllowed,i=n.value,u=this.formatInput(r),s=u.formattedValue,f=u.value,l=Math.max(t.selectionStart,t.selectionEnd),p=this.getCursorPosition(r,s,l);return o(s,f,this.getFloatValue(f))||(s=i),t.value=s,this.setPatchedCaretPosition(t,p,i),s!==i&&this.setState({value:s},function(){a.onChange(e,f)}),f}},{key:"onKeyDown",value:function(e){var t=e.target,r=t.selectionStart,n=t.selectionEnd,a=t.value,o=this.props.decimalPrecision,i=e.key,u=this.getNumberRegex(!1,void 0!==o),s=new RegExp("-");if(n-r===0)if("Delete"!==i||u.test(a[r])||s.test(a[r])){if("Backspace"===i&&!u.test(a[r-1])&&!s.test(a[r-1])){e.preventDefault();for(var f=r;!u.test(a[f-1])&&f>0;)f--;this.setPatchedCaretPosition(t,f)}}else{e.preventDefault();for(var l=r;!u.test(a[l])&&l<a.length;)l++;this.setPatchedCaretPosition(t,l)}this.props.onKeyDown(e)}},{key:"render",value:function(){var e=p(this.props,g),t=c({},e,{type:this.props.type,value:this.state.value,onChange:this.onChange,onKeyDown:this.onKeyDown});if("text"===this.props.displayType)return y.default.createElement("span",e,this.state.value);if(this.props.customInput){var r=this.props.customInput;return y.default.createElement(r,t)}return y.default.createElement("input",t)}}]),t}(y.default.Component);x.propTypes=g,x.defaultProps=b,e.exports=x},function(e,t,r){e.exports=r(3)()},function(e,t,r){"use strict";var n=r(4),a=r(5),o=r(6);e.exports=function(){function e(e,t,r,n,i,u){u!==o&&a(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function t(){return e}e.isRequired=e;var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t};return r.checkPropTypes=n,r.PropTypes=r,r}},function(e,t){"use strict";function r(e){return function(){return e}}var n=function(){};n.thatReturns=r,n.thatReturnsFalse=r(!1),n.thatReturnsTrue=r(!0),n.thatReturnsNull=r(null),n.thatReturnsThis=function(){return this},n.thatReturnsArgument=function(e){return e},e.exports=n},function(e,t,r){"use strict";function n(e,t,r,n,o,i,u,s){if(a(t),!e){var f;if(void 0===t)f=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var l=[r,n,o,i,u,s],p=0;f=new Error(t.replace(/%s/g,function(){return l[p++]})),f.name="Invariant Violation"}throw f.framesToPop=1,f}}var a=function(e){};e.exports=n},function(e,t){"use strict";var r="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";e.exports=r},function(t,r){t.exports=e}])});
!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.NumberFormat=t(require("react")):e.NumberFormat=t(e.React)}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var a=r[n]={exports:{},id:n,loaded:!1};return e[n].call(a.exports,a,a.exports,t),a.loaded=!0,a.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){e.exports=r(1)},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function u(){}function s(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function f(e){return e.replace(/^0+/,"")||"0"}function l(e,t){for(var r="",n=0;n<=t-1;n++)r+=e[n]||"0";return r}function p(e,t){var r={};return Object.keys(e).forEach(function(n){t[n]||(r[n]=e[n])}),r}var c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},d=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),h=r(2),v=n(h),m=r(7),y=n(m),g={thousandSeparator:v.default.oneOfType([v.default.string,v.default.oneOf([!0])]),decimalSeparator:v.default.string,decimalPrecision:v.default.number,displayType:v.default.oneOf(["input","text"]),prefix:v.default.string,suffix:v.default.string,format:v.default.oneOfType([v.default.string,v.default.func]),mask:v.default.string,value:v.default.oneOfType([v.default.number,v.default.string]),customInput:v.default.func,allowNegative:v.default.bool,onKeyDown:v.default.func,onChange:v.default.func,type:v.default.oneOf(["text","tel"]),isAllowed:v.default.func},b={displayType:"input",decimalSeparator:".",allowNegative:!0,type:"text",onChange:u,onKeyDown:u,isAllowed:function(){return!0}},x=function(e){function t(e){a(this,t);var r=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e)),n=r.optimizeValueProp(e);return r.state={value:r.formatInput(n).formattedValue},r.onChange=r.onChange.bind(r),r.onKeyDown=r.onKeyDown.bind(r),r}return i(t,e),d(t,[{key:"componentDidUpdate",value:function(e,t){this.updateValueIfRequired(e,t)}},{key:"updateValueIfRequired",value:function(e){var t=this.props,r=this.state;if(e!==t){var n=r.value,a=this.optimizeValueProp(t);void 0===a&&(a=n);var o=this.formatInput(a),i=o.formattedValue;i!==n&&this.setState({value:i})}}},{key:"getFloatValue",value:function(e){var t=this.props.decimalSeparator;return parseFloat(e.replace(t,"."))||0}},{key:"optimizeValueProp",value:function(e){var t=this.getSeparators(e),r=t.decimalSeparator,n=e.decimalPrecision,a=e.format,o=e.value;if(a||void 0===o)return o;var i="number"==typeof o;return i&&(o=o.toString()),r&&i&&(o=o.replace(".",r)),0===n?o.split(r)[0]:o}},{key:"getSeparators",value:function(e){e=e||this.props;var t=e,r=t.decimalSeparator,n=e,a=n.thousandSeparator;if(a===!0&&(a=","),r===a)throw new Error("\n Decimal separator can't be same as thousand separator.\n\n thousandSeparator: "+a+' (thousandSeparator = {true} is same as thousandSeparator = ",")\n decimalSeparator: '+r+" (default value for decimalSeparator is .)\n ");return{decimalSeparator:r,thousandSeparator:a}}},{key:"getNumberRegex",value:function(e,t){var r=this.props,n=r.format,a=r.decimalPrecision,o=this.getSeparators(),i=o.decimalSeparator;return new RegExp("\\d"+(!i||0===a||t||n?"":"|"+s(i)),e?"g":void 0)}},{key:"setCaretPosition",value:function(e,t){if(e.value=e.value,null!==e){if(e.createTextRange){var r=e.createTextRange();return r.move("character",t),r.select(),!0}return e.selectionStart||0===e.selectionStart?(e.focus(),e.setSelectionRange(t,t),!0):(e.focus(),!1)}}},{key:"setPatchedCaretPosition",value:function(e,t,r){var n=this;this.setCaretPosition(e,t),setTimeout(function(){e.value===r&&n.setCaretPosition(e,t)},0)}},{key:"formatWithPattern",value:function(e){var t=this.props,r=t.format,n=t.mask;if(!r)return e;for(var a=r.split("#").length-1,o=0,i=r,u=0,s=e.length;u<s;u++)u<a&&(o=i.indexOf("#"),i=i.replace("#",e[u]));var f=i.lastIndexOf("#");return n?i.replace(/#/g,n):i.substring(0,o+1)+(f!==-1?i.substring(f+1,i.length):"")}},{key:"formatInput",value:function(e){var t=this.props,r=t.prefix,n=t.suffix,a=(t.mask,t.format),o=t.allowNegative,i=t.decimalPrecision,u=this.getSeparators(),s=u.thousandSeparator,p=u.decimalSeparator,c=this.getNumberRegex(!0),d=void 0,h=void 0;"number"==typeof e&&(e+="");var v=new RegExp("(-)"),m=new RegExp("(-)(.)*(-)");o&&!a&&(d=v.test(e),h=m.test(e));var y=e&&e.match(c);if(!y&&h)return{value:"",formattedValue:""};if(!y&&d)return{value:"",formattedValue:"-"};if(!y)return{value:"",formattedValue:""};var g=e.match(c).join(""),b=g;if(a)"string"==typeof a?b=this.formatWithPattern(b):"function"==typeof a&&(b=a(b));else{var x=b.indexOf(p)!==-1||i,P=b.split(p),S=P[0],w=P[1]||"";S=f(S),void 0!==i&&(w=l(w,i)),s&&(S=S.replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+s)),r&&(S=r+S),n&&(w+=n),d&&!h&&(S="-"+S),b=S+(x&&p||"")+w}return{value:(d&&!h?"-":"")+b.match(c).join(""),formattedValue:b}}},{key:"getCursorPosition",value:function(e,t,r){var n=this.getNumberRegex(),a=void 0,o=void 0;for(a=0,o=0;o<r;o++)if((e[o].match(n)||e[o]===t[a])&&("0"!==e[o]||!(t[a]||"").match(n)||"0"===t[a])){for(;e[o]!==t[a]&&a<t.length;)a++;a++}return a}},{key:"onChange",value:function(e){e.persist();var t=e.target,r=t.value,n=this.state,a=this.props,o=a.isAllowed,i=n.value,u=this.formatInput(r),s=u.formattedValue,f=u.value,l=Math.max(t.selectionStart,t.selectionEnd),p=this.getCursorPosition(r,s,l);return o(s,f,this.getFloatValue(f))||(s=i),t.value=s,this.setPatchedCaretPosition(t,p,s),s!==i&&this.setState({value:s},function(){a.onChange(e,f)}),f}},{key:"onKeyDown",value:function(e){var t=e.target,r=t.selectionStart,n=t.selectionEnd,a=t.value,o=this.props.decimalPrecision,i=e.key,u=this.getNumberRegex(!1,void 0!==o),s=new RegExp("-");if(n-r===0)if("Delete"!==i||u.test(a[r])||s.test(a[r])){if("Backspace"===i&&!u.test(a[r-1])&&!s.test(a[r-1])){e.preventDefault();for(var f=r;!u.test(a[f-1])&&f>0;)f--;this.setPatchedCaretPosition(t,f,a)}}else{e.preventDefault();for(var l=r;!u.test(a[l])&&l<a.length;)l++;this.setPatchedCaretPosition(t,l,a)}this.props.onKeyDown(e)}},{key:"render",value:function(){var e=p(this.props,g),t=c({},e,{type:this.props.type,value:this.state.value,onChange:this.onChange,onKeyDown:this.onKeyDown});if("text"===this.props.displayType)return y.default.createElement("span",e,this.state.value);if(this.props.customInput){var r=this.props.customInput;return y.default.createElement(r,t)}return y.default.createElement("input",t)}}]),t}(y.default.Component);x.propTypes=g,x.defaultProps=b,e.exports=x},function(e,t,r){e.exports=r(3)()},function(e,t,r){"use strict";var n=r(4),a=r(5),o=r(6);e.exports=function(){function e(e,t,r,n,i,u){u!==o&&a(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function t(){return e}e.isRequired=e;var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t};return r.checkPropTypes=n,r.PropTypes=r,r}},function(e,t){"use strict";function r(e){return function(){return e}}var n=function(){};n.thatReturns=r,n.thatReturnsFalse=r(!1),n.thatReturnsTrue=r(!0),n.thatReturnsNull=r(null),n.thatReturnsThis=function(){return this},n.thatReturnsArgument=function(e){return e},e.exports=n},function(e,t,r){"use strict";function n(e,t,r,n,o,i,u,s){if(a(t),!e){var f;if(void 0===t)f=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var l=[r,n,o,i,u,s],p=0;f=new Error(t.replace(/%s/g,function(){return l[p++]})),f.name="Invariant Violation"}throw f.framesToPop=1,f}}var a=function(e){};e.exports=n},function(e,t){"use strict";var r="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";e.exports=r},function(t,r){t.exports=e}])});

@@ -235,3 +235,3 @@ 'use strict';

key: 'setPatchedCaretPosition',
value: function setPatchedCaretPosition(el, caretPos, lastValue) {
value: function setPatchedCaretPosition(el, caretPos, currentValue) {
var _this2 = this;

@@ -246,3 +246,3 @@

setTimeout(function () {
if (el.value === lastValue) _this2.setCaretPosition(el, caretPos);
if (el.value === currentValue) _this2.setCaretPosition(el, caretPos);
}, 0);

@@ -402,5 +402,2 @@ }

//set caret position befor setState
//this.setPatchedCaretPosition(el, cursorPos);
if (!isAllowed(formattedValue, value, this.getFloatValue(value))) {

@@ -412,5 +409,6 @@ formattedValue = lastValue;

el.value = formattedValue;
//reset again after setState so if formattedValue is other then
this.setPatchedCaretPosition(el, cursorPos, lastValue);
//set caret position
this.setPatchedCaretPosition(el, cursorPos, formattedValue);
//change the state

@@ -444,3 +442,3 @@ if (formattedValue !== lastValue) {

nextCursorPosition++;
}this.setPatchedCaretPosition(el, nextCursorPosition);
}this.setPatchedCaretPosition(el, nextCursorPosition, value);
} else if (key === 'Backspace' && !numRegex.test(value[selectionStart - 1]) && !negativeRegex.test(value[selectionStart - 1])) {

@@ -451,3 +449,3 @@ e.preventDefault();

prevCursorPosition--;
}this.setPatchedCaretPosition(el, prevCursorPosition);
}this.setPatchedCaretPosition(el, prevCursorPosition, value);
}

@@ -454,0 +452,0 @@ }

{
"name": "react-number-format",
"description": "React component to format number in an input or as a text.",
"version": "2.0.0-alpha4",
"version": "2.0.0-alpha5",
"main": "lib/number_format.js",

@@ -6,0 +6,0 @@ "author": "Sudhanshu Yadav",

@@ -195,3 +195,3 @@ /**

setPatchedCaretPosition(el, caretPos, lastValue) {
setPatchedCaretPosition(el, caretPos, currentValue) {
/*

@@ -204,3 +204,3 @@ setting caret position within timeout of 0ms is required for mobile chrome,

setTimeout(() => {
if(el.value === lastValue) this.setCaretPosition(el, caretPos);
if(el.value === currentValue) this.setCaretPosition(el, caretPos);
}, 0);

@@ -335,5 +335,2 @@ }

//set caret position befor setState
//this.setPatchedCaretPosition(el, cursorPos);
if (!isAllowed(formattedValue, value, this.getFloatValue(value))) {

@@ -345,5 +342,5 @@ formattedValue = lastValue;

el.value = formattedValue;
//reset again after setState so if formattedValue is other then
this.setPatchedCaretPosition(el, cursorPos, lastValue);
//set caret position
this.setPatchedCaretPosition(el, cursorPos, formattedValue);

@@ -373,3 +370,3 @@ //change the state

while (!numRegex.test(value[nextCursorPosition]) && nextCursorPosition < value.length) nextCursorPosition++;
this.setPatchedCaretPosition(el, nextCursorPosition);
this.setPatchedCaretPosition(el, nextCursorPosition, value);
} else if (key === 'Backspace' && !numRegex.test(value[selectionStart - 1]) && !negativeRegex.test(value[selectionStart-1])) {

@@ -379,3 +376,3 @@ e.preventDefault();

while (!numRegex.test(value[prevCursorPosition - 1]) && prevCursorPosition > 0) prevCursorPosition--;
this.setPatchedCaretPosition(el, prevCursorPosition);
this.setPatchedCaretPosition(el, prevCursorPosition, value);
}

@@ -382,0 +379,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc