Socket
Socket
Sign inDemoInstall

react-number-format

Package Overview
Dependencies
8
Maintainers
1
Versions
117
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.1.3 to 5.1.4

example/src/index.js

122

dist/react-number-format.cjs.js
/**
* react-number-format - 5.1.3
* react-number-format - 5.1.4
* Author : Sudhanshu Yadav

@@ -708,3 +708,3 @@ * Copyright (c) 2016, 2023 to Sudhanshu Yadav, released under the MIT license.

var suffix = props.suffix; if ( suffix === void 0 ) suffix = '';
var allowNegative = props.allowNegative; if ( allowNegative === void 0 ) allowNegative = true;
var allowNegative = props.allowNegative;
var thousandsGroupStyle = props.thousandsGroupStyle; if ( thousandsGroupStyle === void 0 ) thousandsGroupStyle = 'thousand';

@@ -782,5 +782,6 @@ // don't apply formatting on empty string or '-'

function removeFormatting(value, changeMeta, props) {
var assign;
if ( changeMeta === void 0 ) changeMeta = getDefaultChangeMeta(value);
var allowNegative = props.allowNegative; if ( allowNegative === void 0 ) allowNegative = true;
var allowNegative = props.allowNegative;
var prefix = props.prefix; if ( prefix === void 0 ) prefix = '';

@@ -797,2 +798,11 @@ var suffix = props.suffix; if ( suffix === void 0 ) suffix = '';

var isBeforeDecimalSeparator = value[end] === decimalSeparator;
/**
* If only a number is added on empty input which matches with the prefix or suffix,
* then don't remove it, just return the same
*/
if (charIsNumber(value) &&
(value === prefix || value === suffix) &&
changeMeta.lastValue === '') {
return value;
}
/** Check for any allowed decimal separator is added in the numeric format and replace it with decimal separator */

