react-number-format
Advanced tools
Comparing version 2.0.0-alpha to 2.0.0-alpha2
/*! | ||
* react-number-format - 2.0.0-alpha | ||
* react-number-format - 2.0.0-alpha2 | ||
* Author : Sudhanshu Yadav | ||
@@ -204,5 +204,5 @@ * Copyright (c) 2016,2017 to Sudhanshu Yadav - ignitersworld.com , released under the MIT license. | ||
var value = props.value, | ||
decimalPrecision = props.decimalPrecision, | ||
var decimalPrecision = props.decimalPrecision, | ||
format = props.format; | ||
var value = props.value; | ||
@@ -229,7 +229,10 @@ | ||
value: function getSeparators(props) { | ||
var _ref = props || this.props, | ||
thousandSeparator = _ref.thousandSeparator, | ||
decimalSeparator = _ref.decimalSeparator, | ||
decimalPrecision = _ref.decimalPrecision; | ||
props = props || this.props; | ||
var _props = props, | ||
decimalSeparator = _props.decimalSeparator; | ||
var _props2 = props, | ||
thousandSeparator = _props2.thousandSeparator; | ||
if (thousandSeparator === true) { | ||
@@ -251,5 +254,5 @@ thousandSeparator = ','; | ||
value: function getNumberRegex(g, ignoreDecimalSeparator) { | ||
var _props = this.props, | ||
format = _props.format, | ||
decimalPrecision = _props.decimalPrecision; | ||
var _props3 = this.props, | ||
format = _props3.format, | ||
decimalPrecision = _props3.decimalPrecision; | ||
@@ -305,5 +308,5 @@ var _getSeparators2 = this.getSeparators(), | ||
value: function formatWithPattern(str) { | ||
var _props2 = this.props, | ||
format = _props2.format, | ||
mask = _props2.mask; | ||
var _props4 = this.props, | ||
format = _props4.format, | ||
mask = _props4.mask; | ||
@@ -332,9 +335,9 @@ if (!format) return str; | ||
value: function formatInput(val) { | ||
var _props3 = this.props, | ||
prefix = _props3.prefix, | ||
suffix = _props3.suffix, | ||
mask = _props3.mask, | ||
format = _props3.format, | ||
allowNegative = _props3.allowNegative, | ||
decimalPrecision = _props3.decimalPrecision; | ||
var _props5 = this.props, | ||
prefix = _props5.prefix, | ||
suffix = _props5.suffix, | ||
mask = _props5.mask, | ||
format = _props5.format, | ||
allowNegative = _props5.allowNegative, | ||
decimalPrecision = _props5.decimalPrecision; | ||
@@ -482,15 +485,9 @@ var _getSeparators3 = this.getSeparators(), | ||
var decimalPrecision = this.props.decimalPrecision; | ||
var key = e.key, | ||
which = e.which, | ||
keyCode = e.keyCode; | ||
var key = e.key; | ||
var numRegex = this.getNumberRegex(false, decimalPrecision !== undefined); | ||
console.log(numRegex.toString(), key, which, keyCode); | ||
console.log(e); | ||
var negativeRegex = new RegExp('-'); | ||
//Handle backspace and delete against non numerical/decimal characters | ||
if (selectionEnd - selectionStart === 0) { | ||
console.log('coming here'); | ||
if (key === 'Delete' && !numRegex.test(value[selectionStart]) && !negativeRegex.test(value[selectionStart])) { | ||
console.log('delete'); | ||
e.preventDefault(); | ||
@@ -502,3 +499,2 @@ var nextCursorPosition = selectionStart; | ||
} else if (key === 'Backspace' && !numRegex.test(value[selectionStart - 1]) && !negativeRegex.test(value[selectionStart - 1])) { | ||
console.log('Backspace'); | ||
e.preventDefault(); | ||
@@ -505,0 +501,0 @@ var prevCursorPosition = selectionStart; |
/*! | ||
* react-number-format - 2.0.0-alpha | ||
* react-number-format - 2.0.0-alpha2 | ||
* 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(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function s(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}var f=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},c=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}}(),p=r(2),d=n(p),h=r(7),v=n(h),m={thousandSeparator:d.default.oneOfType([d.default.string,d.default.oneOf([!0])]),decimalSeparator:d.default.string,decimalPrecision:d.default.number,displayType:d.default.oneOf(["input","text"]),prefix:d.default.string,suffix:d.default.string,format:d.default.oneOfType([d.default.string,d.default.func]),mask:d.default.string,value:d.default.oneOfType([d.default.number,d.default.string]),customInput:d.default.func,allowNegative:d.default.bool,onKeyDown:d.default.func,onChange:d.default.func,isAllowed:d.default.func},g={displayType:"input",decimalSeparator:".",allowNegative:!0,isAllowed:function(){return!0}},y=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),c(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:this.formatInput(a).formattedValue})}}},{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.value,a=e.decimalPrecision,o=e.format;if(o||void 0===n)return n;var i="number"==typeof n;return i&&(n=n.toString()),r&&i&&(n=n.replace(".",r)),0===a?n.split(r)[0]:n}},{key:"getSeparators",value:function(e){var t=e||this.props,r=t.thousandSeparator,n=t.decimalSeparator;t.decimalPrecision;if(r===!0&&(r=","),n===r)throw new Error("\n Decimal separator can't be same as thousand separator.\n\n thousandSeparator: "+r+' (thousandSeparator = {true} is same as thousandSeparator = ",")\n decimalSeparator: '+n+" (default value for decimalSeparator is .)\n ");return{decimalSeparator:n,thousandSeparator:r}}},{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?"":"|"+u(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){var r=this;this.setCaretPosition(e,t),setTimeout(function(){return r.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 l=i.lastIndexOf("#");return n?i.replace(/#/g,n):i.substring(0,o+1)+(l!==-1?i.substring(l+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(),f=u.thousandSeparator,c=u.decimalSeparator,p=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 g=e&&e.match(p);if(!g&&h)return{value:"",formattedValue:""};if(!g&&d)return{value:"",formattedValue:"-"};if(!g)return{value:"",formattedValue:""};var y=e.match(p).join(""),b=y;if(a)"string"==typeof a?b=this.formatWithPattern(b):"function"==typeof a&&(b=a(b));else{var x=b.indexOf(c)!==-1||i,P=b.split(c),S=P[0],w=P[1]||"";S=s(S),void 0!==i&&(w=l(w,i)),f&&(S=S.replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+f)),r&&(S=r+S),n&&(w+=n),d&&!h&&(S="-"+S),b=S+(x&&c||"")+w}return{value:(d&&!h?"-":"")+b.match(p).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:"onChangeHandler",value:function(e,t){var r=this;e.persist();var n=e.target,a=n.value,o=this.props.isAllowed,i=this.state.value,u=this.formatInput(a),s=u.formattedValue,l=u.value,f=this.getCursorPosition(a,s,n.selectionStart);return o(s,l,this.getFloatValue(l))||(s=i),this.setState({value:s},function(){r.setPatchedCaretPosition(n,f),t&&s!==i&&t(e,l)}),l}},{key:"onChange",value:function(e){this.onChangeHandler(e,this.props.onChange)}},{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=e.which,s=e.keyCode,l=this.getNumberRegex(!1,void 0!==o);console.log(l.toString(),i,u,s),console.log(e);var f=new RegExp("-");if(n-r===0)if(console.log("coming here"),"Delete"!==i||l.test(a[r])||f.test(a[r])){if("Backspace"===i&&!l.test(a[r-1])&&!f.test(a[r-1])){console.log("Backspace"),e.preventDefault();for(var c=r;!l.test(a[c-1])&&c>0;)c--;this.setPatchedCaretPosition(t,c)}}else{console.log("delete"),e.preventDefault();for(var p=r;!l.test(a[p])&&p<a.length;)p++;this.setPatchedCaretPosition(t,p)}this.props.onKeyDown&&this.props.onKeyDown(e)}},{key:"render",value:function(){var e=f({},this.props);Object.keys(m).forEach(function(t){delete e[t]});var t=f({},e,{type:"text",value:this.state.value,onChange:this.onChange,onKeyDown:this.onKeyDown});if("text"===this.props.displayType)return v.default.createElement("span",e,this.state.value);if(this.props.customInput){var r=this.props.customInput;return v.default.createElement(r,t)}return v.default.createElement("input",t)}}]),t}(v.default.Component);y.propTypes=m,y.defaultProps=g,e.exports=y},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 l;if(void 0===t)l=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var f=[r,n,o,i,u,s],c=0;l=new Error(t.replace(/%s/g,function(){return f[c++]})),l.name="Invariant Violation"}throw l.framesToPop=1,l}}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(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function s(e){return e.replace(/^0+/,"")||"0"}function f(e,t){for(var r="",n=0;n<=t-1;n++)r+=e[n]||"0";return r}var l=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},p=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}}(),c=r(2),d=n(c),h=r(7),v=n(h),m={thousandSeparator:d.default.oneOfType([d.default.string,d.default.oneOf([!0])]),decimalSeparator:d.default.string,decimalPrecision:d.default.number,displayType:d.default.oneOf(["input","text"]),prefix:d.default.string,suffix:d.default.string,format:d.default.oneOfType([d.default.string,d.default.func]),mask:d.default.string,value:d.default.oneOfType([d.default.number,d.default.string]),customInput:d.default.func,allowNegative:d.default.bool,onKeyDown:d.default.func,onChange:d.default.func,isAllowed:d.default.func},y={displayType:"input",decimalSeparator:".",allowNegative:!0,isAllowed:function(){return!0}},g=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),p(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:this.formatInput(a).formattedValue})}}},{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?"":"|"+u(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){var r=this;this.setCaretPosition(e,t),setTimeout(function(){return r.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(),l=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=s(S),void 0!==i&&(w=f(w,i)),l&&(S=S.replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+l)),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:"onChangeHandler",value:function(e,t){var r=this;e.persist();var n=e.target,a=n.value,o=this.props.isAllowed,i=this.state.value,u=this.formatInput(a),s=u.formattedValue,f=u.value,l=this.getCursorPosition(a,s,n.selectionStart);return o(s,f,this.getFloatValue(f))||(s=i),this.setState({value:s},function(){r.setPatchedCaretPosition(n,l),t&&s!==i&&t(e,f)}),f}},{key:"onChange",value:function(e){this.onChangeHandler(e,this.props.onChange)}},{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&&this.props.onKeyDown(e)}},{key:"render",value:function(){var e=l({},this.props);Object.keys(m).forEach(function(t){delete e[t]});var t=l({},e,{type:"text",value:this.state.value,onChange:this.onChange,onKeyDown:this.onKeyDown});if("text"===this.props.displayType)return v.default.createElement("span",e,this.state.value);if(this.props.customInput){var r=this.props.customInput;return v.default.createElement(r,t)}return v.default.createElement("input",t)}}]),t}(v.default.Component);g.propTypes=m,g.defaultProps=y,e.exports=g},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}])}); |
@@ -136,5 +136,5 @@ 'use strict'; | ||
var value = props.value, | ||
decimalPrecision = props.decimalPrecision, | ||
var decimalPrecision = props.decimalPrecision, | ||
format = props.format; | ||
var value = props.value; | ||
@@ -161,7 +161,10 @@ | ||
value: function getSeparators(props) { | ||
var _ref = props || this.props, | ||
thousandSeparator = _ref.thousandSeparator, | ||
decimalSeparator = _ref.decimalSeparator, | ||
decimalPrecision = _ref.decimalPrecision; | ||
props = props || this.props; | ||
var _props = props, | ||
decimalSeparator = _props.decimalSeparator; | ||
var _props2 = props, | ||
thousandSeparator = _props2.thousandSeparator; | ||
if (thousandSeparator === true) { | ||
@@ -183,5 +186,5 @@ thousandSeparator = ','; | ||
value: function getNumberRegex(g, ignoreDecimalSeparator) { | ||
var _props = this.props, | ||
format = _props.format, | ||
decimalPrecision = _props.decimalPrecision; | ||
var _props3 = this.props, | ||
format = _props3.format, | ||
decimalPrecision = _props3.decimalPrecision; | ||
@@ -237,5 +240,5 @@ var _getSeparators2 = this.getSeparators(), | ||
value: function formatWithPattern(str) { | ||
var _props2 = this.props, | ||
format = _props2.format, | ||
mask = _props2.mask; | ||
var _props4 = this.props, | ||
format = _props4.format, | ||
mask = _props4.mask; | ||
@@ -264,9 +267,9 @@ if (!format) return str; | ||
value: function formatInput(val) { | ||
var _props3 = this.props, | ||
prefix = _props3.prefix, | ||
suffix = _props3.suffix, | ||
mask = _props3.mask, | ||
format = _props3.format, | ||
allowNegative = _props3.allowNegative, | ||
decimalPrecision = _props3.decimalPrecision; | ||
var _props5 = this.props, | ||
prefix = _props5.prefix, | ||
suffix = _props5.suffix, | ||
mask = _props5.mask, | ||
format = _props5.format, | ||
allowNegative = _props5.allowNegative, | ||
decimalPrecision = _props5.decimalPrecision; | ||
@@ -414,15 +417,9 @@ var _getSeparators3 = this.getSeparators(), | ||
var decimalPrecision = this.props.decimalPrecision; | ||
var key = e.key, | ||
which = e.which, | ||
keyCode = e.keyCode; | ||
var key = e.key; | ||
var numRegex = this.getNumberRegex(false, decimalPrecision !== undefined); | ||
console.log(numRegex.toString(), key, which, keyCode); | ||
console.log(e); | ||
var negativeRegex = new RegExp('-'); | ||
//Handle backspace and delete against non numerical/decimal characters | ||
if (selectionEnd - selectionStart === 0) { | ||
console.log('coming here'); | ||
if (key === 'Delete' && !numRegex.test(value[selectionStart]) && !negativeRegex.test(value[selectionStart])) { | ||
console.log('delete'); | ||
e.preventDefault(); | ||
@@ -434,3 +431,2 @@ var nextCursorPosition = selectionStart; | ||
} else if (key === 'Backspace' && !numRegex.test(value[selectionStart - 1]) && !negativeRegex.test(value[selectionStart - 1])) { | ||
console.log('Backspace'); | ||
e.preventDefault(); | ||
@@ -437,0 +433,0 @@ var prevCursorPosition = selectionStart; |
{ | ||
"name": "react-number-format", | ||
"description": "React component to format number in an input or as a text.", | ||
"version": "2.0.0-alpha", | ||
"version": "2.0.0-alpha2", | ||
"main": "lib/number_format.js", | ||
@@ -6,0 +6,0 @@ "author": "Sudhanshu Yadav", |
@@ -104,4 +104,6 @@ /** | ||
const {decimalSeparator} = this.getSeparators(props); | ||
let {value, decimalPrecision, format} = props; | ||
const {decimalPrecision, format} = props; | ||
let {value} = props; | ||
if (format || value === undefined) return value; | ||
@@ -125,3 +127,8 @@ | ||
getSeparators(props) { | ||
let {thousandSeparator, decimalSeparator, decimalPrecision} = props || this.props; | ||
props = props || this.props; | ||
const {decimalSeparator} = props; | ||
let {thousandSeparator} = props; | ||
if (thousandSeparator === true) { | ||
@@ -333,12 +340,8 @@ thousandSeparator = ',' | ||
const {decimalPrecision} = this.props; | ||
const {key, which, keyCode} = e; | ||
const {key} = e; | ||
const numRegex = this.getNumberRegex(false, decimalPrecision !== undefined); | ||
console.log(numRegex.toString(), key, which, keyCode); | ||
console.log(e); | ||
const negativeRegex = new RegExp('-'); | ||
//Handle backspace and delete against non numerical/decimal characters | ||
if(selectionEnd - selectionStart === 0) { | ||
console.log('coming here'); | ||
if (key === 'Delete' && !numRegex.test(value[selectionStart]) && !negativeRegex.test(value[selectionStart])) { | ||
console.log('delete'); | ||
e.preventDefault(); | ||
@@ -349,3 +352,2 @@ let nextCursorPosition = selectionStart; | ||
} else if (key === 'Backspace' && !numRegex.test(value[selectionStart - 1]) && !negativeRegex.test(value[selectionStart-1])) { | ||
console.log('Backspace'); | ||
e.preventDefault(); | ||
@@ -352,0 +354,0 @@ let prevCursorPosition = selectionStart; |
127534
2220