New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-number-format

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-number-format - npm Package Compare versions

Comparing version 3.6.1 to 3.6.2

5

dist/react-number-format.es.js
/**
* react-number-format - 3.6.1
* react-number-format - 3.6.2
* Author : Sudhanshu Yadav

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

var otherProps = omit(this.props, propTypes$1);
var inputProps = Object.assign({}, otherProps, {
var inputProps = _extends({}, otherProps, {
type: type,

@@ -1373,0 +1374,0 @@ value: value,

/**
* react-number-format - 3.6.1
* react-number-format - 3.6.2
* Author : Sudhanshu Yadav

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

var otherProps = omit(this.props, propTypes$1);
var inputProps = Object.assign({}, otherProps, {
var inputProps = _extends({}, otherProps, {
type: type,

@@ -1379,0 +1380,0 @@ value: value,

4

dist/react-number-format.min.js
/**
* react-number-format - 3.6.1
* react-number-format - 3.6.2
* Author : Sudhanshu Yadav

@@ -8,2 +8,2 @@ * Copyright (c) 2016, 2018 to Sudhanshu Yadav, released under the MIT license.

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):e.NumberFormat=t(e.React)}(this,function(h){"use strict";function o(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 g(){return(g=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 i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function s(e,t){return(s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function u(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function e(e){return function(){return e}}h=h&&h.hasOwnProperty("default")?h.default:h;var t=function(){};t.thatReturns=e,t.thatReturnsFalse=e(!1),t.thatReturnsTrue=e(!0),t.thatReturnsNull=e(null),t.thatReturnsThis=function(){return this},t.thatReturnsArgument=function(e){return e};var n=t;var c=function(e,t,r,n,o,a,i,s){if(!e){var u;if(void 0===t)u=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[r,n,o,a,i,s],l=0;(u=new Error(t.replace(/%s/g,function(){return c[l++]}))).name="Invariant Violation"}throw u.framesToPop=1,u}},r=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable;(function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},r=0;r<10;r++)t["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var n={};return"abcdefghijklmnopqrst".split("").forEach(function(e){n[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},n)).join("")}catch(e){return!1}})()&&Object.assign;var f,p=(function(e){e.exports=function(){function e(e,t,r,n,o,a){"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"!==a&&c(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function t(){return e}var r={array:e.isRequired=e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return r.checkPropTypes=n,r.PropTypes=r}()}(f={exports:{}},f.exports),f.exports);function m(){}function v(e){return!!(e||"").match(/\d/)}function d(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}function P(e){var t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1],r="-"===e[0],n=r&&t,o=(e=e.replace("-","")).split(".");return{beforeDecimal:o[0],afterDecimal:o[1]||"",hasNagation:r,addNegation:n}}function y(e,t,r){for(var n="",o=r?"0":"",a=0;a<=t-1;a++)n+=e[a]||o;return n}function b(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 S(e,t,r){return Math.min(Math.max(e,t),r)}var x={thousandSeparator:p.oneOfType([p.string,p.oneOf([!0])]),decimalSeparator:p.string,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]),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"]),isAllowed:p.func,renderText:p.func,getInputRef:p.func},O={displayType:"input",decimalSeparator:".",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},w=function(e){function a(e){var t,r,n;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),r=this,(t=!(n=i(a).call(this,e))||"object"!=typeof n&&"function"!=typeof n?u(r):n).validateProps();var o=t.formatValueProp();return t.state={value:o,numAsString:t.removeFormatting(o)},t.selectionBeforeInput={selectionStart:0,selectionEnd:0},t.onChange=t.onChange.bind(u(u(t))),t.onKeyDown=t.onKeyDown.bind(u(u(t))),t.onMouseUp=t.onMouseUp.bind(u(u(t))),t.onFocus=t.onFocus.bind(u(u(t))),t.onBlur=t.onBlur.bind(u(u(t))),t}var t,r,n;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&&s(e,t)}(a,h.Component),t=a,(r=[{key:"componentDidUpdate",value:function(e){this.updateValueIfRequired(e)}},{key:"updateValueIfRequired",value:function(e){var t=this.props,r=this.state;if(e!==t){this.validateProps();var n=r.value,o=r.numAsString||"",a=this.formatNumString(o),i=void 0===t.value?a:this.formatValueProp(),s=this.removeFormatting(i),u=parseFloat(s),c=parseFloat(o);(isNaN(u)&&isNaN(c)||u===c)&&a===n||this.setState({value:i,numAsString:s})}}},{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),o="-"===e[0];o&&(e=e.replace("-","")),r&&0===t&&(e=e.split(r)[0]);var a=(e=(e.match(n)||[]).join("").replace(r,".")).indexOf(".");return-1!==a&&(e="".concat(e.substring(0,a),".").concat(e.substring(a+1,e.length).replace(new RegExp(d(r),"g"),""))),o&&(e="-"+e),e}},{key:"getNumberRegex",value:function(e,t){var r=this.props,n=r.format,o=r.decimalScale,a=this.getSeparators().decimalSeparator;return new RegExp("\\d"+(!a||0===o||t||n?"":"|"+d(a)),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){b(e,t),setTimeout(function(){e.value===r&&b(e,t)},0)}},{key:"correctCaretPosition",value:function(e,t,r){var n=this.props,o=n.prefix,a=n.suffix,i=n.format;if(""===e)return 0;if(t=S(t,0,e.length),!i){var s="-"===e[0];return S(t,o.length+(s?1:0),e.length-a.length)}if("function"==typeof i)return t;if("#"===i[t]&&v(e[t]))return t;if("#"===i[t-1]&&v(e[t-1]))return t;var u=i.indexOf("#");t=S(t,u,i.lastIndexOf("#")+1);for(var c=i.substring(t,i.length).indexOf("#"),l=t,f=t+(-1===c?0:c);u<l&&("#"!==i[l]||!v(e[l]));)l-=1;return!v(e[f])||"left"===r&&t!==u||t-l<f-t?v(e[l])?l+1:l:f}},{key:"getCaretPosition",value:function(e,t,r){var n,o,a=this.props.format,i=this.state.value,s=this.getNumberRegex(!0),u=(e.match(s)||[]).join(""),c=(t.match(s)||[]).join("");for(o=n=0;o<r;o++){var l=e[o]||"",f=t[n]||"";if((l.match(s)||l===f)&&("0"!==l||!f.match(s)||"0"===f||u.length===c.length)){for(;l!==t[n]&&n<t.length;)n++;n++}}return"string"!=typeof a||i||(n=t.length),n=this.correctCaretPosition(t,n)}},{key:"removePrefixAndSuffix",value:function(e){var t=this.props,r=t.format,n=t.prefix,o=t.suffix;if(!r&&e){var a="-"===e[0];a&&(e=e.substring(1,e.length));var i=(e=n&&0===e.indexOf(n)?e.substring(n.length,e.length):e).lastIndexOf(o);e=o&&-1!==i&&i===e.length-o.length?e.substring(0,i):e,a&&(e="-"+e)}return e}},{key:"removePatternFormatting",value:function(e){for(var t=this.props.format.split("#").filter(function(e){return""!==e}),r=0,n="",o=0,a=t.length;o<=a;o++){var i=t[o]||"",s=o===a?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(""),o=0,a=t.length;o<a;o++)"#"===t[o]&&(n[o]=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,o=t.prefix,a=t.suffix,i=t.allowNegative,s=this.getSeparators(),u=s.thousandSeparator,c=s.decimalSeparator,l=-1!==e.indexOf(".")||r&&n,f=P(e,i),p=f.beforeDecimal,h=f.afterDecimal,g=f.addNegation;return void 0!==r&&(h=y(h,r,n)),u&&(p=p.replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+u)),o&&(p=o+p),a&&(h+=a),g&&(p="-"+p),e=p+(l&&c||"")+h}},{key:"formatNumString",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=this.props,r=t.format,n=t.allowEmptyFormatting,o=e;return""!==e||n?"-"!==e||r?o="string"==typeof r?this.formatWithPattern(o):"function"==typeof r?r(o):this.formatAsNumber(o):(o="-",e=""):o="",o}},{key:"formatValueProp",value:function(){var e=this.props,t=e.format,r=e.decimalScale,n=e.fixedDecimalScale,o=e.allowEmptyFormatting,a=this.props,i=a.value,s=a.isNumericString,u=!i&&0!==i;return u&&o&&(i=""),u&&!o?"":("number"==typeof i&&(i=i.toString(),s=!0),s&&!t&&"number"==typeof r&&(i=function(e,t,r){if(-1!==["","-"].indexOf(e))return e;var n=-1!==e.indexOf(".")&&t,o=P(e),a=o.beforeDecimal,i=o.afterDecimal,s=o.hasNagation,u=parseFloat("0.".concat(i||"0")).toFixed(t).split("."),c=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]),l=y(u[1]||"",Math.min(t,i.length),r),f=n?".":"";return"".concat(s?"-":"").concat(c).concat(f).concat(l)}(i,r,n)),s?this.formatNumString(i):this.formatInput(i))}},{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("(-)(.)*(-)"),o=r.test(e),a=n.test(e);return e=e.replace(/-/g,""),o&&!a&&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.formatNegation(e)),e=this.removeFormatting(e),this.formatNumString(e)}},{key:"isCharacterAFormat",value:function(e,t){var r=this.props,n=r.format,o=r.prefix,a=r.suffix,i=r.decimalScale,s=r.fixedDecimalScale,u=this.getSeparators().decimalSeparator;return"string"==typeof n&&"#"!==n[e]||!(n||!(e<o.length||e>=t.length-a.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,o=n.format,a=n.decimalSeparator,i=n.allowNegative,s=n.prefix,u=n.suffix,c=this.state.numAsString||"",l=this.selectionBeforeInput,f=l.selectionStart,p=l.selectionEnd,h=function(e,t){for(var r=0,n=0,o=e.length,a=t.length;e[r]===t[r]&&r<o;)r++;for(;e[o-1-n]===t[a-1-n]&&r<a-n&&r<o-n;)n++;return{start:r,end:o-n}}(t,r),g=h.start,m=h.end,v=o?0:s.length,d=t.length-(o?0:u.length);if(r.length>t.length||!r.length||g===m||0===f&&p===t.length||f===v&&p===d)return r;if(this.checkIfFormatGotDeleted(g,m,t)&&(r=t),!o){var y=this.removeFormatting(r),b=P(y,i),S=b.beforeDecimal,x=b.afterDecimal,O=b.addNegation,w=e<r.indexOf(a)+1;if(y.length<c.length&&w&&""===S&&!parseFloat(x))return O?"-":""}return r}},{key:"onChange",value:function(e){e.persist();var t=e.target,r=t.value,n=this.state,o=this.props,a=o.isAllowed,i=n.value||"",s=Math.max(t.selectionStart,t.selectionEnd);r=this.correctInputValue(s,i,r);var u=this.formatInput(r)||"",c=this.removeFormatting(u),l=this.getValueObject(u,c);a(l)||(u=i),t.value=u;var f=this.getCaretPosition(r,u,s);this.setPatchedCaretPosition(t,f,u),u!==i?this.setState({value:u,numAsString:c},function(){o.onValueChange(l,e),o.onChange(e)}):o.onChange(e)}},{key:"onBlur",value:function(t){var r=this,n=this.props,e=this.state,o=n.format,a=n.onBlur,i=e.numAsString,s=e.value;if(!o){i=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",o=r[1]||"";return"".concat(t?"-":"").concat(n).concat(o?".".concat(o):"")}(i);var u=this.formatNumString(i);if(u!==s)return t.persist(),void this.setState({value:u,numAsString:i},function(){var e=r.getValueObject(u,i);n.onValueChange(e,t),a(t)})}a(t)}},{key:"onKeyDown",value:function(e){var t,r=this,n=e.target,o=e.key,a=n.selectionStart,i=n.selectionEnd,s=n.value,u=void 0===s?"":s,c=this.props,l=c.decimalScale,f=c.fixedDecimalScale,p=c.prefix,h=c.suffix,g=c.format,m=c.onKeyDown,v=c.onValueChange,d=void 0!==l&&f,y=this.getNumberRegex(!1,d),b=new RegExp("-"),S="string"==typeof g;if(this.selectionBeforeInput={selectionStart:a,selectionEnd:i},"ArrowLeft"===o||"Backspace"===o?t=a-1:"ArrowRight"===o?t=a+1:"Delete"===o&&(t=a),void 0!==t&&a===i){var x=t,O=S?g.indexOf("#"):p.length,w=S?g.lastIndexOf("#")+1:u.length-h.length;if("ArrowLeft"===o||"ArrowRight"===o){var P="ArrowLeft"===o?"left":"right";x=this.correctCaretPosition(u,t,P)}else if("Delete"!==o||y.test(u[t])||b.test(u[t])){if("Backspace"===o&&!y.test(u[t]))if(a<=O+1&&"-"===u[0]&&void 0===g){var k=u.substring(1),N=this.removeFormatting(k),F=this.getValueObject(k,N);e.persist(),this.setState({value:k,numAsString:N},function(){r.setPatchedCaretPosition(n,x,k),v(F,e)})}else if(!b.test(u[t])){for(;!y.test(u[x-1])&&O<x;)x--;x=this.correctCaretPosition(u,x,"left")}}else for(;!y.test(u[x])&&x<w;)x++;(x!==t||t<O||w<t)&&(e.preventDefault(),this.setPatchedCaretPosition(n,x,u)),e.isUnitTestRun&&this.setPatchedCaretPosition(n,x,u),this.props.onKeyDown(e)}else m(e)}},{key:"onMouseUp",value:function(e){var t=e.target,r=t.selectionStart,n=t.selectionEnd,o=t.value,a=void 0===o?"":o;if(r===n){var i=this.correctCaretPosition(a,r);i!==r&&this.setPatchedCaretPosition(t,i,a)}this.props.onMouseUp(e)}},{key:"onFocus",value:function(i){var s=this;i.persist(),setTimeout(function(){var e=i.target,t=e.selectionStart,r=e.selectionEnd,n=e.value,o=void 0===n?"":n,a=s.correctCaretPosition(o,t);a===t||0===t&&r===o.length||s.setPatchedCaretPosition(e,a,o),s.props.onFocus(i)},0)}},{key:"render",value:function(){var t,r,n,e=this.props,o=e.type,a=e.displayType,i=e.customInput,s=e.renderText,u=e.getInputRef,c=this.state.value,l=(t=this.props,r=x,n={},Object.keys(t).forEach(function(e){r[e]||(n[e]=t[e])}),n),f=Object.assign({},l,{type:o,value:c,onChange:this.onChange,onKeyDown:this.onKeyDown,onMouseUp:this.onMouseUp,onFocus:this.onFocus,onBlur:this.onBlur});if("text"===a)return s?s(c)||null:h.createElement("span",g({},l,{ref:u}),c);if(i){var p=i;return h.createElement(p,f)}return h.createElement("input",g({},f,{ref:u}))}}])&&o(t.prototype,r),n&&o(t,n),a}();return w.propTypes=x,w.defaultProps=O,w});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):e.NumberFormat=t(e.React)}(this,function(h){"use strict";function o(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 g(){return(g=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 i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function s(e,t){return(s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function u(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function e(e){return function(){return e}}h=h&&h.hasOwnProperty("default")?h.default:h;var t=function(){};t.thatReturns=e,t.thatReturnsFalse=e(!1),t.thatReturnsTrue=e(!0),t.thatReturnsNull=e(null),t.thatReturnsThis=function(){return this},t.thatReturnsArgument=function(e){return e};var n=t;var c=function(e,t,r,n,o,a,i,s){if(!e){var u;if(void 0===t)u=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[r,n,o,a,i,s],l=0;(u=new Error(t.replace(/%s/g,function(){return c[l++]}))).name="Invariant Violation"}throw u.framesToPop=1,u}},r=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable;(function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},r=0;r<10;r++)t["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var n={};return"abcdefghijklmnopqrst".split("").forEach(function(e){n[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},n)).join("")}catch(e){return!1}})()&&Object.assign;var f,p=(function(e){e.exports=function(){function e(e,t,r,n,o,a){"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"!==a&&c(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function t(){return e}var r={array:e.isRequired=e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return r.checkPropTypes=n,r.PropTypes=r}()}(f={exports:{}},f.exports),f.exports);function m(){}function v(e){return!!(e||"").match(/\d/)}function d(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}function P(e){var t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1],r="-"===e[0],n=r&&t,o=(e=e.replace("-","")).split(".");return{beforeDecimal:o[0],afterDecimal:o[1]||"",hasNagation:r,addNegation:n}}function y(e,t,r){for(var n="",o=r?"0":"",a=0;a<=t-1;a++)n+=e[a]||o;return n}function S(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 b(e,t,r){return Math.min(Math.max(e,t),r)}var x={thousandSeparator:p.oneOfType([p.string,p.oneOf([!0])]),decimalSeparator:p.string,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]),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"]),isAllowed:p.func,renderText:p.func,getInputRef:p.func},O={displayType:"input",decimalSeparator:".",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},w=function(e){function a(e){var t,r,n;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),r=this,(t=!(n=i(a).call(this,e))||"object"!=typeof n&&"function"!=typeof n?u(r):n).validateProps();var o=t.formatValueProp();return t.state={value:o,numAsString:t.removeFormatting(o)},t.selectionBeforeInput={selectionStart:0,selectionEnd:0},t.onChange=t.onChange.bind(u(u(t))),t.onKeyDown=t.onKeyDown.bind(u(u(t))),t.onMouseUp=t.onMouseUp.bind(u(u(t))),t.onFocus=t.onFocus.bind(u(u(t))),t.onBlur=t.onBlur.bind(u(u(t))),t}var t,r,n;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&&s(e,t)}(a,h.Component),t=a,(r=[{key:"componentDidUpdate",value:function(e){this.updateValueIfRequired(e)}},{key:"updateValueIfRequired",value:function(e){var t=this.props,r=this.state;if(e!==t){this.validateProps();var n=r.value,o=r.numAsString||"",a=this.formatNumString(o),i=void 0===t.value?a:this.formatValueProp(),s=this.removeFormatting(i),u=parseFloat(s),c=parseFloat(o);(isNaN(u)&&isNaN(c)||u===c)&&a===n||this.setState({value:i,numAsString:s})}}},{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),o="-"===e[0];o&&(e=e.replace("-","")),r&&0===t&&(e=e.split(r)[0]);var a=(e=(e.match(n)||[]).join("").replace(r,".")).indexOf(".");return-1!==a&&(e="".concat(e.substring(0,a),".").concat(e.substring(a+1,e.length).replace(new RegExp(d(r),"g"),""))),o&&(e="-"+e),e}},{key:"getNumberRegex",value:function(e,t){var r=this.props,n=r.format,o=r.decimalScale,a=this.getSeparators().decimalSeparator;return new RegExp("\\d"+(!a||0===o||t||n?"":"|"+d(a)),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){S(e,t),setTimeout(function(){e.value===r&&S(e,t)},0)}},{key:"correctCaretPosition",value:function(e,t,r){var n=this.props,o=n.prefix,a=n.suffix,i=n.format;if(""===e)return 0;if(t=b(t,0,e.length),!i){var s="-"===e[0];return b(t,o.length+(s?1:0),e.length-a.length)}if("function"==typeof i)return t;if("#"===i[t]&&v(e[t]))return t;if("#"===i[t-1]&&v(e[t-1]))return t;var u=i.indexOf("#");t=b(t,u,i.lastIndexOf("#")+1);for(var c=i.substring(t,i.length).indexOf("#"),l=t,f=t+(-1===c?0:c);u<l&&("#"!==i[l]||!v(e[l]));)l-=1;return!v(e[f])||"left"===r&&t!==u||t-l<f-t?v(e[l])?l+1:l:f}},{key:"getCaretPosition",value:function(e,t,r){var n,o,a=this.props.format,i=this.state.value,s=this.getNumberRegex(!0),u=(e.match(s)||[]).join(""),c=(t.match(s)||[]).join("");for(o=n=0;o<r;o++){var l=e[o]||"",f=t[n]||"";if((l.match(s)||l===f)&&("0"!==l||!f.match(s)||"0"===f||u.length===c.length)){for(;l!==t[n]&&n<t.length;)n++;n++}}return"string"!=typeof a||i||(n=t.length),n=this.correctCaretPosition(t,n)}},{key:"removePrefixAndSuffix",value:function(e){var t=this.props,r=t.format,n=t.prefix,o=t.suffix;if(!r&&e){var a="-"===e[0];a&&(e=e.substring(1,e.length));var i=(e=n&&0===e.indexOf(n)?e.substring(n.length,e.length):e).lastIndexOf(o);e=o&&-1!==i&&i===e.length-o.length?e.substring(0,i):e,a&&(e="-"+e)}return e}},{key:"removePatternFormatting",value:function(e){for(var t=this.props.format.split("#").filter(function(e){return""!==e}),r=0,n="",o=0,a=t.length;o<=a;o++){var i=t[o]||"",s=o===a?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(""),o=0,a=t.length;o<a;o++)"#"===t[o]&&(n[o]=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,o=t.prefix,a=t.suffix,i=t.allowNegative,s=this.getSeparators(),u=s.thousandSeparator,c=s.decimalSeparator,l=-1!==e.indexOf(".")||r&&n,f=P(e,i),p=f.beforeDecimal,h=f.afterDecimal,g=f.addNegation;return void 0!==r&&(h=y(h,r,n)),u&&(p=p.replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+u)),o&&(p=o+p),a&&(h+=a),g&&(p="-"+p),e=p+(l&&c||"")+h}},{key:"formatNumString",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=this.props,r=t.format,n=t.allowEmptyFormatting,o=e;return""!==e||n?"-"!==e||r?o="string"==typeof r?this.formatWithPattern(o):"function"==typeof r?r(o):this.formatAsNumber(o):(o="-",e=""):o="",o}},{key:"formatValueProp",value:function(){var e=this.props,t=e.format,r=e.decimalScale,n=e.fixedDecimalScale,o=e.allowEmptyFormatting,a=this.props,i=a.value,s=a.isNumericString,u=!i&&0!==i;return u&&o&&(i=""),u&&!o?"":("number"==typeof i&&(i=i.toString(),s=!0),s&&!t&&"number"==typeof r&&(i=function(e,t,r){if(-1!==["","-"].indexOf(e))return e;var n=-1!==e.indexOf(".")&&t,o=P(e),a=o.beforeDecimal,i=o.afterDecimal,s=o.hasNagation,u=parseFloat("0.".concat(i||"0")).toFixed(t).split("."),c=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]),l=y(u[1]||"",Math.min(t,i.length),r),f=n?".":"";return"".concat(s?"-":"").concat(c).concat(f).concat(l)}(i,r,n)),s?this.formatNumString(i):this.formatInput(i))}},{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("(-)(.)*(-)"),o=r.test(e),a=n.test(e);return e=e.replace(/-/g,""),o&&!a&&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.formatNegation(e)),e=this.removeFormatting(e),this.formatNumString(e)}},{key:"isCharacterAFormat",value:function(e,t){var r=this.props,n=r.format,o=r.prefix,a=r.suffix,i=r.decimalScale,s=r.fixedDecimalScale,u=this.getSeparators().decimalSeparator;return"string"==typeof n&&"#"!==n[e]||!(n||!(e<o.length||e>=t.length-a.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,o=n.format,a=n.decimalSeparator,i=n.allowNegative,s=n.prefix,u=n.suffix,c=this.state.numAsString||"",l=this.selectionBeforeInput,f=l.selectionStart,p=l.selectionEnd,h=function(e,t){for(var r=0,n=0,o=e.length,a=t.length;e[r]===t[r]&&r<o;)r++;for(;e[o-1-n]===t[a-1-n]&&r<a-n&&r<o-n;)n++;return{start:r,end:o-n}}(t,r),g=h.start,m=h.end,v=o?0:s.length,d=t.length-(o?0:u.length);if(r.length>t.length||!r.length||g===m||0===f&&p===t.length||f===v&&p===d)return r;if(this.checkIfFormatGotDeleted(g,m,t)&&(r=t),!o){var y=this.removeFormatting(r),S=P(y,i),b=S.beforeDecimal,x=S.afterDecimal,O=S.addNegation,w=e<r.indexOf(a)+1;if(y.length<c.length&&w&&""===b&&!parseFloat(x))return O?"-":""}return r}},{key:"onChange",value:function(e){e.persist();var t=e.target,r=t.value,n=this.state,o=this.props,a=o.isAllowed,i=n.value||"",s=Math.max(t.selectionStart,t.selectionEnd);r=this.correctInputValue(s,i,r);var u=this.formatInput(r)||"",c=this.removeFormatting(u),l=this.getValueObject(u,c);a(l)||(u=i),t.value=u;var f=this.getCaretPosition(r,u,s);this.setPatchedCaretPosition(t,f,u),u!==i?this.setState({value:u,numAsString:c},function(){o.onValueChange(l,e),o.onChange(e)}):o.onChange(e)}},{key:"onBlur",value:function(t){var r=this,n=this.props,e=this.state,o=n.format,a=n.onBlur,i=e.numAsString,s=e.value;if(!o){i=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",o=r[1]||"";return"".concat(t?"-":"").concat(n).concat(o?".".concat(o):"")}(i);var u=this.formatNumString(i);if(u!==s)return t.persist(),void this.setState({value:u,numAsString:i},function(){var e=r.getValueObject(u,i);n.onValueChange(e,t),a(t)})}a(t)}},{key:"onKeyDown",value:function(e){var t,r=this,n=e.target,o=e.key,a=n.selectionStart,i=n.selectionEnd,s=n.value,u=void 0===s?"":s,c=this.props,l=c.decimalScale,f=c.fixedDecimalScale,p=c.prefix,h=c.suffix,g=c.format,m=c.onKeyDown,v=c.onValueChange,d=void 0!==l&&f,y=this.getNumberRegex(!1,d),S=new RegExp("-"),b="string"==typeof g;if(this.selectionBeforeInput={selectionStart:a,selectionEnd:i},"ArrowLeft"===o||"Backspace"===o?t=a-1:"ArrowRight"===o?t=a+1:"Delete"===o&&(t=a),void 0!==t&&a===i){var x=t,O=b?g.indexOf("#"):p.length,w=b?g.lastIndexOf("#")+1:u.length-h.length;if("ArrowLeft"===o||"ArrowRight"===o){var P="ArrowLeft"===o?"left":"right";x=this.correctCaretPosition(u,t,P)}else if("Delete"!==o||y.test(u[t])||S.test(u[t])){if("Backspace"===o&&!y.test(u[t]))if(a<=O+1&&"-"===u[0]&&void 0===g){var k=u.substring(1),N=this.removeFormatting(k),F=this.getValueObject(k,N);e.persist(),this.setState({value:k,numAsString:N},function(){r.setPatchedCaretPosition(n,x,k),v(F,e)})}else if(!S.test(u[t])){for(;!y.test(u[x-1])&&O<x;)x--;x=this.correctCaretPosition(u,x,"left")}}else for(;!y.test(u[x])&&x<w;)x++;(x!==t||t<O||w<t)&&(e.preventDefault(),this.setPatchedCaretPosition(n,x,u)),e.isUnitTestRun&&this.setPatchedCaretPosition(n,x,u),this.props.onKeyDown(e)}else m(e)}},{key:"onMouseUp",value:function(e){var t=e.target,r=t.selectionStart,n=t.selectionEnd,o=t.value,a=void 0===o?"":o;if(r===n){var i=this.correctCaretPosition(a,r);i!==r&&this.setPatchedCaretPosition(t,i,a)}this.props.onMouseUp(e)}},{key:"onFocus",value:function(i){var s=this;i.persist(),setTimeout(function(){var e=i.target,t=e.selectionStart,r=e.selectionEnd,n=e.value,o=void 0===n?"":n,a=s.correctCaretPosition(o,t);a===t||0===t&&r===o.length||s.setPatchedCaretPosition(e,a,o),s.props.onFocus(i)},0)}},{key:"render",value:function(){var t,r,n,e=this.props,o=e.type,a=e.displayType,i=e.customInput,s=e.renderText,u=e.getInputRef,c=this.state.value,l=(t=this.props,r=x,n={},Object.keys(t).forEach(function(e){r[e]||(n[e]=t[e])}),n),f=g({},l,{type:o,value:c,onChange:this.onChange,onKeyDown:this.onKeyDown,onMouseUp:this.onMouseUp,onFocus:this.onFocus,onBlur:this.onBlur});if("text"===a)return s?s(c)||null:h.createElement("span",g({},l,{ref:u}),c);if(i){var p=i;return h.createElement(p,f)}return h.createElement("input",g({},f,{ref:u}))}}])&&o(t.prototype,r),n&&o(t,n),a}();return w.propTypes=x,w.defaultProps=O,w});

@@ -919,3 +919,4 @@ "use strict";

var otherProps = (0, _utils.omit)(this.props, propTypes);
var inputProps = Object.assign({}, otherProps, {
var inputProps = _extends({}, otherProps, {
type: type,

@@ -922,0 +923,0 @@ value: value,

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

@@ -47,2 +47,3 @@ "author": "Sudhanshu Yadav",

"babel-plugin-add-module-exports": "^1.0.0",
"babel-plugin-transform-object-assign": "^6.22.0",
"classnames": "^2.2.3",

@@ -49,0 +50,0 @@ "cross-env": "^3.1.4",

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