react-number-textfield
Advanced tools
Comparing version 1.4.5 to 1.4.6
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define("ReactNumberTextfield",["react"],t):"object"==typeof exports?exports.ReactNumberTextfield=t(require("react")):e.ReactNumberTextfield=t(e.react)}(window,function(e){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=1)}([function(t,r){t.exports=e},function(e,t,r){"use strict";r.r(t);var n=r(0);const i={string_value:""};class o extends n.Component{constructor(e){if(super(e),this.state=i,this.handleKeyPress=(e=>{const t=e.charCode;let r=!1;if(!function(e){if(e>=48&&e<=57)return!0;return!1}(t)){String.fromCharCode(t)!==this.props.decimal_character?r=!0:(0===this.props.precision||this.state.string_value.indexOf(this.props.decimal_character)>-1)&&(r=!0)}if(r)return e.preventDefault(),e.stopPropagation(),!1}),this.handleChange=(e=>{const t=a(e.target.value,this.props.decimal_character,this.props.group_separator,this.props.precision);this.setState({string_value:t.string_value}),"function"==typeof this.props.didChangeNumber&&this.props.didChangeNumber(t.number_value)}),"number"==typeof e.value&&(this.state=a(e.value.toString(),e.decimal_character,e.group_separator,e.precision)),e.precision<0||e.precision%1!=0)throw new Error("Maximum precision must be a positive integer.")}static derivedStateFromProps(e,t){if("number"==typeof e.value)return a(e.value.toString(),e.decimal_character,e.group_separator,e.precision)}render(){return n.createElement("input",{type:"text",className:this.props.className,value:this.state.string_value,placeholder:this.props.placeholder,onKeyPress:this.handleKeyPress,onChange:this.handleChange})}}function a(e,t,r,n){const i=new RegExp(`[^0-9${o=t,o.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}]+`,"g");var o;let a=e.replace(i,"").replace(t,"."),s=function(e){let t=void 0;const r=e.indexOf(".")>-1;r&&1===e.length&&(e="0"+e);t=r?parseFloat(e):parseInt(e);return t}(a);if(void 0===s||isNaN(s))return console.warn("String could not be represented as a number. Resetting textfield value."),{number_value:void 0,string_value:""};const u=a.indexOf(".")>-1,c=function(e){const t=e.toString().split(".");if(t.length>1)return t[1].length;return 0}(a);if(s%1!=0&&c>n){console.warn("Additional decimal digit will exceed maximum precision.");const e=Math.pow(10,n);s=Math.floor(s*e)/e}return{number_value:s,string_value:a=function(e,t,r,n){const i=e.toString().split("."),o=i[0],a=i.length>1?i[1]:"",s=Math.floor(o.length/3);let u="";if(s>0)for(let e=1;e<=s;e++)u=o.substr(-3*e,3)+(e>1?t+u:"");const c=o.length%3;c>0&&(u=o.substr(0,c)+(u.length>0?t+u:""));n>-1&&(u+=r+a,n>a.length&&(u+=new Array(n-a.length).fill(0).join("")));return u}(s,r,t,u?Math.max(0,Math.min(c,n)):-1)}}o.defaultProps={decimal_character:".",group_separator:",",precision:2},r.d(t,"NumberTextfield",function(){return o})}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define("ReactNumberTextfield",["react"],t):"object"==typeof exports?exports.ReactNumberTextfield=t(require("react")):e.ReactNumberTextfield=t(e.react)}(window,function(e){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=1)}([function(t,r){t.exports=e},function(e,t,r){"use strict";r.r(t);var n=r(0);const i={string_value:""};class o extends n.Component{constructor(e){if(super(e),this.state=i,this.handleKeyPress=(e=>{const t=e.charCode;let r=!1;if(!function(e){if(e>=48&&e<=57)return!0;return!1}(t)){String.fromCharCode(t)!==this.props.decimal_character?r=!0:(0===this.props.precision||this.state.string_value.indexOf(this.props.decimal_character)>-1)&&(r=!0)}if(r)return e.preventDefault(),e.stopPropagation(),!1}),this.handleChange=(e=>{const t=s(e.target.value,this.props.decimal_character,this.props.group_separator,this.props.precision);this.setState({string_value:t.string_value}),"function"==typeof this.props.didChangeNumber&&this.props.didChangeNumber(t.number_value)}),"number"==typeof e.value&&(this.state=s(e.value.toString(),e.decimal_character,e.group_separator,e.precision)),e.precision<0||e.precision%1!=0)throw new Error("Maximum precision must be a positive integer.")}static derivedStateFromProps(e,t){if("number"==typeof e.value)return s(e.value.toString(),e.decimal_character,e.group_separator,e.precision)}render(){const e="function"==typeof this.props.renderString?this.props.renderString(this.state.string_value):this.state.string_value;return n.createElement("input",{type:"text",className:this.props.className,value:e,placeholder:this.props.placeholder,onKeyPress:this.handleKeyPress,onChange:this.handleChange})}}function s(e,t,r,n){const i=new RegExp(`[^0-9${o=t,o.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}]+`,"g");var o;let s=e.replace(i,"").replace(t,"."),a=function(e){let t=void 0;const r=e.indexOf(".")>-1;r&&1===e.length&&(e="0"+e);t=r?parseFloat(e):parseInt(e);return t}(s);if(void 0===a||isNaN(a))return console.warn("String could not be represented as a number. Resetting textfield value."),{number_value:void 0,string_value:""};const u=s.indexOf(".")>-1,c=function(e){const t=e.toString().split(".");if(t.length>1)return t[1].length;return 0}(s);if(a%1!=0&&c>n){console.warn("Additional decimal digit will exceed maximum precision.");const e=Math.pow(10,n);a=Math.floor(a*e)/e}return{number_value:a,string_value:s=function(e,t,r,n){const i=e.toString().split("."),o=i[0],s=i.length>1?i[1]:"",a=Math.floor(o.length/3);let u="";if(a>0)for(let e=1;e<=a;e++)u=o.substr(-3*e,3)+(e>1?t+u:"");const c=o.length%3;c>0&&(u=o.substr(0,c)+(u.length>0?t+u:""));n>-1&&(u+=r+s,n>s.length&&(u+=new Array(n-s.length).fill(0).join("")));return u}(a,r,t,u?Math.max(0,Math.min(c,n)):-1)}}o.defaultProps={decimal_character:".",group_separator:",",precision:2},r.d(t,"NumberTextfield",function(){return o})}])}); | ||
//# sourceMappingURL=react-number-textfield.js.map |
{ | ||
"name": "react-number-textfield", | ||
"version": "1.4.5", | ||
"version": "1.4.6", | ||
"description": "Controlled ReactJS component for entering numbers.", | ||
@@ -5,0 +5,0 @@ "main": "build/react-number-textfield.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35347
384