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
120
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 4.0.7 to 4.0.8

188

dist/react-number-format.es.js
/**
* react-number-format - 4.0.7
* react-number-format - 4.0.8
* Author : Sudhanshu Yadav

@@ -106,172 +106,4 @@ * Copyright (c) 2016, 2019 to Sudhanshu Yadav, released under the MIT license.

* LICENSE file in the root directory of this source tree.
*
*
*/
function makeEmptyFunction(arg) {
return function () {
return arg;
};
}
/**
* This function accepts and discards inputs; it has no side effects. This is
* primarily useful idiomatically for overridable function endpoints which
* always need to be callable, since JS lacks a null-call idiom ala Cocoa.
*/
var emptyFunction = function emptyFunction() {};
emptyFunction.thatReturns = makeEmptyFunction;
emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
emptyFunction.thatReturnsNull = makeEmptyFunction(null);
emptyFunction.thatReturnsThis = function () {
return this;
};
emptyFunction.thatReturnsArgument = function (arg) {
return arg;
};
var emptyFunction_1 = emptyFunction;
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
/**
* Use invariant() to assert state which your program assumes to be true.
*
* Provide sprintf-style format (only %s is supported) and arguments
* to provide information about what broke and what you were
* expecting.
*
* The invariant message will be stripped in production, but the invariant
* will remain to ensure logic does not differ in production.
*/
var validateFormat = function validateFormat(format) {};
function invariant(condition, format, a, b, c, d, e, f) {
validateFormat(format);
if (!condition) {
var error;
if (format === undefined) {
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(format.replace(/%s/g, function () {
return args[argIndex++];
}));
error.name = 'Invariant Violation';
}
error.framesToPop = 1; // we don't care about invariant's own frame
throw error;
}
}
var invariant_1 = invariant;
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/
/* eslint-disable no-unused-vars */
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
function toObject(val) {
if (val === null || val === undefined) {
throw new TypeError('Object.assign cannot be called with null or undefined');
}
return Object(val);
}
function shouldUseNative() {
try {
if (!Object.assign) {
return false;
}
// Detect buggy property enumeration order in older V8 versions.
// https://bugs.chromium.org/p/v8/issues/detail?id=4118
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
test1[5] = 'de';
if (Object.getOwnPropertyNames(test1)[0] === '5') {
return false;
}
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test2 = {};
for (var i = 0; i < 10; i++) {
test2['_' + String.fromCharCode(i)] = i;
}
var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
return test2[n];
});
if (order2.join('') !== '0123456789') {
return false;
}
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test3 = {};
'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
test3[letter] = letter;
});
if (Object.keys(Object.assign({}, test3)).join('') !==
'abcdefghijklmnopqrst') {
return false;
}
return true;
} catch (err) {
// We don't expect any of the above to throw, but better to be safe.
return false;
}
}
var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
var from;
var to = toObject(target);
var symbols;
for (var s = 1; s < arguments.length; s++) {
from = Object(arguments[s]);
for (var key in from) {
if (hasOwnProperty.call(from, key)) {
to[key] = from[key];
}
}
if (getOwnPropertySymbols) {
symbols = getOwnPropertySymbols(from);
for (var i = 0; i < symbols.length; i++) {
if (propIsEnumerable.call(from, symbols[i])) {
to[symbols[i]] = from[symbols[i]];
}
}
}
}
return to;
};
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';

@@ -281,2 +113,6 @@

function emptyFunction() {}
function emptyFunctionWithReset() {}
emptyFunctionWithReset.resetWarningCache = emptyFunction;
var factoryWithThrowingShims = function() {

@@ -288,4 +124,3 @@ function shim(props, propName, componentName, location, propFullName, secret) {

}
invariant_1(
false,
var err = new Error(
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +

@@ -295,2 +130,4 @@ 'Use PropTypes.checkPropTypes() to call them. ' +

);
err.name = 'Invariant Violation';
throw err;
} shim.isRequired = shim;

@@ -313,2 +150,3 @@ function getShim() {

element: shim,
elementType: shim,
instanceOf: getShim,

@@ -320,6 +158,8 @@ node: shim,

shape: getShim,
exact: getShim
exact: getShim,
checkPropTypes: emptyFunctionWithReset,
resetWarningCache: emptyFunction
};
ReactPropTypes.checkPropTypes = emptyFunction_1;
ReactPropTypes.PropTypes = ReactPropTypes;

@@ -530,3 +370,3 @@

isNumericString: propTypes.bool,
customInput: propTypes.func,
customInput: propTypes.elementType,
allowNegative: propTypes.bool,

@@ -533,0 +373,0 @@ allowEmptyFormatting: propTypes.bool,

/**
* react-number-format - 4.0.7
* react-number-format - 4.0.8
* Author : Sudhanshu Yadav

@@ -11,4 +11,4 @@ * Copyright (c) 2016, 2019 to Sudhanshu Yadav, released under the MIT license.

typeof define === 'function' && define.amd ? define(['react'], factory) :
(global.NumberFormat = factory(global.React));
}(this, (function (React) { 'use strict';
(global = global || self, global.NumberFormat = factory(global.React));
}(this, function (React) { 'use strict';

@@ -113,172 +113,4 @@ React = React && React.hasOwnProperty('default') ? React['default'] : React;

* LICENSE file in the root directory of this source tree.
*
*
*/
function makeEmptyFunction(arg) {
return function () {
return arg;
};
}
/**
* This function accepts and discards inputs; it has no side effects. This is
* primarily useful idiomatically for overridable function endpoints which
* always need to be callable, since JS lacks a null-call idiom ala Cocoa.
*/
var emptyFunction = function emptyFunction() {};
emptyFunction.thatReturns = makeEmptyFunction;
emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
emptyFunction.thatReturnsNull = makeEmptyFunction(null);
emptyFunction.thatReturnsThis = function () {
return this;
};
emptyFunction.thatReturnsArgument = function (arg) {
return arg;
};
var emptyFunction_1 = emptyFunction;
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
/**
* Use invariant() to assert state which your program assumes to be true.
*
* Provide sprintf-style format (only %s is supported) and arguments
* to provide information about what broke and what you were
* expecting.
*
* The invariant message will be stripped in production, but the invariant
* will remain to ensure logic does not differ in production.
*/
var validateFormat = function validateFormat(format) {};
function invariant(condition, format, a, b, c, d, e, f) {
validateFormat(format);
if (!condition) {
var error;
if (format === undefined) {
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(format.replace(/%s/g, function () {
return args[argIndex++];
}));
error.name = 'Invariant Violation';
}
error.framesToPop = 1; // we don't care about invariant's own frame
throw error;
}
}
var invariant_1 = invariant;
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/
/* eslint-disable no-unused-vars */
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
function toObject(val) {
if (val === null || val === undefined) {
throw new TypeError('Object.assign cannot be called with null or undefined');
}
return Object(val);
}
function shouldUseNative() {
try {
if (!Object.assign) {
return false;
}
// Detect buggy property enumeration order in older V8 versions.
// https://bugs.chromium.org/p/v8/issues/detail?id=4118
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
test1[5] = 'de';
if (Object.getOwnPropertyNames(test1)[0] === '5') {
return false;
}
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test2 = {};
for (var i = 0; i < 10; i++) {
test2['_' + String.fromCharCode(i)] = i;
}
var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
return test2[n];
});
if (order2.join('') !== '0123456789') {
return false;
}
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test3 = {};
'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
test3[letter] = letter;
});
if (Object.keys(Object.assign({}, test3)).join('') !==
'abcdefghijklmnopqrst') {
return false;
}
return true;
} catch (err) {
// We don't expect any of the above to throw, but better to be safe.
return false;
}
}
var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
var from;
var to = toObject(target);
var symbols;
for (var s = 1; s < arguments.length; s++) {
from = Object(arguments[s]);
for (var key in from) {
if (hasOwnProperty.call(from, key)) {
to[key] = from[key];
}
}
if (getOwnPropertySymbols) {
symbols = getOwnPropertySymbols(from);
for (var i = 0; i < symbols.length; i++) {
if (propIsEnumerable.call(from, symbols[i])) {
to[symbols[i]] = from[symbols[i]];
}
}
}
}
return to;
};
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';

@@ -288,2 +120,6 @@

function emptyFunction() {}
function emptyFunctionWithReset() {}
emptyFunctionWithReset.resetWarningCache = emptyFunction;
var factoryWithThrowingShims = function() {

@@ -295,4 +131,3 @@ function shim(props, propName, componentName, location, propFullName, secret) {

}
invariant_1(
false,
var err = new Error(
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +

@@ -302,2 +137,4 @@ 'Use PropTypes.checkPropTypes() to call them. ' +

);
err.name = 'Invariant Violation';
throw err;
} shim.isRequired = shim;

@@ -320,2 +157,3 @@ function getShim() {

element: shim,
elementType: shim,
instanceOf: getShim,

@@ -327,6 +165,8 @@ node: shim,

shape: getShim,
exact: getShim
exact: getShim,
checkPropTypes: emptyFunctionWithReset,
resetWarningCache: emptyFunction
};
ReactPropTypes.checkPropTypes = emptyFunction_1;
ReactPropTypes.PropTypes = ReactPropTypes;

@@ -537,3 +377,3 @@

isNumericString: propTypes.bool,
customInput: propTypes.func,
customInput: propTypes.elementType,
allowNegative: propTypes.bool,

@@ -1492,2 +1332,2 @@ allowEmptyFormatting: propTypes.bool,

})));
}));

@@ -1,8 +0,1 @@