@@ -803,20 +813,50 @@ if (end - start === 1 && allowedDecimalSeparators.indexOf(value[start]) !== -1) {

}
var hasNegation = false;
/**
* if prefix starts with - the number hast to have two - at the start
* if suffix starts with - and the value length is same as suffix length, then the - sign is from the suffix
* In other cases, if the value starts with - then it is a negation
*/
if (prefix.startsWith('-'))
{ hasNegation = value.startsWith('--'); }
else if (suffix.startsWith('-') && value.length === suffix.length)
{ hasNegation = false; }
else if (value[0] === '-')
{ hasNegation = true; }
// remove negation from start to simplify prefix logic as negation comes before prefix
if (hasNegation) {
value = value.substring(1);
// account for the removal of the negation for start and end index
start -= 1;
end -= 1;
var stripNegation = function (value, start, end) {
/**
* if prefix starts with - we don't allow negative number to avoid confusion
* if suffix starts with - and the value length is same as suffix length, then the - sign is from the suffix
* In other cases, if the value starts with - then it is a negation
*/
var hasNegation = false;
var hasDoubleNegation = false;
if (prefix.startsWith('-')) {
hasNegation = false;
}
else if (value.startsWith('--')) {
hasNegation = false;
hasDoubleNegation = true;
}
else if (suffix.startsWith('-') && value.length === suffix.length) {
hasNegation = false;
}
else if (value[0] === '-') {
hasNegation = true;
}
var charsToRemove = hasNegation ? 1 : 0;
if (hasDoubleNegation)
{ charsToRemove = 2; }
// remove negation/double negation from start to simplify prefix logic as negation comes before prefix
if (charsToRemove) {
value = value.substring(charsToRemove);
// account for the removal of the negation for start and end index
start -= charsToRemove;
end -= charsToRemove;
}
return { value: value, start: start, end: end, hasNegation: hasNegation };
};
var toMetadata = stripNegation(value, start, end);
var hasNegation = toMetadata.hasNegation;
((assign = toMetadata, value = assign.value, start = assign.start, end = assign.end));
var ref$1 = stripNegation(changeMeta.lastValue, from.start, from.end);
var fromStart = ref$1.start;
var fromEnd = ref$1.end;
var lastValue = ref$1.value;
// if only prefix and suffix part is updated reset the value to last value
// if the changed range is from suffix in the updated value, and the the suffix starts with the same characters, allow the change
var updatedSuffixPart = value.substring(start, end);
if (value.length &&
lastValue.length &&
(fromStart > lastValue.length - suffix.length || fromEnd < prefix.length) &&
!(updatedSuffixPart && suffix.startsWith(updatedSuffixPart))) {
value = lastValue;
}

@@ -835,3 +875,3 @@ /**

value = value.substring(startIndex);
// account for deleted prefix for end index
// account for deleted prefix for end
end -= startIndex;

@@ -848,2 +888,6 @@ /**

{ endIndex = suffixStartIndex; }
// if the suffix is removed from the end
else if (end > suffixStartIndex)
{ endIndex = end; }
// if the suffix is removed from start
else if (end > value.length - suffix.length)

@@ -863,6 +907,6 @@ { endIndex = end; }

//clear all numbers in such case while keeping the - sign
var ref$1 = splitDecimal(value, allowNegative);
var beforeDecimal = ref$1.beforeDecimal;
var afterDecimal = ref$1.afterDecimal;
var addNegation = ref$1.addNegation; // eslint-disable-line prefer-const
var ref$2 = splitDecimal(value, allowNegative);
var beforeDecimal = ref$2.beforeDecimal;
var afterDecimal = ref$2.afterDecimal;
var addNegation = ref$2.addNegation; // eslint-disable-line prefer-const
//clear only if something got deleted before decimal (cursor is before decimal)

@@ -889,11 +933,22 @@ if (to.end - to.start < from.end - from.start &&

}
function validateProps(props) {
function validateAndUpdateProps(props) {
var ref = getSeparators(props);
var thousandSeparator = ref.thousandSeparator;
var decimalSeparator = ref.decimalSeparator;
// eslint-disable-next-line prefer-const
var prefix = props.prefix; if ( prefix === void 0 ) prefix = '';
var allowNegative = props.allowNegative; if ( allowNegative === void 0 ) allowNegative = true;
if (thousandSeparator === decimalSeparator) {
throw new Error(("\n Decimal separator can't be same as thousand separator.\n thousandSeparator: " + thousandSeparator + " (thousandSeparator = {true} is same as thousandSeparator = \",\")\n decimalSeparator: " + decimalSeparator + " (default value for decimalSeparator is .)\n "));
}
if (prefix.startsWith('-') && allowNegative) {
// TODO: throw error in next major version
console.error(("\n Prefix can't start with '-' when allowNegative is true.\n prefix: " + prefix + "\n allowNegative: " + allowNegative + "\n "));
allowNegative = false;
}
return Object.assign(Object.assign({}, props), { allowNegative: allowNegative });
}
function useNumericFormat(props) {
// validate props
props = validateAndUpdateProps(props);
var decimalSeparator = props.decimalSeparator; if ( decimalSeparator === void 0 ) decimalSeparator = '.';

@@ -916,4 +971,2 @@ var allowedDecimalSeparators = props.allowedDecimalSeparators;

var restProps = __rest(props, ["decimalSeparator", "allowedDecimalSeparators", "thousandsGroupStyle", "suffix", "allowNegative", "allowLeadingZeros", "onKeyDown", "onBlur", "thousandSeparator", "decimalScale", "fixedDecimalScale", "prefix", "defaultValue", "value", "valueIsNumericString", "onValueChange"]);
// validate props
validateProps(props);
var _format = function (numStr) { return format(numStr, props); };

@@ -960,3 +1013,6 @@ var _removeFormatting = function (inputValue, changeMeta) { return removeFormatting(inputValue, changeMeta, props); };

// if user hits backspace, while the cursor is before prefix, and the input has negation, remove the negation
if (key === 'Backspace' && value[0] === '-' && selectionStart === prefix.length + 1) {
if (key === 'Backspace' &&
value[0] === '-' &&
selectionStart === prefix.length + 1 &&
allowNegative) {
// bring the cursor to after negation

@@ -1140,3 +1196,3 @@ setCaretPosition(el, 1);

}
function validateProps$1(props) {
function validateProps(props) {
var mask = props.mask;

@@ -1159,3 +1215,3 @@ if (mask) {

// validate props
validateProps$1(props);
validateProps(props);
var _getCaretBoundary = function (formattedValue) {

@@ -1162,0 +1218,0 @@ return getCaretBoundary$1(formattedValue, props);

/**
* react-number-format - 5.1.3
* react-number-format - 5.1.4
* Author : Sudhanshu Yadav

@@ -701,3 +701,3 @@ * Copyright (c) 2016, 2023 to Sudhanshu Yadav, released under the MIT license.

var suffix = props.suffix; if ( suffix === void 0 ) suffix = '';
var allowNegative = props.allowNegative; if ( allowNegative === void 0 ) allowNegative = true;
var allowNegative = props.allowNegative;
var thousandsGroupStyle = props.thousandsGroupStyle; if ( thousandsGroupStyle === void 0 ) thousandsGroupStyle = 'thousand';

@@ -775,5 +775,6 @@ // don't apply formatting on empty string or '-'

function removeFormatting(value, changeMeta, props) {
var assign;
if ( changeMeta === void 0 ) changeMeta = getDefaultChangeMeta(value);
var allowNegative = props.allowNegative; if ( allowNegative === void 0 ) allowNegative = true;
var allowNegative = props.allowNegative;
var prefix = props.prefix; if ( prefix === void 0 ) prefix = '';

@@ -790,2 +791,11 @@ var suffix = props.suffix; if ( suffix === void 0 ) suffix = '';

var isBeforeDecimalSeparator = value[end] === decimalSeparator;
/**
* If only a number is added on empty input which matches with the prefix or suffix,
* then don't remove it, just return the same
*/
if (charIsNumber(value) &&
(value === prefix || value === suffix) &&
changeMeta.lastValue === '') {
return value;
}
/** Check for any allowed decimal separator is added in the numeric format and replace it with decimal separator */

@@ -796,20 +806,50 @@ if (end - start === 1 && allowedDecimalSeparators.indexOf(value[start]) !== -1) {

}
var hasNegation = false;
/**
* if prefix starts with - the number hast to have two - at the start
* if suffix starts with - and the value length is same as suffix length, then the - sign is from the suffix
* In other cases, if the value starts with - then it is a negation
*/
if (prefix.startsWith('-'))
{ hasNegation = value.startsWith('--'); }
else if (suffix.startsWith('-') && value.length === suffix.length)
{ hasNegation = false; }
else if (value[0] === '-')
{ hasNegation = true; }
// remove negation from start to simplify prefix logic as negation comes before prefix
if (hasNegation) {
value = value.substring(1);
// account for the removal of the negation for start and end index
start -= 1;
end -= 1;
var stripNegation = function (value, start, end) {
/**
* if prefix starts with - we don't allow negative number to avoid confusion
* if suffix starts with - and the value length is same as suffix length, then the - sign is from the suffix
* In other cases, if the value starts with - then it is a negation
*/
var hasNegation = false;
var hasDoubleNegation = false;
if (prefix.startsWith('-')) {
hasNegation = false;
}
else if (value.startsWith('--')) {
hasNegation = false;
hasDoubleNegation = true;
}
else if (suffix.startsWith('-') && value.length === suffix.length) {
hasNegation = false;
}
else if (value[0] === '-') {
hasNegation = true;
}
var charsToRemove = hasNegation ? 1 : 0;
if (hasDoubleNegation)
{ charsToRemove = 2; }
// remove negation/double negation from start to simplify prefix logic as negation comes before prefix
if (charsToRemove) {
value = value.substring(charsToRemove);
// account for the removal of the negation for start and end index
start -= charsToRemove;
end -= charsToRemove;
}
return { value: value, start: start, end: end, hasNegation: hasNegation };
};
var toMetadata = stripNegation(value, start, end);
var hasNegation = toMetadata.hasNegation;
((assign = toMetadata, value = assign.value, start = assign.start, end = assign.end));
var ref$1 = stripNegation(changeMeta.lastValue, from.start, from.end);
var fromStart = ref$1.start;
var fromEnd = ref$1.end;
var lastValue = ref$1.value;
// if only prefix and suffix part is updated reset the value to last value
// if the changed range is from suffix in the updated value, and the the suffix starts with the same characters, allow the change
var updatedSuffixPart = value.substring(start, end);
if (value.length &&
lastValue.length &&
(fromStart > lastValue.length - suffix.length || fromEnd < prefix.length) &&
!(updatedSuffixPart && suffix.startsWith(updatedSuffixPart))) {
value = lastValue;
}

@@ -828,3 +868,3 @@ /**

value = value.substring(startIndex);
// account for deleted prefix for end index
// account for deleted prefix for end
end -= startIndex;

@@ -841,2 +881,6 @@ /**

{ endIndex = suffixStartIndex; }
// if the suffix is removed from the end
else if (end > suffixStartIndex)
{ endIndex = end; }
// if the suffix is removed from start
else if (end > value.length - suffix.length)

@@ -856,6 +900,6 @@ { endIndex = end; }

//clear all numbers in such case while keeping the - sign
var ref$1 = splitDecimal(value, allowNegative);
var beforeDecimal = ref$1.beforeDecimal;
var afterDecimal = ref$1.afterDecimal;
var addNegation = ref$1.addNegation; // eslint-disable-line prefer-const
var ref$2 = splitDecimal(value, allowNegative);
var beforeDecimal = ref$2.beforeDecimal;
var afterDecimal = ref$2.afterDecimal;
var addNegation = ref$2.addNegation; // eslint-disable-line prefer-const
//clear only if something got deleted before decimal (cursor is before decimal)

@@ -882,11 +926,22 @@ if (to.end - to.start < from.end - from.start &&

}
function validateProps(props) {
function validateAndUpdateProps(props) {
var ref = getSeparators(props);
var thousandSeparator = ref.thousandSeparator;
var decimalSeparator = ref.decimalSeparator;
// eslint-disable-next-line prefer-const
var prefix = props.prefix; if ( prefix === void 0 ) prefix = '';
var allowNegative = props.allowNegative; if ( allowNegative === void 0 ) allowNegative = true;
if (thousandSeparator === decimalSeparator) {
throw new Error(("\n Decimal separator can't be same as thousand separator.\n thousandSeparator: " + thousandSeparator + " (thousandSeparator = {true} is same as thousandSeparator = \",\")\n decimalSeparator: " + decimalSeparator + " (default value for decimalSeparator is .)\n "));
}
if (prefix.startsWith('-') && allowNegative) {
// TODO: throw error in next major version
console.error(("\n Prefix can't start with '-' when allowNegative is true.\n prefix: " + prefix + "\n allowNegative: " + allowNegative + "\n "));
allowNegative = false;
}
return Object.assign(Object.assign({}, props), { allowNegative: allowNegative });
}
function useNumericFormat(props) {
// validate props
props = validateAndUpdateProps(props);
var decimalSeparator = props.decimalSeparator; if ( decimalSeparator === void 0 ) decimalSeparator = '.';

@@ -909,4 +964,2 @@ var allowedDecimalSeparators = props.allowedDecimalSeparators;

var restProps = __rest(props, ["decimalSeparator", "allowedDecimalSeparators", "thousandsGroupStyle", "suffix", "allowNegative", "allowLeadingZeros", "onKeyDown", "onBlur", "thousandSeparator", "decimalScale", "fixedDecimalScale", "prefix", "defaultValue", "value", "valueIsNumericString", "onValueChange"]);
// validate props
validateProps(props);
var _format = function (numStr) { return format(numStr, props); };

@@ -953,3 +1006,6 @@ var _removeFormatting = function (inputValue, changeMeta) { return removeFormatting(inputValue, changeMeta, props); };

// if user hits backspace, while the cursor is before prefix, and the input has negation, remove the negation
if (key === 'Backspace' && value[0] === '-' && selectionStart === prefix.length + 1) {
if (key === 'Backspace' &&
value[0] === '-' &&
selectionStart === prefix.length + 1 &&
allowNegative) {
// bring the cursor to after negation

@@ -1133,3 +1189,3 @@ setCaretPosition(el, 1);

}
function validateProps$1(props) {
function validateProps(props) {
var mask = props.mask;

@@ -1152,3 +1208,3 @@ if (mask) {

// validate props
validateProps$1(props);
validateProps(props);
var _getCaretBoundary = function (formattedValue) {

@@ -1155,0 +1211,0 @@ return getCaretBoundary$1(formattedValue, props);

/**
* react-number-format - 5.1.3
* react-number-format - 5.1.4
* Author : Sudhanshu Yadav

@@ -707,3 +707,3 @@ * Copyright (c) 2016, 2023 to Sudhanshu Yadav, released under the MIT license.

var suffix = props.suffix; if ( suffix === void 0 ) suffix = '';
var allowNegative = props.allowNegative; if ( allowNegative === void 0 ) allowNegative = true;
var allowNegative = props.allowNegative;
var thousandsGroupStyle = props.thousandsGroupStyle; if ( thousandsGroupStyle === void 0 ) thousandsGroupStyle = 'thousand';

@@ -781,5 +781,6 @@ // don't apply formatting on empty string or '-'

function removeFormatting(value, changeMeta, props) {
var assign;
if ( changeMeta === void 0 ) changeMeta = getDefaultChangeMeta(value);
var allowNegative = props.allowNegative; if ( allowNegative === void 0 ) allowNegative = true;
var allowNegative = props.allowNegative;
var prefix = props.prefix; if ( prefix === void 0 ) prefix = '';

@@ -796,2 +797,11 @@ var suffix = props.suffix; if ( suffix === void 0 ) suffix = '';

var isBeforeDecimalSeparator = value[end] === decimalSeparator;
/**
* If only a number is added on empty input which matches with the prefix or suffix,
* then don't remove it, just return the same
*/
if (charIsNumber(value) &&
(value === prefix || value === suffix) &&
changeMeta.lastValue === '') {
return value;
}
/** Check for any allowed decimal separator is added in the numeric format and replace it with decimal separator */

@@ -802,20 +812,50 @@ if (end - start === 1 && allowedDecimalSeparators.indexOf(value[start]) !== -1) {

}
var hasNegation = false;
/**
* if prefix starts with - the number hast to have two - at the start
* if suffix starts with - and the value length is same as suffix length, then the - sign is from the suffix
* In other cases, if the value starts with - then it is a negation
*/
if (prefix.startsWith('-'))
{ hasNegation = value.startsWith('--'); }
else if (suffix.startsWith('-') && value.length === suffix.length)
{ hasNegation = false; }
else if (value[0] === '-')
{ hasNegation = true; }
// remove negation from start to simplify prefix logic as negation comes before prefix
if (hasNegation) {
value = value.substring(1);
// account for the removal of the negation for start and end index
start -= 1;
end -= 1;
var stripNegation = function (value, start, end) {
/**
* if prefix starts with - we don't allow negative number to avoid confusion
* if suffix starts with - and the value length is same as suffix length, then the - sign is from the suffix
* In other cases, if the value starts with - then it is a negation
*/
var hasNegation = false;
var hasDoubleNegation = false;
if (prefix.startsWith('-')) {
hasNegation = false;
}
else if (value.startsWith('--')) {
hasNegation = false;
hasDoubleNegation = true;
}
else if (suffix.startsWith('-') && value.length === suffix.length) {
hasNegation = false;
}
else if (value[0] === '-') {
hasNegation = true;
}
var charsToRemove = hasNegation ? 1 : 0;
if (hasDoubleNegation)
{ charsToRemove = 2; }
// remove negation/double negation from start to simplify prefix logic as negation comes before prefix
if (charsToRemove) {
value = value.substring(charsToRemove);
// account for the removal of the negation for start and end index
start -= charsToRemove;
end -= charsToRemove;
}
return { value: value, start: start, end: end, hasNegation: hasNegation };
};
var toMetadata = stripNegation(value, start, end);
var hasNegation = toMetadata.hasNegation;
((assign = toMetadata, value = assign.value, start = assign.start, end = assign.end));
var ref$1 = stripNegation(changeMeta.lastValue, from.start, from.end);
var fromStart = ref$1.start;
var fromEnd = ref$1.end;
var lastValue = ref$1.value;
// if only prefix and suffix part is updated reset the value to last value
// if the changed range is from suffix in the updated value, and the the suffix starts with the same characters, allow the change
var updatedSuffixPart = value.substring(start, end);
if (value.length &&
lastValue.length &&
(fromStart > lastValue.length - suffix.length || fromEnd < prefix.length) &&
!(updatedSuffixPart && suffix.startsWith(updatedSuffixPart))) {
value = lastValue;
}

@@ -834,3 +874,3 @@ /**

value = value.substring(startIndex);
// account for deleted prefix for end index
// account for deleted prefix for end
end -= startIndex;

@@ -847,2 +887,6 @@ /**

{ endIndex = suffixStartIndex; }
// if the suffix is removed from the end
else if (end > suffixStartIndex)
{ endIndex = end; }
// if the suffix is removed from start
else if (end > value.length - suffix.length)

@@ -862,6 +906,6 @@ { endIndex = end; }

//clear all numbers in such case while keeping the - sign
var ref$1 = splitDecimal(value, allowNegative);
var beforeDecimal = ref$1.beforeDecimal;
var afterDecimal = ref$1.afterDecimal;
var addNegation = ref$1.addNegation; // eslint-disable-line prefer-const
var ref$2 = splitDecimal(value, allowNegative);
var beforeDecimal = ref$2.beforeDecimal;
var afterDecimal = ref$2.afterDecimal;
var addNegation = ref$2.addNegation; // eslint-disable-line prefer-const
//clear only if something got deleted before decimal (cursor is before decimal)

@@ -888,11 +932,22 @@ if (to.end - to.start < from.end - from.start &&

}
function validateProps(props) {
function validateAndUpdateProps(props) {
var ref = getSeparators(props);
var thousandSeparator = ref.thousandSeparator;
var decimalSeparator = ref.decimalSeparator;
// eslint-disable-next-line prefer-const
var prefix = props.prefix; if ( prefix === void 0 ) prefix = '';
var allowNegative = props.allowNegative; if ( allowNegative === void 0 ) allowNegative = true;
if (thousandSeparator === decimalSeparator) {
throw new Error(("\n Decimal separator can't be same as thousand separator.\n thousandSeparator: " + thousandSeparator + " (thousandSeparator = {true} is same as thousandSeparator = \",\")\n decimalSeparator: " + decimalSeparator + " (default value for decimalSeparator is .)\n "));
}
if (prefix.startsWith('-') && allowNegative) {
// TODO: throw error in next major version
console.error(("\n Prefix can't start with '-' when allowNegative is true.\n prefix: " + prefix + "\n allowNegative: " + allowNegative + "\n "));
allowNegative = false;
}
return Object.assign(Object.assign({}, props), { allowNegative: allowNegative });
}
function useNumericFormat(props) {
// validate props
props = validateAndUpdateProps(props);
var decimalSeparator = props.decimalSeparator; if ( decimalSeparator === void 0 ) decimalSeparator = '.';

@@ -915,4 +970,2 @@ var allowedDecimalSeparators = props.allowedDecimalSeparators;

var restProps = __rest(props, ["decimalSeparator", "allowedDecimalSeparators", "thousandsGroupStyle", "suffix", "allowNegative", "allowLeadingZeros", "onKeyDown", "onBlur", "thousandSeparator", "decimalScale", "fixedDecimalScale", "prefix", "defaultValue", "value", "valueIsNumericString", "onValueChange"]);
// validate props
validateProps(props);
var _format = function (numStr) { return format(numStr, props); };

@@ -959,3 +1012,6 @@ var _removeFormatting = function (inputValue, changeMeta) { return removeFormatting(inputValue, changeMeta, props); };

// if user hits backspace, while the cursor is before prefix, and the input has negation, remove the negation
if (key === 'Backspace' && value[0] === '-' && selectionStart === prefix.length + 1) {
if (key === 'Backspace' &&
value[0] === '-' &&
selectionStart === prefix.length + 1 &&
allowNegative) {
// bring the cursor to after negation

@@ -1139,3 +1195,3 @@ setCaretPosition(el, 1);

}
function validateProps$1(props) {
function validateProps(props) {
var mask = props.mask;

@@ -1158,3 +1214,3 @@ if (mask) {

// validate props
validateProps$1(props);
validateProps(props);
var _getCaretBoundary = function (formattedValue) {

@@ -1161,0 +1217,0 @@ return getCaretBoundary$1(formattedValue, props);

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).NumberFormat={},e.React)}(this,function(e,R){"use strict";var k,t,M="default"in R?R.default:R;function I(e,t){var r={};for(a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(r[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var n=0,a=Object.getOwnPropertySymbols(e);n<a.length;n++)t.indexOf(a[n])<0&&Object.prototype.propertyIsEnumerable.call(e,a[n])&&(r[a[n]]=e[a[n]]);return r}function P(){}function K(e){return!!(e||"").match(/\d/)}function x(e){return null==e}function D(e){return"number"==typeof e&&isNaN(e)}function m(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}function d(e,t,r){var r=function(e){switch(e){case"lakh":return/(\d+?)(?=(\d\d)+(\d)(?!\d))(\.\d+)?/g;case"wan":return/(\d)(?=(\d{4})+(?!\d))/g;default:return/(\d)(?=(\d{3})+(?!\d))/g}}(r),n=-1===(n=e.search(/[1-9]/))?e.length:n;return e.substring(0,n)+e.substring(n,e.length).replace(r,"$1"+t)}function g(e,t){void 0===t&&(t=!0);var r="-"===e[0],t=r&&t,e=(e=e.replace("-","")).split(".");return{beforeDecimal:e[0],afterDecimal:e[1]||"",hasNegation:r,addNegation:t}}function v(e,t,r){for(var n="",a=r?"0":"",o=0;o<=t-1;o++)n+=e[o]||a;return n}function a(e,t){return Array(t+1).join(e)}function O(e){var t,e=e+"",r="-"===e[0]?"-":"",e=(e=r?e.substring(1):e).split(/[eE]/g),n=e[0],e=e[1];return(e=Number(e))&&(e=1+e,t=(n=n.replace(".","")).length,e<0?n="0."+a("0",Math.abs(e))+n:t<=e?n+=a("0",e-t):n=(n.substring(0,e)||"0")+"."+n.substring(e)),r+n}function V(e,t,r){var n,a,o,u;return-1!==["","-"].indexOf(e)?e:(n=(-1!==e.indexOf(".")||r)&&t,a=(e=g(e)).beforeDecimal,u=e.afterDecimal,e=e.hasNegation,o=parseFloat("0."+(u||"0")),u=(u.length<=t?"0."+u:o.toFixed(t)).split("."),(e?"-":"")+a.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])+(n?".":"")+v(u[1]||"",t,r))}function L(e,t){var r;e.value=e.value,null!==e&&(e.createTextRange?((r=e.createTextRange()).move("character",t),r.select()):e.selectionStart||0===e.selectionStart?(e.focus(),e.setSelectionRange(t,t)):e.focus())}function W(e){return Math.max(e.selectionStart,e.selectionEnd)}function p(e){return{from:{start:0,end:0},to:{start:0,end:e.length},lastValue:""}}function h(e,t){return"string"==typeof(e=void 0===e?" ":e)?e:e[t]||" "}function U(e,t,r,n){var a,o,u=e.length;if(e=t,a=0,o=u,t=Math.min(Math.max(e,a),o),"left"===n){for(;0<=t&&!r[t];)t--;-1===t&&(t=r.indexOf(!0))}else{for(;t<=u&&!r[t];)t++;u<t&&(t=r.lastIndexOf(!0))}return t=-1===t?u:t}function G(e){for(var t=Array.from({length:e.length+1}).map(function(){return!0}),r=0,n=t.length;r<n;r++)t[r]=Boolean(K(e[r])||K(e[r-1]));return t}function $(e,t,r,n,a,o){void 0===o&&(o=P);var u,i=R.useRef(),l=(c=function(e){var t,e=x(e)||D(e)?t="":"number"==typeof e||r?(t="number"==typeof e?O(e):e,n(t)):(t=a(e,void 0),e);return{formattedValue:e,numAsString:t}},(u=R.useRef(c)).current=c,R.useRef(function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];return u.current.apply(u,e)}).current),c=R.useState(function(){return l(t)}),s=c[0],f=c[1];return R.useMemo(function(){x(e)?i.current=void 0:(i.current=l(e),f(i.current))},[e,l]),[s,function(e,t){f({formattedValue:e.formattedValue,numAsString:e.value}),o(e,t)}]}function Z(e){return e.replace(/[^0-9]/g,"")}function _(e){return e}function r(e){function i(e,t,r){return U(e,t,b(e),r)}function r(e,t,r){var n,a,o=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{from:{start:r,end:a-n},to:{start:r,end:o-n}}}(x,e),o=Object.assign(Object.assign({},o),{lastValue:x}),o=c(e,o),u=F(o),o=c(u,void 0);return m&&!m(B(u,o))?(a=W(n=t.target),a=A(e,x,a),j(n,a,x),!1):(T({formattedValue:u,numAsString:o,inputValue:e,event:t,source:r,setCaretPosition:!0,input:t.target}),!0)}var t=e.type,n=(void 0===t&&(t="text"),e.displayType),a=(void 0===n&&(n="input"),e.customInput),o=e.renderText,u=e.getInputRef,l=e.format,c=(void 0===l&&(l=_),e.removeFormatting),s=(void 0===c&&(c=Z),e.defaultValue),f=e.valueIsNumericString,d=e.onValueChange,m=e.isAllowed,g=e.onChange,v=(void 0===g&&(g=P),e.onKeyDown),p=(void 0===v&&(v=P),e.onMouseUp),h=(void 0===p&&(p=P),e.onFocus),S=(void 0===h&&(h=P),e.onBlur),y=(void 0===S&&(S=P),e.value),b=e.getCaretBoundary,w=(void 0===b&&(b=G),e.isValidInputCharacter),e=(void 0===w&&(w=K),I(e,["type","displayType","customInput","renderText","getInputRef","format","removeFormatting","defaultValue","valueIsNumericString","onValueChange","isAllowed","onChange","onKeyDown","onMouseUp","onFocus","onBlur","value","getCaretBoundary","isValidInputCharacter"])),y=$(y,s,Boolean(f),l,c,d),s=y[0],x=s.formattedValue,D=s.numAsString,O=y[1],V=R.useRef(),f=(R.useEffect(function(){var e,t,r=l(D);void 0!==V.current&&r===V.current||(e=N.current,t=c(r,void 0),T({formattedValue:r,numAsString:t,input:e,setCaretPosition:!0,source:k.props,event:void 0}))}),R.useState(!1)),d=f[0],C=f[1],N=R.useRef(null),E=R.useRef({setCaretTimeout:null,focusTimeout:null}),F=(R.useEffect(function(){return C(!0),function(){clearTimeout(E.current.setCaretTimeout),clearTimeout(E.current.focusTimeout)}},[]),l),B=function(e,t){var r=parseFloat(t);return{formattedValue:e,value:t,floatValue:isNaN(r)?void 0:r}},j=function(e,t,r){L(e,t),E.current.setCaretTimeout=setTimeout(function(){e.value===r&&L(e,t)},0)},A=function(e,t,r){var n=b(t);return U(t,function(e,t,r,n,a,o){for(var a=a.findIndex(function(e){return e}),a=e.slice(0,a),u=(t||r.startsWith(a)||(r=a+r,n+=a.length),r.length),i=e.length,l={},c=new Array(u),s=0;s<u;s++){c[s]=-1;for(var f=0,d=i;f<d;f++)if(r[s]===e[f]&&!0!==l[f]){l[c[s]=f]=!0;break}}for(var m=n;m<u&&(-1===c[m]||!o(r[m]));)m++;for(t=m===u||-1===c[m]?i:c[m],m=n-1;0<m&&-1===c[m];)m--;return a=-1===m||-1===c[m]?0:c[m]+1,!(t<a)&&n-a<t-n?a:t}(t,x,e,r,n,w),n)},T=function(e){var t,r=e.formattedValue,n=(void 0===r&&(r=""),e.input),a=e.setCaretPosition,o=(void 0===a&&(a=!0),e.source),u=e.event,i=e.numAsString,l=e.caretPos;n&&(void 0===l&&a&&(e=e.inputValue||n.value,t=W(n),n.value=r,l=A(e,r,t)),n.value=r,a&&void 0!==l&&j(n,l,r)),r!==x&&(e=B(r,i),t={event:u,source:o},V.current=e.formattedValue,O(e,t))},s=d&&!("undefined"==typeof navigator||navigator.platform&&/iPhone|iPod/.test(navigator.platform))?"numeric":void 0,y=Object.assign({inputMode:s},e,{type:t,value:x,onChange:function(e){var t=e.target.value;r(t,e,k.event)&&g(e)},onKeyDown:function(e){var t,r=e.target,n=e.key,a=r.selectionStart,o=r.selectionEnd,u=r.value;void 0===u&&(u=""),"ArrowLeft"===n||"Backspace"===n?t=Math.max(a-1,0):"ArrowRight"===n?t=Math.min(a+1,u.length):"Delete"===n&&(t=a),void 0!==t&&a===o&&(a=t,"ArrowLeft"===n||"ArrowRight"===n?a=i(u,t,"ArrowLeft"===n?"left":"right"):"Delete"!==n||w(u[t])?"Backspace"!==n||w(u[t])||(a=i(u,t,"left")):a=i(u,t,"right"),a!==t&&j(r,a,u),e.isUnitTestRun&&j(r,a,u)),v(e)},onMouseUp:function(e){var t=e.target,r=t.selectionStart,n=t.selectionEnd,a=t.value;void 0===a&&(a=""),r===n&&(n=i(a,r))!==r&&j(t,n,a),p(e)},onFocus:function(a){a.persist&&a.persist();var o=a.target;N.current=o,E.current.focusTimeout=setTimeout(function(){var e=o.selectionStart,t=o.selectionEnd,r=o.value,n=i(r=void 0===r?"":r,e);n===e||0===e&&t===r.length||j(o,n,r),h(a)},0)},onBlur:function(e){N.current=null,clearTimeout(E.current.focusTimeout),clearTimeout(E.current.setCaretTimeout),S(e)}});return"text"===n?o?M.createElement(M.Fragment,null,o(x,e)||null):M.createElement("span",Object.assign({},e,{ref:u}),x):a?M.createElement(a,Object.assign({},y,{ref:u})):M.createElement("input",Object.assign({},y,{ref:u}))}function C(e,t){var r,n,a,o,u=t.decimalScale,i=t.fixedDecimalScale,l=t.prefix,c=(void 0===l&&(l=""),t.suffix),s=(void 0===c&&(c=""),t.allowNegative),f=(void 0===s&&(s=!0),t.thousandsGroupStyle);return void 0===f&&(f="thousand"),""!==e&&"-"!==e&&(r=(t=N(t)).thousandSeparator,t=t.decimalSeparator,n=0!==u&&-1!==e.indexOf(".")||u&&i,a=(s=g(e,s)).beforeDecimal,o=s.afterDecimal,s=s.addNegation,void 0!==u&&(o=v(o,u,!!i)),r&&(a=d(a,r,f)),l&&(a=l+a),c&&(o+=c),e=(a=s?"-"+a:a)+(n&&t||"")+o),e}function N(e){var t=e.decimalSeparator,r=e.thousandSeparator,e=e.allowedDecimalSeparators;return{decimalSeparator:t=void 0===t?".":t,thousandSeparator:r=!0===r?",":r,allowedDecimalSeparators:e=e||[t,"."]}}function E(e,t,r){void 0===t&&(t=p(e));var n=r.allowNegative,a=(void 0===n&&(n=!0),r.prefix),o=(void 0===a&&(a=""),r.suffix),u=(void 0===o&&(o=""),r.decimalScale),i=t.from,t=t.to,l=t.start,c=t.end,r=N(r),s=r.allowedDecimalSeparators,r=r.decimalSeparator,f=e[c]===r,u=(c-l==1&&-1!==s.indexOf(e[l])&&(s=0===u?"":r,e=e.substring(0,l)+s+e.substring(l+1,e.length)),!1),s=(a.startsWith("-")?u=e.startsWith("--"):o.startsWith("-")&&e.length===o.length?u=!1:"-"===e[0]&&(u=!0),u&&(e=e.substring(1),--l,--c),0),a=(e.startsWith(a)?s+=a.length:l<a.length&&(s=l),c-=s,(e=e.substring(s)).length),l=e.length-o.length,d=(e.endsWith(o)?a=l:c>e.length-o.length&&(a=c),e=e.substring(0,a),s=n,void 0===(l=u?"-"+e:e)&&(l=""),o=new RegExp("(-)"),c=new RegExp("(-)(.)*(-)"),o=o.test(l),c=c.test(l),l=l.replace(/-/g,""),(e=((e=l=o&&!c&&s?"-"+l:l).match((a=!0,new RegExp("(^-)|[0-9]|"+m(r),a?"g":void 0)))||[]).join("")).indexOf(r)),u=g(e=e.replace(new RegExp(m(r),"g"),function(e,t){return t===d?".":""}),n),o=u.beforeDecimal,c=u.afterDecimal,s=u.addNegation;return e=t.end-t.start<i.end-i.start&&""===o&&f&&!parseFloat(c)?s?"-":"":e}function F(e,t){var r=t.prefix,t=(void 0===r&&(r=""),t.suffix),n=(void 0===t&&(t=""),Array.from({length:e.length+1}).map(function(){return!0})),a="-"===e[0],r=(n.fill(!1,0,r.length+(a?1:0)),e.length);return n.fill(!1,r-t.length+1,r+1),n}function n(i){var t=i.decimalSeparator,a=(void 0===t&&(t="."),i.allowedDecimalSeparators,i.thousandsGroupStyle,i.suffix,i.allowNegative,i.allowLeadingZeros),l=i.onKeyDown,o=(void 0===l&&(l=P),i.onBlur),c=(void 0===o&&(o=P),i.thousandSeparator),s=i.decimalScale,f=i.fixedDecimalScale,d=i.prefix,e=(void 0===d&&(d=""),i.defaultValue),r=i.value,n=i.valueIsNumericString,u=i.onValueChange,m=I(i,["decimalSeparator","allowedDecimalSeparators","thousandsGroupStyle","suffix","allowNegative","allowLeadingZeros","onKeyDown","onBlur","thousandSeparator","decimalScale","fixedDecimalScale","prefix","defaultValue","value","valueIsNumericString","onValueChange"]),g=(v=N(v=i)).thousandSeparator,v=v.decimalSeparator;if(g===v)throw new Error("\n Decimal separator can't be same as thousand separator.\n thousandSeparator: "+g+' (thousandSeparator = {true} is same as thousandSeparator = ",")\n decimalSeparator: '+v+" (default value for decimalSeparator is .)\n ");function p(e){return C(e,i)}function h(e,t){return E(e,t,i)}function S(e){return!x(e)&&!D(e)&&("number"==typeof e&&(e=O(e)),y&&"number"==typeof s)?V(e,s,Boolean(f)):e}var y=n,g=(x(r)?x(e)||(y=null!=n?n:"number"==typeof e):y=null!=n?n:"number"==typeof r,$(S(r),S(e),Boolean(y),p,h,u)),v=g[0],b=v.numAsString,n=v.formattedValue,w=g[1];return Object.assign(Object.assign({},m),{value:n,valueIsNumericString:!1,isValidInputCharacter:function(e){return e===t||K(e)},onValueChange:w,format:p,removeFormatting:h,getCaretBoundary:function(e){return F(e,i)},onKeyDown:function(e){var t,r=e.target,n=e.key,a=r.selectionStart,o=r.selectionEnd,u=r.value;void 0===u&&(u=""),a===o&&("Backspace"===n&&"-"===u[0]&&a===d.length+1&&L(r,1),t=(o=N(i)).decimalSeparator,o=o.allowedDecimalSeparators,"Backspace"===n&&u[a-1]===t&&s&&f&&(L(r,a-1),e.preventDefault()),null!=o&&o.includes(n)&&u[a]===t&&L(r,a+1),o=!0===c?",":c,"Backspace"===n&&u[a-1]===o&&L(r,a-1),"Delete"===n&&u[a]===o&&L(r,a+1)),l(e)},onBlur:function(e){var t,r,n=b;n.match(/\d/g)||(n=""),a||(n=(r=n)&&((t="-"===r[0])?"-":"")+((t=(r=t?r.substring(1,r.length):r).split("."))[0].replace(/^0+/,"")||"0")+((t=t[1]||"")?"."+t:"")),(n=f&&s?V(n,s,f):n)!==b&&(r=C(n,i),w({formattedValue:r,value:n,floatValue:parseFloat(n)},{event:e,source:k.event})),o(e)}})}function o(e,t){var r=t.format,n=t.allowEmptyFormatting,a=t.mask,o=t.patternChar;if(void 0===o&&(o="#"),""===e&&!n)return"";for(var u=0,i=r.split(""),l=0,c=r.length;l<c;l++)r[l]===o&&(i[l]=e[u]||h(a,u),u+=1);return i.join("")}function u(e,t,r){void 0===t&&(t=p(e));function a(e){return u[e]===i}function n(e,t){for(var r="",n=0;n<e.length;n++)a(t+n)&&K(e[n])&&(r+=e[n]);return r}function o(e){return e.replace(/[^0-9]/g,"")}var u=r.format,i=r.patternChar,r=(void 0===i&&(i="#"),t.from),l=t.to,t=t.lastValue;void 0===t&&(t="");if(!u.match(/\d/))return o(e);if(""===t&&e.length===u.length){for(var c="",s=0;s<e.length;s++)if(a(s))K(e[s])&&(c+=e[s]);else if(e[s]!==u[s])return o(e);return c}var f=t.substring(0,r.start),l=e.substring(l.start,l.end),t=t.substring(r.end);return""+n(f,0)+o(l)+n(t,r.end)}function i(n,e){for(var t=e.format,a=e.mask,o=e.patternChar,r=(void 0===o&&(o="#"),Array.from({length:n.length+1}).map(function(){return!0})),u=0,i=-1,l={},c=(t.split("").forEach(function(e,t){var r=void 0;e===o&&(r=h(a,++u-1),-1===i&&n[t]===r&&(i=t)),l[t]=r}),function(e){return t[e]===o&&n[e]!==l[e]}),s=0,f=r.length;s<f;s++)r[s]=s===i||c(s)||c(s-1);return r[t.indexOf(o)]=!0,r}function l(r){r.mask,r.allowEmptyFormatting;var l=r.format,e=r.inputMode,c=(void 0===e&&(e="numeric"),r.onKeyDown),s=(void 0===c&&(c=P),r.patternChar),t=(void 0===s&&(s="#"),I(r,["mask","allowEmptyFormatting","format","inputMode","onKeyDown","patternChar"])),n=r;if((n=n.mask)&&("string"===n?n:n.toString()).match(/\d/g))throw new Error("Mask "+n+" should not contain numeric character;");function f(e){return i(e,r)}return Object.assign(Object.assign({},t),{inputMode:e,format:function(e){return o(e,r)},removeFormatting:function(e,t){return u(e,t,r)},getCaretBoundary:f,onKeyDown:function(e){var t=e.key,r=e.target,n=r.selectionStart,a=r.selectionEnd,o=r.value;if(n===a){var u=n;if("Backspace"===t||"Delete"===t){a="right";if("Backspace"===t){for(;0<u&&l[u-1]!==s;)u--;a="left"}else{for(var i=l.length;u<i&&l[u]!==s;)u++;a="right"}u=U(o,u,f(o),a)}else l[u]!==s&&"ArrowLeft"!==t&&"ArrowRight"!==t&&(u=U(o,u+1,f(o),"right"));u!==n&&L(r,u)}c(e)}})}(t=k=k||{}).event="event",t.props="prop",e.NumberFormatBase=r,e.NumericFormat=function(e){return e=n(e),M.createElement(r,Object.assign({},e))},e.PatternFormat=function(e){return e=l(e),M.createElement(r,Object.assign({},e))},e.getNumericCaretBoundary=F,e.getPatternCaretBoundary=i,e.numericFormatter=C,e.patternFormatter=o,e.removeNumericFormat=E,e.removePatternFormat=u,e.useNumericFormat=n,e.usePatternFormat=l,Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).NumberFormat={},e.React)}(this,function(e,R){"use strict";var k,t,M="default"in R?R.default:R;function I(e,t){var r={};for(a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(r[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var n=0,a=Object.getOwnPropertySymbols(e);n<a.length;n++)t.indexOf(a[n])<0&&Object.prototype.propertyIsEnumerable.call(e,a[n])&&(r[a[n]]=e[a[n]]);return r}function P(){}function K(e){return!!(e||"").match(/\d/)}function w(e){return null==e}function x(e){return"number"==typeof e&&isNaN(e)}function h(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}function d(e,t,r){var r=function(e){switch(e){case"lakh":return/(\d+?)(?=(\d\d)+(\d)(?!\d))(\.\d+)?/g;case"wan":return/(\d)(?=(\d{4})+(?!\d))/g;default:return/(\d)(?=(\d{3})+(?!\d))/g}}(r),n=-1===(n=e.search(/[1-9]/))?e.length:n;return e.substring(0,n)+e.substring(n,e.length).replace(r,"$1"+t)}function S(e,t){void 0===t&&(t=!0);var r="-"===e[0],t=r&&t,e=(e=e.replace("-","")).split(".");return{beforeDecimal:e[0],afterDecimal:e[1]||"",hasNegation:r,addNegation:t}}function g(e,t,r){for(var n="",a=r?"0":"",o=0;o<=t-1;o++)n+=e[o]||a;return n}function a(e,t){return Array(t+1).join(e)}function N(e){var t,e=e+"",r="-"===e[0]?"-":"",e=(e=r?e.substring(1):e).split(/[eE]/g),n=e[0],e=e[1];return(e=Number(e))&&(e=1+e,t=(n=n.replace(".","")).length,e<0?n="0."+a("0",Math.abs(e))+n:t<=e?n+=a("0",e-t):n=(n.substring(0,e)||"0")+"."+n.substring(e)),r+n}function D(e,t,r){var n,a,o,i;return-1!==["","-"].indexOf(e)?e:(n=(-1!==e.indexOf(".")||r)&&t,a=(e=S(e)).beforeDecimal,i=e.afterDecimal,e=e.hasNegation,o=parseFloat("0."+(i||"0")),i=(i.length<=t?"0."+i:o.toFixed(t)).split("."),(e?"-":"")+a.split("").reverse().reduce(function(e,t,r){return e.length>r?(Number(e[0])+Number(t)).toString()+e.substring(1,e.length):t+e},i[0])+(n?".":"")+g(i[1]||"",t,r))}function W(e,t){var r;e.value=e.value,null!==e&&(e.createTextRange?((r=e.createTextRange()).move("character",t),r.select()):e.selectionStart||0===e.selectionStart?(e.focus(),e.setSelectionRange(t,t)):e.focus())}function L(e){return Math.max(e.selectionStart,e.selectionEnd)}function y(e){return{from:{start:0,end:0},to:{start:0,end:e.length},lastValue:""}}function m(e,t){return"string"==typeof(e=void 0===e?" ":e)?e:e[t]||" "}function U(e,t,r,n){var a,o,i=e.length;if(e=t,a=0,o=i,t=Math.min(Math.max(e,a),o),"left"===n){for(;0<=t&&!r[t];)t--;-1===t&&(t=r.indexOf(!0))}else{for(;t<=i&&!r[t];)t++;i<t&&(t=r.lastIndexOf(!0))}return t=-1===t?i:t}function G(e){for(var t=Array.from({length:e.length+1}).map(function(){return!0}),r=0,n=t.length;r<n;r++)t[r]=Boolean(K(e[r])||K(e[r-1]));return t}function $(e,t,r,n,a,o){void 0===o&&(o=P);var i,u=R.useRef(),l=(s=function(e){var t,e=w(e)||x(e)?t="":"number"==typeof e||r?(t="number"==typeof e?N(e):e,n(t)):(t=a(e,void 0),e);return{formattedValue:e,numAsString:t}},(i=R.useRef(s)).current=s,R.useRef(function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];return i.current.apply(i,e)}).current),s=R.useState(function(){return l(t)}),c=s[0],f=s[1];return R.useMemo(function(){w(e)?u.current=void 0:(u.current=l(e),f(u.current))},[e,l]),[c,function(e,t){f({formattedValue:e.formattedValue,numAsString:e.value}),o(e,t)}]}function Z(e){return e.replace(/[^0-9]/g,"")}function _(e){return e}function r(e){function u(e,t,r){return U(e,t,b(e),r)}function r(e,t,r){var n,a,o=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{from:{start:r,end:a-n},to:{start:r,end:o-n}}}(x,e),o=Object.assign(Object.assign({},o),{lastValue:x}),o=s(e,o),i=F(o),o=s(i,void 0);return g&&!g(B(i,o))?(a=L(n=t.target),a=A(e,x,a),j(n,a,x),!1):(T({formattedValue:i,numAsString:o,inputValue:e,event:t,source:r,setCaretPosition:!0,input:t.target}),!0)}var t=e.type,n=(void 0===t&&(t="text"),e.displayType),a=(void 0===n&&(n="input"),e.customInput),o=e.renderText,i=e.getInputRef,l=e.format,s=(void 0===l&&(l=_),e.removeFormatting),c=(void 0===s&&(s=Z),e.defaultValue),f=e.valueIsNumericString,d=e.onValueChange,g=e.isAllowed,m=e.onChange,v=(void 0===m&&(m=P),e.onKeyDown),p=(void 0===v&&(v=P),e.onMouseUp),h=(void 0===p&&(p=P),e.onFocus),S=(void 0===h&&(h=P),e.onBlur),y=(void 0===S&&(S=P),e.value),b=e.getCaretBoundary,w=(void 0===b&&(b=G),e.isValidInputCharacter),e=(void 0===w&&(w=K),I(e,["type","displayType","customInput","renderText","getInputRef","format","removeFormatting","defaultValue","valueIsNumericString","onValueChange","isAllowed","onChange","onKeyDown","onMouseUp","onFocus","onBlur","value","getCaretBoundary","isValidInputCharacter"])),y=$(y,c,Boolean(f),l,s,d),c=y[0],x=c.formattedValue,N=c.numAsString,D=y[1],O=R.useRef(),f=(R.useEffect(function(){var e,t,r=l(N);void 0!==O.current&&r===O.current||(e=C.current,t=s(r,void 0),T({formattedValue:r,numAsString:t,input:e,setCaretPosition:!0,source:k.props,event:void 0}))}),R.useState(!1)),d=f[0],V=f[1],C=R.useRef(null),E=R.useRef({setCaretTimeout:null,focusTimeout:null}),F=(R.useEffect(function(){return V(!0),function(){clearTimeout(E.current.setCaretTimeout),clearTimeout(E.current.focusTimeout)}},[]),l),B=function(e,t){var r=parseFloat(t);return{formattedValue:e,value:t,floatValue:isNaN(r)?void 0:r}},j=function(e,t,r){W(e,t),E.current.setCaretTimeout=setTimeout(function(){e.value===r&&W(e,t)},0)},A=function(e,t,r){var n=b(t);return U(t,function(e,t,r,n,a,o){for(var a=a.findIndex(function(e){return e}),a=e.slice(0,a),i=(t||r.startsWith(a)||(r=a+r,n+=a.length),r.length),u=e.length,l={},s=new Array(i),c=0;c<i;c++){s[c]=-1;for(var f=0,d=u;f<d;f++)if(r[c]===e[f]&&!0!==l[f]){l[s[c]=f]=!0;break}}for(var g=n;g<i&&(-1===s[g]||!o(r[g]));)g++;for(t=g===i||-1===s[g]?u:s[g],g=n-1;0<g&&-1===s[g];)g--;return a=-1===g||-1===s[g]?0:s[g]+1,!(t<a)&&n-a<t-n?a:t}(t,x,e,r,n,w),n)},T=function(e){var t,r=e.formattedValue,n=(void 0===r&&(r=""),e.input),a=e.setCaretPosition,o=(void 0===a&&(a=!0),e.source),i=e.event,u=e.numAsString,l=e.caretPos;n&&(void 0===l&&a&&(e=e.inputValue||n.value,t=L(n),n.value=r,l=A(e,r,t)),n.value=r,a&&void 0!==l&&j(n,l,r)),r!==x&&(e=B(r,u),t={event:i,source:o},O.current=e.formattedValue,D(e,t))},c=d&&!("undefined"==typeof navigator||navigator.platform&&/iPhone|iPod/.test(navigator.platform))?"numeric":void 0,y=Object.assign({inputMode:c},e,{type:t,value:x,onChange:function(e){var t=e.target.value;r(t,e,k.event)&&m(e)},onKeyDown:function(e){var t,r=e.target,n=e.key,a=r.selectionStart,o=r.selectionEnd,i=r.value;void 0===i&&(i=""),"ArrowLeft"===n||"Backspace"===n?t=Math.max(a-1,0):"ArrowRight"===n?t=Math.min(a+1,i.length):"Delete"===n&&(t=a),void 0!==t&&a===o&&(a=t,"ArrowLeft"===n||"ArrowRight"===n?a=u(i,t,"ArrowLeft"===n?"left":"right"):"Delete"!==n||w(i[t])?"Backspace"!==n||w(i[t])||(a=u(i,t,"left")):a=u(i,t,"right"),a!==t&&j(r,a,i),e.isUnitTestRun&&j(r,a,i)),v(e)},onMouseUp:function(e){var t=e.target,r=t.selectionStart,n=t.selectionEnd,a=t.value;void 0===a&&(a=""),r===n&&(n=u(a,r))!==r&&j(t,n,a),p(e)},onFocus:function(a){a.persist&&a.persist();var o=a.target;C.current=o,E.current.focusTimeout=setTimeout(function(){var e=o.selectionStart,t=o.selectionEnd,r=o.value,n=u(r=void 0===r?"":r,e);n===e||0===e&&t===r.length||j(o,n,r),h(a)},0)},onBlur:function(e){C.current=null,clearTimeout(E.current.focusTimeout),clearTimeout(E.current.setCaretTimeout),S(e)}});return"text"===n?o?M.createElement(M.Fragment,null,o(x,e)||null):M.createElement("span",Object.assign({},e,{ref:i}),x):a?M.createElement(a,Object.assign({},y,{ref:i})):M.createElement("input",Object.assign({},y,{ref:i}))}function O(e,t){var r,n,a,o,i=t.decimalScale,u=t.fixedDecimalScale,l=t.prefix,s=(void 0===l&&(l=""),t.suffix),c=(void 0===s&&(s=""),t.allowNegative),f=t.thousandsGroupStyle;return void 0===f&&(f="thousand"),""!==e&&"-"!==e&&(r=(t=V(t)).thousandSeparator,t=t.decimalSeparator,n=0!==i&&-1!==e.indexOf(".")||i&&u,a=(c=S(e,c)).beforeDecimal,o=c.afterDecimal,c=c.addNegation,void 0!==i&&(o=g(o,i,!!u)),r&&(a=d(a,r,f)),l&&(a=l+a),s&&(o+=s),e=(a=c?"-"+a:a)+(n&&t||"")+o),e}function V(e){var t=e.decimalSeparator,r=e.thousandSeparator,e=e.allowedDecimalSeparators;return{decimalSeparator:t=void 0===t?".":t,thousandSeparator:r=!0===r?",":r,allowedDecimalSeparators:e=e||[t,"."]}}function C(e,t,r){void 0===t&&(t=y(e));var n,a,o,i,u=r.allowNegative,l=r.prefix,s=(void 0===l&&(l=""),r.suffix),c=(void 0===s&&(s=""),r.decimalScale),f=t.from,d=t.to,g=d.start,m=d.end,r=V(r),v=r.allowedDecimalSeparators,r=r.decimalSeparator,p=e[m]===r;return K(e)&&(e===l||e===s)&&""===t.lastValue||(m-g==1&&-1!==v.indexOf(e[g])&&(v=0===c?"":r,e=e.substring(0,g)+v+e.substring(g+1,e.length)),v=(c=function(e,t,r){var n=!1,a=!1,o=(l.startsWith("-")?n=!1:e.startsWith("--")?a=!(n=!1):s.startsWith("-")&&e.length===s.length?n=!1:"-"===e[0]&&(n=!0),n?1:0);return(o=a?2:o)&&(e=e.substring(o),t-=o,r-=o),{value:e,start:t,end:r,hasNegation:n}})(e,g,m),i=v.hasNegation,e=v.value,g=v.start,m=v.end,c=(v=c(t.lastValue,f.start,f.end)).start,t=v.end,v=v.value,n=e.substring(g,m),a=0,(e=!(e.length&&v.length&&(c>v.length-s.length||t<l.length))||n&&s.startsWith(n)?e:v).startsWith(l)?a+=l.length:g<l.length&&(a=g),m-=a,c=(e=e.substring(a)).length,t=e.length-s.length,e.endsWith(s)?c=t:(t<m||m>e.length-s.length)&&(c=m),e=e.substring(0,c),n=u,void 0===(v=i?"-"+e:e)&&(v=""),g=new RegExp("(-)"),a=new RegExp("(-)(.)*(-)"),g=g.test(v),a=a.test(v),v=v.replace(/-/g,""),o=(e=((e=v=g&&!a&&n?"-"+v:v).match((t=!0,new RegExp("(^-)|[0-9]|"+h(r),t?"g":void 0)))||[]).join("")).indexOf(r),c=(m=S(e=e.replace(new RegExp(h(r),"g"),function(e,t){return t===o?".":""}),u)).beforeDecimal,i=m.afterDecimal,g=m.addNegation,d.end-d.start<f.end-f.start&&""===c&&p&&!parseFloat(i)&&(e=g?"-":"")),e}function E(e,t){var r=t.prefix,t=(void 0===r&&(r=""),t.suffix),n=(void 0===t&&(t=""),Array.from({length:e.length+1}).map(function(){return!0})),a="-"===e[0],r=(n.fill(!1,0,r.length+(a?1:0)),e.length);return n.fill(!1,r-t.length+1,r+1),n}function n(u){function e(e){return O(e,u)}function t(e,t){return C(e,t,u)}function r(e){return!w(e)&&!x(e)&&("number"==typeof e&&(e=N(e)),S&&"number"==typeof f)?D(e,f,Boolean(d)):e}var n=(u=function(e){var t=(r=V(e)).thousandSeparator,r=r.decimalSeparator,n=e.prefix,a=(void 0===n&&(n=""),e.allowNegative);if(void 0===a&&(a=!0),t===r)throw new Error("\n Decimal separator can't be same as thousand separator.\n thousandSeparator: "+t+' (thousandSeparator = {true} is same as thousandSeparator = ",")\n decimalSeparator: '+r+" (default value for decimalSeparator is .)\n ");return n.startsWith("-")&&a&&(console.error("\n Prefix can't start with '-' when allowNegative is true.\n prefix: "+n+"\n allowNegative: "+a+"\n "),a=!1),Object.assign(Object.assign({},e),{allowNegative:a})}(u)).decimalSeparator,l=(void 0===n&&(n="."),u.allowedDecimalSeparators,u.thousandsGroupStyle,u.suffix,u.allowNegative),a=u.allowLeadingZeros,s=u.onKeyDown,o=(void 0===s&&(s=P),u.onBlur),c=(void 0===o&&(o=P),u.thousandSeparator),f=u.decimalScale,d=u.fixedDecimalScale,g=u.prefix,i=(void 0===g&&(g=""),u.defaultValue),m=u.value,v=u.valueIsNumericString,p=u.onValueChange,h=I(u,["decimalSeparator","allowedDecimalSeparators","thousandsGroupStyle","suffix","allowNegative","allowLeadingZeros","onKeyDown","onBlur","thousandSeparator","decimalScale","fixedDecimalScale","prefix","defaultValue","value","valueIsNumericString","onValueChange"]),S=v,v=(w(m)?w(i)||(S=null!=v?v:"number"==typeof i):S=null!=v?v:"number"==typeof m,$(r(m),r(i),Boolean(S),e,t,p)),m=v[0],y=m.numAsString,i=m.formattedValue,b=v[1];return Object.assign(Object.assign({},h),{value:i,valueIsNumericString:!1,isValidInputCharacter:function(e){return e===n||K(e)},onValueChange:b,format:e,removeFormatting:t,getCaretBoundary:function(e){return E(e,u)},onKeyDown:function(e){var t,r=e.target,n=e.key,a=r.selectionStart,o=r.selectionEnd,i=r.value;void 0===i&&(i=""),a===o&&("Backspace"===n&&"-"===i[0]&&a===g.length+1&&l&&W(r,1),t=(o=V(u)).decimalSeparator,o=o.allowedDecimalSeparators,"Backspace"===n&&i[a-1]===t&&f&&d&&(W(r,a-1),e.preventDefault()),null!=o&&o.includes(n)&&i[a]===t&&W(r,a+1),o=!0===c?",":c,"Backspace"===n&&i[a-1]===o&&W(r,a-1),"Delete"===n&&i[a]===o&&W(r,a+1)),s(e)},onBlur:function(e){var t,r,n=y;n.match(/\d/g)||(n=""),a||(n=(r=n)&&((t="-"===r[0])?"-":"")+((t=(r=t?r.substring(1,r.length):r).split("."))[0].replace(/^0+/,"")||"0")+((t=t[1]||"")?"."+t:"")),(n=d&&f?D(n,f,d):n)!==y&&(r=O(n,u),b({formattedValue:r,value:n,floatValue:parseFloat(n)},{event:e,source:k.event})),o(e)}})}function o(e,t){var r=t.format,n=t.allowEmptyFormatting,a=t.mask,o=t.patternChar;if(void 0===o&&(o="#"),""===e&&!n)return"";for(var i=0,u=r.split(""),l=0,s=r.length;l<s;l++)r[l]===o&&(u[l]=e[i]||m(a,i),i+=1);return u.join("")}function i(e,t,r){void 0===t&&(t=y(e));function a(e){return i[e]===u}function n(e,t){for(var r="",n=0;n<e.length;n++)a(t+n)&&K(e[n])&&(r+=e[n]);return r}function o(e){return e.replace(/[^0-9]/g,"")}var i=r.format,u=r.patternChar,r=(void 0===u&&(u="#"),t.from),l=t.to,t=t.lastValue;void 0===t&&(t="");if(!i.match(/\d/))return o(e);if(""===t&&e.length===i.length){for(var s="",c=0;c<e.length;c++)if(a(c))K(e[c])&&(s+=e[c]);else if(e[c]!==i[c])return o(e);return s}var f=t.substring(0,r.start),l=e.substring(l.start,l.end),t=t.substring(r.end);return""+n(f,0)+o(l)+n(t,r.end)}function u(n,e){for(var t=e.format,a=e.mask,o=e.patternChar,r=(void 0===o&&(o="#"),Array.from({length:n.length+1}).map(function(){return!0})),i=0,u=-1,l={},s=(t.split("").forEach(function(e,t){var r=void 0;e===o&&(r=m(a,++i-1),-1===u&&n[t]===r&&(u=t)),l[t]=r}),function(e){return t[e]===o&&n[e]!==l[e]}),c=0,f=r.length;c<f;c++)r[c]=c===u||s(c)||s(c-1);return r[t.indexOf(o)]=!0,r}function l(r){r.mask,r.allowEmptyFormatting;var l=r.format,e=r.inputMode,s=(void 0===e&&(e="numeric"),r.onKeyDown),c=(void 0===s&&(s=P),r.patternChar),t=(void 0===c&&(c="#"),I(r,["mask","allowEmptyFormatting","format","inputMode","onKeyDown","patternChar"])),n=r;if((n=n.mask)&&("string"===n?n:n.toString()).match(/\d/g))throw new Error("Mask "+n+" should not contain numeric character;");function f(e){return u(e,r)}return Object.assign(Object.assign({},t),{inputMode:e,format:function(e){return o(e,r)},removeFormatting:function(e,t){return i(e,t,r)},getCaretBoundary:f,onKeyDown:function(e){var t=e.key,r=e.target,n=r.selectionStart,a=r.selectionEnd,o=r.value;if(n===a){var i=n;if("Backspace"===t||"Delete"===t){a="right";if("Backspace"===t){for(;0<i&&l[i-1]!==c;)i--;a="left"}else{for(var u=l.length;i<u&&l[i]!==c;)i++;a="right"}i=U(o,i,f(o),a)}else l[i]!==c&&"ArrowLeft"!==t&&"ArrowRight"!==t&&(i=U(o,i+1,f(o),"right"));i!==n&&W(r,i)}s(e)}})}(t=k=k||{}).event="event",t.props="prop",e.NumberFormatBase=r,e.NumericFormat=function(e){return e=n(e),M.createElement(r,Object.assign({},e))},e.PatternFormat=function(e){return e=l(e),M.createElement(r,Object.assign({},e))},e.getNumericCaretBoundary=E,e.getPatternCaretBoundary=u,e.numericFormatter=O,e.patternFormatter=o,e.removeNumericFormat=C,e.removePatternFormat=i,e.useNumericFormat=n,e.usePatternFormat=l,Object.defineProperty(e,"__esModule",{value:!0})});
{
"name": "react-number-format",
"description": "React component to format number in an input or as a text.",
"version": "5.1.3",
"version": "5.1.4",
"main": "dist/react-number-format.cjs.js",

@@ -111,4 +111,4 @@ "module": "dist/react-number-format.es.js",

"peerDependencies": {
"react": "^0.14 || ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 || ^18.0.0",
"react-dom": "^0.14 || ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 || ^18.0.0"
"react": "^0.14 || ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0",
"react-dom": "^0.14 || ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0"
},

@@ -115,0 +115,0 @@ "dependencies": {

@@ -5,3 +5,3 @@ [![Actions Status](https://github.com/s-yadav/react-number-format/workflows/CI/badge.svg)](https://github.com/s-yadav/react-number-format/actions)

React Number format is a input formatter library with a sohpisticated and light weight caret engine.
React Number format is a input formatter library with a sophisticated and lightweight caret engine.

@@ -8,0 +8,0 @@ ### Features

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc