diff --git a/dist/react-number-format.es.js b/dist/react-number-format.es.js index b2e5caee..38067fa1 100644 --- a/dist/react-number-format.es.js +++ b/dist/react-number-format.es.js @@ -1,5 +1,5 @@ /** - * react-number-format - 4.0.8 + * react-number-format - 4.0.9 * Author : Sudhanshu Yadav * Copyright (c) 2016, 2019 to Sudhanshu Yadav, released under the MIT license. * https://github.com/s-yadav/react-number-format @@ -508,7 +508,7 @@ function (_React$Component) { var _this$getSeparators2 = this.getSeparators(), decimalSeparator = _this$getSeparators2.decimalSeparator; - return new RegExp('\\d' + (decimalSeparator && decimalScale !== 0 && !ignoreDecimalSeparator && !format ? '|' + escapeRegExp(decimalSeparator) : ''), g ? 'g' : undefined); + return new RegExp('\\d' + (decimalSeparator && decimalScale !== 0 && !ignoreDecimalSeparator && (!format || typeof format === "function") ? '|' + escapeRegExp(decimalSeparator) : ''), g ? 'g' : undefined); } }, { key: "getSeparators", @@ -736,16 +736,14 @@ function (_React$Component) { removeFormatting = _this$props4.removeFormatting; if (!val) return val; - if (!format) { - val = this.removePrefixAndSuffix(val); - val = this.getFloatString(val); - } else if (typeof format === 'string') { + if (typeof format === 'string') { val = this.removePatternFormatting(val); } else if (typeof removeFormatting === 'function') { //condition need to be handled if format method is provide, val = removeFormatting(val); } else { - val = (val.match(/\d/g) || []).join(''); + val = this.removePrefixAndSuffix(val); + val = this.getFloatString(val); } return val; diff --git a/dist/react-number-format.js b/dist/react-number-format.js index 772da72c..75280de8 100644 --- a/dist/react-number-format.js +++ b/dist/react-number-format.js @@ -1,5 +1,5 @@ /** - * react-number-format - 4.0.8 + * react-number-format - 4.0.9 * Author : Sudhanshu Yadav * Copyright (c) 2016, 2019 to Sudhanshu Yadav, released under the MIT license. * https://github.com/s-yadav/react-number-format @@ -514,7 +514,7 @@ var _this$getSeparators2 = this.getSeparators(), decimalSeparator = _this$getSeparators2.decimalSeparator; - return new RegExp('\\d' + (decimalSeparator && decimalScale !== 0 && !ignoreDecimalSeparator && !format ? '|' + escapeRegExp(decimalSeparator) : ''), g ? 'g' : undefined); + return new RegExp('\\d' + (decimalSeparator && decimalScale !== 0 && !ignoreDecimalSeparator && (!format || typeof format === "function") ? '|' + escapeRegExp(decimalSeparator) : ''), g ? 'g' : undefined); } }, { key: "getSeparators", @@ -742,16 +742,14 @@ removeFormatting = _this$props4.removeFormatting; if (!val) return val; - if (!format) { - val = this.removePrefixAndSuffix(val); - val = this.getFloatString(val); - } else if (typeof format === 'string') { + if (typeof format === 'string') { val = this.removePatternFormatting(val); } else if (typeof removeFormatting === 'function') { //condition need to be handled if format method is provide, val = removeFormatting(val); } else { - val = (val.match(/\d/g) || []).join(''); + val = this.removePrefixAndSuffix(val); + val = this.getFloatString(val); } return val; diff --git a/dist/react-number-format.min.js b/dist/react-number-format.min.js index 15a6057c..a1cb0006 100644 --- a/dist/react-number-format.min.js +++ b/dist/react-number-format.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):(e=e||self).NumberFormat=t(e.React)}(this,function(f){"use strict";function n(e,t){for(var r=0;rr?(Number(e[0])+Number(t)).toString()+e.substring(1,e.length):t+e},u[0]),f=d(u[1]||"",Math.min(t,i.length),r),c=n?".":"";return"".concat(s?"-":"").concat(l).concat(c).concat(f)}(u,n,a)),l?this.formatNumString(u):this.formatInput(u))}},{key:"formatNegation",value:function(){var e=0=t.length-o.length||i&&s&&t[e]===u))}},{key:"checkIfFormatGotDeleted",value:function(e,t,r){for(var n=e;nt.length||!r.length||g===m||0===c&&p===t.length||c===d&&p===v)return r;if(this.checkIfFormatGotDeleted(g,m,t)&&(r=t),!a){var y=this.removeFormatting(r),S=O(y,o),b=S.beforeDecimal,x=S.afterDecimal,w=S.addNegation,k=er?(Number(e[0])+Number(t)).toString()+e.substring(1,e.length):t+e},u[0]),f=d(u[1]||"",Math.min(t,i.length),r),c=n?".":"";return"".concat(s?"-":"").concat(l).concat(c).concat(f)}(u,n,a)),l?this.formatNumString(u):this.formatInput(u))}},{key:"formatNegation",value:function(){var e=0=t.length-o.length||i&&s&&t[e]===u))}},{key:"checkIfFormatGotDeleted",value:function(e,t,r){for(var n=e;nt.length||!r.length||g===m||0===c&&p===t.length||c===d&&p===v)return r;if(this.checkIfFormatGotDeleted(g,m,t)&&(r=t),!a){var y=this.removeFormatting(r),S=O(y,o),b=S.beforeDecimal,x=S.afterDecimal,w=S.addNegation,k=e { expect(() => { shallow() }).toThrow() + }); + + it('should allow to use decimal separator for a format prop as a function', () => { + const wrapper = shallow( val}/>); + + simulateKeyInput(wrapper.find('input'), '123.24', 0); + expect(wrapper.state().value).toEqual('123.24'); }) }) });