/**
* react-number-format - 4.0.7
* Author : Sudhanshu Yadav
* Copyright (c) 2016, 2019 to Sudhanshu Yadav, released under the MIT license.
* https://github.com/s-yadav/react-number-format
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):t.NumberFormat=e(t.React)}(this,function(h){"use strict";function a(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function g(){return(g=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function o(t,e){return(o=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function u(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function t(t){return function(){return t}}h=h&&h.hasOwnProperty("default")?h.default:h;var e=function(){};e.thatReturns=t,e.thatReturnsFalse=t(!1),e.thatReturnsTrue=t(!0),e.thatReturnsNull=t(null),e.thatReturnsThis=function(){return this},e.thatReturnsArgument=function(t){return t};var n=e;var i=function(t,e,r,n,a,o,i,s){if(!t){var u;if(void 0===e)u=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,a,o,i,s],c=0;(u=new Error(e.replace(/%s/g,function(){return l[c++]}))).name="Invariant Violation"}throw u.framesToPop=1,u}},r=Object.getOwnPropertySymbols,l=Object.prototype.hasOwnProperty,c=Object.prototype.propertyIsEnumerable;(function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},r=0;r<10;r++)e["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(e).map(function(t){return e[t]}).join(""))return!1;var n={};return"abcdefghijklmnopqrst".split("").forEach(function(t){n[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},n)).join("")}catch(t){return!1}})()&&Object.assign;var f,p=(function(t){t.exports=function(){function t(t,e,r,n,a,o){"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"!==o&&i(!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 e(){return t}var r={array:t.isRequired=t,bool:t,func:t,number:t,object:t,string:t,symbol:t,any:t,arrayOf:e,element:t,instanceOf:e,node:t,objectOf:e,oneOf:e,oneOfType:e,shape:e,exact:e};return r.checkPropTypes=n,r.PropTypes=r}()}(f={exports:{}},f.exports),f.exports);function m(){}function d(t){return!!(t||"").match(/\d/)}function v(t){return t.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}function P(t){var e=!(1<arguments.length&&void 0!==arguments[1])||arguments[1],r="-"===t[0],n=r&&e,a=(t=t.replace("-","")).split(".");return{beforeDecimal:a[0],afterDecimal:a[1]||"",hasNagation:r,addNegation:n}}function S(t,e,r){for(var n="",a=r?"0":"",o=0;o<=e-1;o++)n+=t[o]||a;return n}function y(t,e){if(t.value=t.value,null!==t){if(t.createTextRange){var r=t.createTextRange();return r.move("character",e),r.select(),!0}return t.selectionStart||0===t.selectionStart?(t.focus(),t.setSelectionRange(e,e),!0):(t.focus(),!1)}}function b(t,e,r){return Math.min(Math.max(t,e),r)}function x(t){return Math.max(t.selectionStart,t.selectionEnd)}var O={thousandSeparator:p.oneOfType([p.string,p.oneOf([!0])]),decimalSeparator:p.string,thousandsGroupStyle:p.oneOf(["thousand","lakh","wan"]),decimalScale:p.number,fixedDecimalScale:p.bool,displayType:p.oneOf(["input","text"]),prefix:p.string,suffix:p.string,format:p.oneOfType([p.string,p.func]),removeFormatting:p.func,mask:p.oneOfType([p.string,p.arrayOf(p.string)]),value:p.oneOfType([p.number,p.string]),defaultValue:p.oneOfType([p.number,p.string]),isNumericString:p.bool,customInput:p.func,allowNegative:p.bool,allowEmptyFormatting:p.bool,onValueChange:p.func,onKeyDown:p.func,onMouseUp:p.func,onChange:p.func,onFocus:p.func,onBlur:p.func,type:p.oneOf(["text","tel","password"]),isAllowed:p.func,renderText:p.func,getInputRef:p.func},w={displayType:"input",decimalSeparator:".",thousandsGroupStyle:"thousand",fixedDecimalScale:!1,prefix:"",suffix:"",allowNegative:!0,allowEmptyFormatting:!1,isNumericString:!1,type:"text",onValueChange:m,onChange:m,onKeyDown:m,onMouseUp:m,onFocus:m,onBlur:m,isAllowed:function(){return!0},getInputRef:m},k=function(t){function i(t){var e,r,n;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,i),r=this,e=!(n=s(i).call(this,t))||"object"!=typeof n&&"function"!=typeof n?u(r):n;var a=t.defaultValue;e.validateProps();var o=e.formatValueProp(a);return e.state={value:o,numAsString:e.removeFormatting(o)},e.selectionBeforeInput={selectionStart:0,selectionEnd:0},e.onChange=e.onChange.bind(u(u(e))),e.onKeyDown=e.onKeyDown.bind(u(u(e))),e.onMouseUp=e.onMouseUp.bind(u(u(e))),e.onFocus=e.onFocus.bind(u(u(e))),e.onBlur=e.onBlur.bind(u(u(e))),e}var e,r,n;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&o(t,e)}(i,h.Component),e=i,(r=[{key:"componentDidUpdate",value:function(t){this.updateValueIfRequired(t)}},{key:"updateValueIfRequired",value:function(t){var e=this.props,r=this.state,n=this.focusedElm,a=r.value,o=r.numAsString,i=void 0===o?"":o;if(t!==e){this.validateProps();var s=this.formatNumString(i),u=void 0===e.value?s:this.formatValueProp(),l=this.removeFormatting(u),c=parseFloat(l),f=parseFloat(i);(isNaN(c)&&isNaN(f)||c===f)&&s===a&&(null!==n||u===a)||this.updateValue({formattedValue:u,numAsString:l,input:n})}}},{key:"getFloatString",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",e=this.props.decimalScale,r=this.getSeparators().decimalSeparator,n=this.getNumberRegex(!0),a="-"===t[0];a&&(t=t.replace("-","")),r&&0===e&&(t=t.split(r)[0]);var o=(t=(t.match(n)||[]).join("").replace(r,".")).indexOf(".");return-1!==o&&(t="".concat(t.substring(0,o),".").concat(t.substring(o+1,t.length).replace(new RegExp(v(r),"g"),""))),a&&(t="-"+t),t}},{key:"getNumberRegex",value:function(t,e){var r=this.props,n=r.format,a=r.decimalScale,o=this.getSeparators().decimalSeparator;return new RegExp("\\d"+(!o||0===a||e||n?"":"|"+v(o)),t?"g":void 0)}},{key:"getSeparators",value:function(){var t=this.props.decimalSeparator,e=this.props.thousandSeparator;return!0===e&&(e=","),{decimalSeparator:t,thousandSeparator:e}}},{key:"getMaskAtIndex",value:function(t){var e=this.props.mask,r=void 0===e?" ":e;return"string"==typeof r?r:r[t]||" "}},{key:"getValueObject",value:function(t,e){var r=parseFloat(e);return{formattedValue:t,value:e,floatValue:isNaN(r)?void 0:r}}},{key:"validateProps",value:function(){var t=this.props.mask,e=this.getSeparators(),r=e.decimalSeparator,n=e.thousandSeparator;if(r===n)throw new Error("\n Decimal separator can't be same as thousand separator.\n thousandSeparator: ".concat(n,' (thousandSeparator = {true} is same as thousandSeparator = ",")\n decimalSeparator: ').concat(r," (default value for decimalSeparator is .)\n "));if(t&&("string"===t?t:t.toString()).match(/\d/g))throw new Error("\n Mask ".concat(t," should not contain numeric character;\n "))}},{key:"setPatchedCaretPosition",value:function(t,e,r){y(t,e),setTimeout(function(){t.value===r&&y(t,e)},0)}},{key:"correctCaretPosition",value:function(t,e,r){var n=this.props,a=n.prefix,o=n.suffix,i=n.format;if(""===t)return 0;if(e=b(e,0,t.length),!i){var s="-"===t[0];return b(e,a.length+(s?1:0),t.length-o.length)}if("function"==typeof i)return e;if("#"===i[e]&&d(t[e]))return e;if("#"===i[e-1]&&d(t[e-1]))return e;var u=i.indexOf("#");e=b(e,u,i.lastIndexOf("#")+1);for(var l=i.substring(e,i.length).indexOf("#"),c=e,f=e+(-1===l?0:l);u<c&&("#"!==i[c]||!d(t[c]));)c-=1;return!d(t[f])||"left"===r&&e!==u||e-c<f-e?d(t[c])?c+1:c:f}},{key:"getCaretPosition",value:function(t,e,r){var n,a,o=this.props.format,i=this.state.value,s=this.getNumberRegex(!0),u=(t.match(s)||[]).join(""),l=(e.match(s)||[]).join("");for(a=n=0;a<r;a++){var c=t[a]||"",f=e[n]||"";if((c.match(s)||c===f)&&("0"!==c||!f.match(s)||"0"===f||u.length===l.length)){for(;c!==e[n]&&n<e.length;)n++;n++}}return"string"!=typeof o||i||(n=e.length),n=this.correctCaretPosition(e,n)}},{key:"removePrefixAndSuffix",value:function(t){var e=this.props,r=e.format,n=e.prefix,a=e.suffix;if(!r&&t){var o="-"===t[0];o&&(t=t.substring(1,t.length));var i=(t=n&&0===t.indexOf(n)?t.substring(n.length,t.length):t).lastIndexOf(a);t=a&&-1!==i&&i===t.length-a.length?t.substring(0,i):t,o&&(t="-"+t)}return t}},{key:"removePatternFormatting",value:function(t){for(var e=this.props.format.split("#").filter(function(t){return""!==t}),r=0,n="",a=0,o=e.length;a<=o;a++){var i=e[a]||"",s=a===o?t.length:t.indexOf(i,r);if(-1===s){n=t;break}n+=t.substring(r,s),r=s+i.length}return(n.match(/\d/g)||[]).join("")}},{key:"removeFormatting",value:function(t){var e=this.props,r=e.format,n=e.removeFormatting;return t?t=r?"string"==typeof r?this.removePatternFormatting(t):"function"==typeof n?n(t):(t.match(/\d/g)||[]).join(""):(t=this.removePrefixAndSuffix(t),this.getFloatString(t)):t}},{key:"formatWithPattern",value:function(t){for(var e=this.props.format,r=0,n=e.split(""),a=0,o=e.length;a<o;a++)"#"===e[a]&&(n[a]=t[r]||this.getMaskAtIndex(r),r+=1);return n.join("")}},{key:"formatAsNumber",value:function(t){var e,r,n,a,o=this.props,i=o.decimalScale,s=o.fixedDecimalScale,u=o.prefix,l=o.suffix,c=o.allowNegative,f=o.thousandsGroupStyle,p=this.getSeparators(),h=p.thousandSeparator,g=p.decimalSeparator,m=-1!==t.indexOf(".")||i&&s,d=P(t,c),v=d.beforeDecimal,y=d.afterDecimal,b=d.addNegation;return void 0!==i&&(y=S(y,i,s)),h&&(e=v,r=h,n=function(t){switch(t){case"lakh":return/(\d+?)(?=(\d\d)+(\d)(?!\d))(\.\d+)?/g;case"wan":return/(\d)(?=(\d{4})+(?!\d))/g;case"thousand":default:return/(\d)(?=(\d{3})+(?!\d))/g}}(f),a=e.search(/[1-9]/),v=e.substring(0,a)+e.substring(a,e.length).replace(n,"$1"+r)),u&&(v=u+v),l&&(y+=l),b&&(v="-"+v),t=v+(m&&g||"")+y}},{key:"formatNumString",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",e=this.props,r=e.format,n=e.allowEmptyFormatting,a=t;return a=""!==t||n?"-"!==t||r?"string"==typeof r?this.formatWithPattern(a):"function"==typeof r?r(a):this.formatAsNumber(a):"-":""}},{key:"formatValueProp",value:function(t){var e=this.props,r=e.format,n=e.decimalScale,a=e.fixedDecimalScale,o=e.allowEmptyFormatting,i=this.props,s=i.value,u=void 0===s?t:s,l=i.isNumericString,c=!u&&0!==u;return c&&o&&(u=""),c&&!o?"":("number"==typeof u&&(u=u.toString(),l=!0),"Infinity"===u&&l&&(u=""),l&&!r&&"number"==typeof n&&(u=function(t,e,r){if(-1!==["","-"].indexOf(t))return t;var n=-1!==t.indexOf(".")&&e,a=P(t),o=a.beforeDecimal,i=a.afterDecimal,s=a.hasNagation,u=parseFloat("0.".concat(i||"0")).toFixed(e).split("."),l=o.split("").reverse().reduce(function(t,e,r){return t.length>r?(Number(t[0])+Number(e)).toString()+t.substring(1,t.length):e+t},u[0]),c=S(u[1]||"",Math.min(e,i.length),r),f=n?".":"";return"".concat(s?"-":"").concat(l).concat(f).concat(c)}(u,n,a)),l?this.formatNumString(u):this.formatInput(u))}},{key:"formatNegation",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",e=this.props.allowNegative,r=new RegExp("(-)"),n=new RegExp("(-)(.)*(-)"),a=r.test(t),o=n.test(t);return t=t.replace(/-/g,""),a&&!o&&e&&(t="-"+t),t}},{key:"formatInput",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";return this.props.format||(t=this.removePrefixAndSuffix(t),t=this.formatNegation(t)),t=this.removeFormatting(t),this.formatNumString(t)}},{key:"isCharacterAFormat",value:function(t,e){var r=this.props,n=r.format,a=r.prefix,o=r.suffix,i=r.decimalScale,s=r.fixedDecimalScale,u=this.getSeparators().decimalSeparator;return"string"==typeof n&&"#"!==n[t]||!(n||!(t<a.length||t>=e.length-o.length||i&&s&&e[t]===u))}},{key:"checkIfFormatGotDeleted",value:function(t,e,r){for(var n=t;n<e;n++)if(this.isCharacterAFormat(n,r))return!0;return!1}},{key:"correctInputValue",value:function(t,e,r){var n=this.props,a=n.format,o=n.allowNegative,i=n.prefix,s=n.suffix,u=this.getSeparators().decimalSeparator,l=this.state.numAsString||"",c=this.selectionBeforeInput,f=c.selectionStart,p=c.selectionEnd,h=function(t,e){for(var r=0,n=0,a=t.length,o=e.length;t[r]===e[r]&&r<a;)r++;for(;t[a-1-n]===e[o-1-n]&&r<o-n&&r<a-n;)n++;return{start:r,end:a-n}}(e,r),g=h.start,m=h.end;if(!a&&"."!==u&&g===m&&"."===r[f])return r.substr(0,f)+u+r.substr(f+1,r.length);var d=a?0:i.length,v=e.length-(a?0:s.length);if(r.length>e.length||!r.length||g===m||0===f&&p===e.length||f===d&&p===v)return r;if(this.checkIfFormatGotDeleted(g,m,e)&&(r=e),!a){var y=this.removeFormatting(r),b=P(y,o),S=b.beforeDecimal,x=b.afterDecimal,O=b.addNegation,w=t<r.indexOf(u)+1;if(y.length<l.length&&w&&""===S&&!parseFloat(x))return O?"-":""}return r}},{key:"updateValue",value:function(t){var e=this,r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:m,n=t.formattedValue,a=t.input,o=t.numAsString,i=t.caretPos,s=this.props.onValueChange,u=this.state.value;if(a){if(!i){var l=t.inputValue||a.value,c=x(a);i=this.getCaretPosition(l,n,c)}a.value=n,this.setPatchedCaretPosition(a,i,n)}void 0===o&&(o=this.removeFormatting(n)),n!==u?this.setState({value:n,numAsString:o},function(){s(e.getValueObject(n,o)),r()}):r()}},{key:"onChange",value:function(t){t.persist();var e=t.target,r=e.value,n=this.state,a=this.props,o=a.isAllowed,i=n.value||"",s=x(e);r=this.correctInputValue(s,i,r);var u=this.formatInput(r)||"",l=this.removeFormatting(u);o(this.getValueObject(u,l))||(u=i),this.updateValue({formattedValue:u,numAsString:l,inputValue:r,input:e},function(){a.onChange(t)})}},{key:"onBlur",value:function(t){var e=this.props,r=this.state,n=e.format,a=e.onBlur,o=r.numAsString,i=r.value;if(this.focusedElm=null,!n){o=function(t){if(!t)return t;var e="-"===t[0];e&&(t=t.substring(1,t.length));var r=t.split("."),n=r[0].replace(/^0+/,"")||"0",a=r[1]||"";return"".concat(e?"-":"").concat(n).concat(a?".".concat(a):"")}(o);var s=this.formatNumString(o);if(s!==i)return t.persist(),void this.updateValue({formattedValue:s,numAsString:o},function(){a(t)})}a(t)}},{key:"onKeyDown",value:function(t){var e,r=t.target,n=t.key,a=r.selectionStart,o=r.selectionEnd,i=r.value,s=void 0===i?"":i,u=this.props,l=u.decimalScale,c=u.fixedDecimalScale,f=u.prefix,p=u.suffix,h=u.format,g=u.onKeyDown,m=(u.onValueChange,void 0!==l&&c),d=this.getNumberRegex(!1,m),v=new RegExp("-"),y="string"==typeof h;if(this.selectionBeforeInput={selectionStart:a,selectionEnd:o},"ArrowLeft"===n||"Backspace"===n?e=a-1:"ArrowRight"===n?e=a+1:"Delete"===n&&(e=a),void 0!==e&&a===o){var b=e,S=y?h.indexOf("#"):f.length,x=y?h.lastIndexOf("#")+1:s.length-p.length;if("ArrowLeft"===n||"ArrowRight"===n){var O="ArrowLeft"===n?"left":"right";b=this.correctCaretPosition(s,e,O)}else if("Delete"!==n||d.test(s[e])||v.test(s[e])){if("Backspace"===n&&!d.test(s[e]))if(a<=S+1&&"-"===s[0]&&void 0===h){var w=s.substring(1);t.persist(),this.updateValue({formattedValue:w,caretPos:b,input:r})}else if(!v.test(s[e])){for(;!d.test(s[b-1])&&S<b;)b--;b=this.correctCaretPosition(s,b,"left")}}else for(;!d.test(s[b])&&b<x;)b++;(b!==e||e<S||x<e)&&(t.preventDefault(),this.setPatchedCaretPosition(r,b,s)),t.isUnitTestRun&&this.setPatchedCaretPosition(r,b,s),this.props.onKeyDown(t)}else g(t)}},{key:"onMouseUp",value:function(t){var e=t.target,r=e.selectionStart,n=e.selectionEnd,a=e.value,o=void 0===a?"":a;if(r===n){var i=this.correctCaretPosition(o,r);i!==r&&this.setPatchedCaretPosition(e,i,o)}this.props.onMouseUp(t)}},{key:"onFocus",value:function(i){var s=this;i.persist(),this.focusedElm=i.target,setTimeout(function(){var t=i.target,e=t.selectionStart,r=t.selectionEnd,n=t.value,a=void 0===n?"":n,o=s.correctCaretPosition(a,e);o===e||0===e&&r===a.length||s.setPatchedCaretPosition(t,o,a),s.props.onFocus(i)},0)}},{key:"render",value:function(){var e,r,n,t=this.props,a=t.type,o=t.displayType,i=t.customInput,s=t.renderText,u=t.getInputRef,l=this.state.value,c=(e=this.props,r=O,n={},Object.keys(e).forEach(function(t){r[t]||(n[t]=e[t])}),n),f=g({},c,{type:a,value:l,onChange:this.onChange,onKeyDown:this.onKeyDown,onMouseUp:this.onMouseUp,onFocus:this.onFocus,onBlur:this.onBlur});if("text"===o)return s?s(l)||null:h.createElement("span",g({},c,{ref:u}),l);if(i){var p=i;return h.createElement(p,f)}return h.createElement("input",g({},f,{ref:u}))}}])&&a(e.prototype,r),n&&a(e,n),i}();return k.propTypes=O,k.defaultProps=w,k});
!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;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)}}function c(){return(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}).apply(this,arguments)}function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function r(e,t){return(r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function i(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}f=f&&f.hasOwnProperty("default")?f.default:f;function a(){}function s(){}s.resetWarningCache=a;var e,t=(function(e){e.exports=function(){function e(e,t,r,n,a,o){if("SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"!==o){var i=new Error("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");throw i.name="Invariant Violation",i}}function t(){return e}var r={array:e.isRequired=e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:s,resetWarningCache:a};return r.PropTypes=r}()}(e={exports:{}},e.exports),e.exports);function p(){}function h(e){return!!(e||"").match(/\d/)}function u(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}function O(e){var t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1],r="-"===e[0],n=r&&t,a=(e=e.replace("-","")).split(".");return{beforeDecimal:a[0],afterDecimal:a[1]||"",hasNagation:r,addNegation:n}}function d(e,t,r){for(var n="",a=r?"0":"",o=0;o<=t-1;o++)n+=e[o]||a;return n}function l(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)}}function g(e,t,r){return Math.min(Math.max(e,t),r)}function m(e){return Math.max(e.selectionStart,e.selectionEnd)}var v={thousandSeparator:t.oneOfType([t.string,t.oneOf([!0])]),decimalSeparator:t.string,thousandsGroupStyle:t.oneOf(["thousand","lakh","wan"]),decimalScale:t.number,fixedDecimalScale:t.bool,displayType:t.oneOf(["input","text"]),prefix:t.string,suffix:t.string,format:t.oneOfType([t.string,t.func]),removeFormatting:t.func,mask:t.oneOfType([t.string,t.arrayOf(t.string)]),value:t.oneOfType([t.number,t.string]),defaultValue:t.oneOfType([t.number,t.string]),isNumericString:t.bool,customInput:t.elementType,allowNegative:t.bool,allowEmptyFormatting:t.bool,onValueChange:t.func,onKeyDown:t.func,onMouseUp:t.func,onChange:t.func,onFocus:t.func,onBlur:t.func,type:t.oneOf(["text","tel","password"]),isAllowed:t.func,renderText:t.func,getInputRef:t.func},y={displayType:"input",decimalSeparator:".",thousandsGroupStyle:"thousand",fixedDecimalScale:!1,prefix:"",suffix:"",allowNegative:!0,allowEmptyFormatting:!1,isNumericString:!1,type:"text",onValueChange:p,onChange:p,onKeyDown:p,onMouseUp:p,onFocus:p,onBlur:p,isAllowed:function(){return!0},getInputRef:p},S=function(e){function a(e){var t;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),t=function(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?i(e):t}(this,o(a).call(this,e));var r=e.defaultValue;t.validateProps();var n=t.formatValueProp(r);return t.state={value:n,numAsString:t.removeFormatting(n)},t.selectionBeforeInput={selectionStart:0,selectionEnd:0},t.onChange=t.onChange.bind(i(i(t))),t.onKeyDown=t.onKeyDown.bind(i(i(t))),t.onMouseUp=t.onMouseUp.bind(i(i(t))),t.onFocus=t.onFocus.bind(i(i(t))),t.onBlur=t.onBlur.bind(i(i(t))),t}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&r(e,t)}(a,f.Component),function(e,t,r){t&&n(e.prototype,t),r&&n(e,r)}(a,[{key:"componentDidUpdate",value:function(e){this.updateValueIfRequired(e)}},{key:"updateValueIfRequired",value:function(e){var t=this.props,r=this.state,n=this.focusedElm,a=r.value,o=r.numAsString,i=void 0===o?"":o;if(e!==t){this.validateProps();var s=this.formatNumString(i),u=void 0===t.value?s:this.formatValueProp(),l=this.removeFormatting(u),f=parseFloat(l),c=parseFloat(i);(isNaN(f)&&isNaN(c)||f===c)&&s===a&&(null!==n||u===a)||this.updateValue({formattedValue:u,numAsString:l,input:n})}}},{key:"getFloatString",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=this.props.decimalScale,r=this.getSeparators().decimalSeparator,n=this.getNumberRegex(!0),a="-"===e[0];a&&(e=e.replace("-","")),r&&0===t&&(e=e.split(r)[0]);var o=(e=(e.match(n)||[]).join("").replace(r,".")).indexOf(".");return-1!==o&&(e="".concat(e.substring(0,o),".").concat(e.substring(o+1,e.length).replace(new RegExp(u(r),"g"),""))),a&&(e="-"+e),e}},{key:"getNumberRegex",value:function(e,t){var r=this.props,n=r.format,a=r.decimalScale,o=this.getSeparators().decimalSeparator;return new RegExp("\\d"+(!o||0===a||t||n?"":"|"+u(o)),e?"g":void 0)}},{key:"getSeparators",value:function(){var e=this.props.decimalSeparator,t=this.props.thousandSeparator;return!0===t&&(t=","),{decimalSeparator:e,thousandSeparator:t}}},{key:"getMaskAtIndex",value:function(e){var t=this.props.mask,r=void 0===t?" ":t;return"string"==typeof r?r:r[e]||" "}},{key:"getValueObject",value:function(e,t){var r=parseFloat(t);return{formattedValue:e,value:t,floatValue:isNaN(r)?void 0:r}}},{key:"validateProps",value:function(){var e=this.props.mask,t=this.getSeparators(),r=t.decimalSeparator,n=t.thousandSeparator;if(r===n)throw new Error("\n Decimal separator can't be same as thousand separator.\n thousandSeparator: ".concat(n,' (thousandSeparator = {true} is same as thousandSeparator = ",")\n decimalSeparator: ').concat(r," (default value for decimalSeparator is .)\n "));if(e&&("string"===e?e:e.toString()).match(/\d/g))throw new Error("\n Mask ".concat(e," should not contain numeric character;\n "))}},{key:"setPatchedCaretPosition",value:function(e,t,r){l(e,t),setTimeout(function(){e.value===r&&l(e,t)},0)}},{key:"correctCaretPosition",value:function(e,t,r){var n=this.props,a=n.prefix,o=n.suffix,i=n.format;if(""===e)return 0;if(t=g(t,0,e.length),!i){var s="-"===e[0];return g(t,a.length+(s?1:0),e.length-o.length)}if("function"==typeof i)return t;if("#"===i[t]&&h(e[t]))return t;if("#"===i[t-1]&&h(e[t-1]))return t;var u=i.indexOf("#");t=g(t,u,i.lastIndexOf("#")+1);for(var l=i.substring(t,i.length).indexOf("#"),f=t,c=t+(-1===l?0:l);u<f&&("#"!==i[f]||!h(e[f]));)f-=1;return!h(e[c])||"left"===r&&t!==u||t-f<c-t?h(e[f])?f+1:f:c}},{key:"getCaretPosition",value:function(e,t,r){var n,a,o=this.props.format,i=this.state.value,s=this.getNumberRegex(!0),u=(e.match(s)||[]).join(""),l=(t.match(s)||[]).join("");for(a=n=0;a<r;a++){var f=e[a]||"",c=t[n]||"";if((f.match(s)||f===c)&&("0"!==f||!c.match(s)||"0"===c||u.length===l.length)){for(;f!==t[n]&&n<t.length;)n++;n++}}return"string"!=typeof o||i||(n=t.length),n=this.correctCaretPosition(t,n)}},{key:"removePrefixAndSuffix",value:function(e){var t=this.props,r=t.format,n=t.prefix,a=t.suffix;if(!r&&e){var o="-"===e[0];o&&(e=e.substring(1,e.length));var i=(e=n&&0===e.indexOf(n)?e.substring(n.length,e.length):e).lastIndexOf(a);e=a&&-1!==i&&i===e.length-a.length?e.substring(0,i):e,o&&(e="-"+e)}return e}},{key:"removePatternFormatting",value:function(e){for(var t=this.props.format.split("#").filter(function(e){return""!==e}),r=0,n="",a=0,o=t.length;a<=o;a++){var i=t[a]||"",s=a===o?e.length:e.indexOf(i,r);if(-1===s){n=e;break}n+=e.substring(r,s),r=s+i.length}return(n.match(/\d/g)||[]).join("")}},{key:"removeFormatting",value:function(e){var t=this.props,r=t.format,n=t.removeFormatting;return e?e=r?"string"==typeof r?this.removePatternFormatting(e):"function"==typeof n?n(e):(e.match(/\d/g)||[]).join(""):(e=this.removePrefixAndSuffix(e),this.getFloatString(e)):e}},{key:"formatWithPattern",value:function(e){for(var t=this.props.format,r=0,n=t.split(""),a=0,o=t.length;a<o;a++)"#"===t[a]&&(n[a]=e[r]||this.getMaskAtIndex(r),r+=1);return n.join("")}},{key:"formatAsNumber",value:function(e){var t=this.props,r=t.decimalScale,n=t.fixedDecimalScale,a=t.prefix,o=t.suffix,i=t.allowNegative,s=t.thousandsGroupStyle,u=this.getSeparators(),l=u.thousandSeparator,f=u.decimalSeparator,c=-1!==e.indexOf(".")||r&&n,p=O(e,i),h=p.beforeDecimal,g=p.afterDecimal,m=p.addNegation;return void 0!==r&&(g=d(g,r,n)),l&&(h=function(e,t,r){var n=function(e){switch(e){case"lakh":return/(\d+?)(?=(\d\d)+(\d)(?!\d))(\.\d+)?/g;case"wan":return/(\d)(?=(\d{4})+(?!\d))/g;case"thousand":default:return/(\d)(?=(\d{3})+(?!\d))/g}}(r),a=e.search(/[1-9]/);return e.substring(0,a)+e.substring(a,e.length).replace(n,"$1"+t)}(h,l,s)),a&&(h=a+h),o&&(g+=o),m&&(h="-"+h),e=h+(c&&f||"")+g}},{key:"formatNumString",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=this.props,r=t.format,n=t.allowEmptyFormatting,a=e;return a=""!==e||n?"-"!==e||r?"string"==typeof r?this.formatWithPattern(a):"function"==typeof r?r(a):this.formatAsNumber(a):"-":""}},{key:"formatValueProp",value:function(e){var t=this.props,r=t.format,n=t.decimalScale,a=t.fixedDecimalScale,o=t.allowEmptyFormatting,i=this.props,s=i.value,u=void 0===s?e:s,l=i.isNumericString,f=!u&&0!==u;return f&&o&&(u=""),f&&!o?"":("number"==typeof u&&(u=u.toString(),l=!0),"Infinity"===u&&l&&(u=""),l&&!r&&"number"==typeof n&&(u=function(e,t,r){if(-1!==["","-"].indexOf(e))return e;var n=-1!==e.indexOf(".")&&t,a=O(e),o=a.beforeDecimal,i=a.afterDecimal,s=a.hasNagation,u=parseFloat("0.".concat(i||"0")).toFixed(t).split("."),l=o.split("").reverse().reduce(function(e,t,r){return e.length>r?(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<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=this.props.allowNegative,r=new RegExp("(-)"),n=new RegExp("(-)(.)*(-)"),a=r.test(e),o=n.test(e);return e=e.replace(/-/g,""),a&&!o&&t&&(e="-"+e),e}},{key:"formatInput",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";return this.props.format||(e=this.removePrefixAndSuffix(e),e=this.formatNegation(e)),e=this.removeFormatting(e),this.formatNumString(e)}},{key:"isCharacterAFormat",value:function(e,t){var r=this.props,n=r.format,a=r.prefix,o=r.suffix,i=r.decimalScale,s=r.fixedDecimalScale,u=this.getSeparators().decimalSeparator;return"string"==typeof n&&"#"!==n[e]||!(n||!(e<a.length||e>=t.length-o.length||i&&s&&t[e]===u))}},{key:"checkIfFormatGotDeleted",value:function(e,t,r){for(var n=e;n<t;n++)if(this.isCharacterAFormat(n,r))return!0;return!1}},{key:"correctInputValue",value:function(e,t,r){var n=this.props,a=n.format,o=n.allowNegative,i=n.prefix,s=n.suffix,u=this.getSeparators().decimalSeparator,l=this.state.numAsString||"",f=this.selectionBeforeInput,c=f.selectionStart,p=f.selectionEnd,h=function(e,t){for(var r=0,n=0,a=e.length,o=t.length;e[r]===t[r]&&r<a;)r++;for(;e[a-1-n]===t[o-1-n]&&r<o-n&&r<a-n;)n++;return{start:r,end:a-n}}(t,r),g=h.start,m=h.end;if(!a&&"."!==u&&g===m&&"."===r[c])return r.substr(0,c)+u+r.substr(c+1,r.length);var d=a?0:i.length,v=t.length-(a?0:s.length);if(r.length>t.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<r.indexOf(u)+1;if(y.length<l.length&&k&&""===b&&!parseFloat(x))return w?"-":""}return r}},{key:"updateValue",value:function(e){var t=this,r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:p,n=e.formattedValue,a=e.input,o=e.numAsString,i=e.caretPos,s=this.props.onValueChange,u=this.state.value;if(a){if(!i){var l=e.inputValue||a.value,f=m(a);i=this.getCaretPosition(l,n,f)}a.value=n,this.setPatchedCaretPosition(a,i,n)}void 0===o&&(o=this.removeFormatting(n)),n!==u?this.setState({value:n,numAsString:o},function(){s(t.getValueObject(n,o)),r()}):r()}},{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||"",s=m(t);r=this.correctInputValue(s,i,r);var u=this.formatInput(r)||"",l=this.removeFormatting(u);o(this.getValueObject(u,l))||(u=i),this.updateValue({formattedValue:u,numAsString:l,inputValue:r,input:t},function(){a.onChange(e)})}},{key:"onBlur",value:function(e){var t=this.props,r=this.state,n=t.format,a=t.onBlur,o=r.numAsString,i=r.value;if(this.focusedElm=null,!n){o=function(e){if(!e)return e;var t="-"===e[0];t&&(e=e.substring(1,e.length));var r=e.split("."),n=r[0].replace(/^0+/,"")||"0",a=r[1]||"";return"".concat(t?"-":"").concat(n).concat(a?".".concat(a):"")}(o);var s=this.formatNumString(o);if(s!==i)return e.persist(),void this.updateValue({formattedValue:s,numAsString:o},function(){a(e)})}a(e)}},{key:"onKeyDown",value:function(e){var t,r=e.target,n=e.key,a=r.selectionStart,o=r.selectionEnd,i=r.value,s=void 0===i?"":i,u=this.props,l=u.decimalScale,f=u.fixedDecimalScale,c=u.prefix,p=u.suffix,h=u.format,g=u.onKeyDown,m=(u.onValueChange,void 0!==l&&f),d=this.getNumberRegex(!1,m),v=new RegExp("-"),y="string"==typeof h;if(this.selectionBeforeInput={selectionStart:a,selectionEnd:o},"ArrowLeft"===n||"Backspace"===n?t=a-1:"ArrowRight"===n?t=a+1:"Delete"===n&&(t=a),void 0!==t&&a===o){var S=t,b=y?h.indexOf("#"):c.length,x=y?h.lastIndexOf("#")+1:s.length-p.length;if("ArrowLeft"===n||"ArrowRight"===n){var w="ArrowLeft"===n?"left":"right";S=this.correctCaretPosition(s,t,w)}else if("Delete"!==n||d.test(s[t])||v.test(s[t])){if("Backspace"===n&&!d.test(s[t]))if(a<=b+1&&"-"===s[0]&&void 0===h){var k=s.substring(1);e.persist(),this.updateValue({formattedValue:k,caretPos:S,input:r})}else if(!v.test(s[t])){for(;!d.test(s[S-1])&&b<S;)S--;S=this.correctCaretPosition(s,S,"left")}}else for(;!d.test(s[S])&&S<x;)S++;(S!==t||t<b||x<t)&&(e.preventDefault(),this.setPatchedCaretPosition(r,S,s)),e.isUnitTestRun&&this.setPatchedCaretPosition(r,S,s),this.props.onKeyDown(e)}else g(e)}},{key:"onMouseUp",value:function(e){var t=e.target,r=t.selectionStart,n=t.selectionEnd,a=t.value,o=void 0===a?"":a;if(r===n){var i=this.correctCaretPosition(o,r);i!==r&&this.setPatchedCaretPosition(t,i,o)}this.props.onMouseUp(e)}},{key:"onFocus",value:function(i){var s=this;i.persist(),this.focusedElm=i.target,setTimeout(function(){var e=i.target,t=e.selectionStart,r=e.selectionEnd,n=e.value,a=void 0===n?"":n,o=s.correctCaretPosition(a,t);o===t||0===t&&r===a.length||s.setPatchedCaretPosition(e,o,a),s.props.onFocus(i)},0)}},{key:"render",value:function(){var e=this.props,t=e.type,r=e.displayType,n=e.customInput,a=e.renderText,o=e.getInputRef,i=this.state.value,s=function(t,r){var n={};return Object.keys(t).forEach(function(e){r[e]||(n[e]=t[e])}),n}(this.props,v),u=c({},s,{type:t,value:i,onChange:this.onChange,onKeyDown:this.onKeyDown,onMouseUp:this.onMouseUp,onFocus:this.onFocus,onBlur:this.onBlur});if("text"===r)return a?a(i)||null:f.createElement("span",c({},s,{ref:o}),i);if(n){var l=n;return f.createElement(l,u)}return f.createElement("input",c({},u,{ref:o}))}}]),a}();return S.propTypes=v,S.defaultProps=y,S});

2

lib/number_format.js

@@ -51,3 +51,3 @@ "use strict";

isNumericString: _propTypes.default.bool,
customInput: _propTypes.default.func,
customInput: _propTypes.default.elementType,
allowNegative: _propTypes.default.bool,

@@ -54,0 +54,0 @@ allowEmptyFormatting: _propTypes.default.bool,

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

@@ -75,10 +75,10 @@ "author": "Sudhanshu Yadav",

"react-transform-hmr": "^1.0.4",
"rollup": "^0.65.2",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-commonjs": "^9.1.6",
"rollup-plugin-filesize": "^4.0.1",
"rollup-plugin-license": "^0.7.0",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-uglify": "^5.0.2",
"rollup": "^1.11.3",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^9.3.4",
"rollup-plugin-filesize": "^6.0.1",
"rollup-plugin-license": "^0.8.1",
"rollup-plugin-node-resolve": "^4.2.3",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-uglify": "^6.0.2",
"typescript": "^3.1.5",

@@ -94,4 +94,4 @@ "webpack": "^4.17.1",

"dependencies": {
"prop-types": "^15.6.0"
"prop-types": "^15.7.2"
}
}

Sorry, the diff of this file is not supported yet

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