Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-number-textfield

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-number-textfield - npm Package Compare versions

Comparing version 1.3.2 to 1.3.3

2

build/react-number-textfield.js

@@ -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 o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.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 o={string_value:""};class i extends n.Component{constructor(e){var t;if(super(e),this.state=o,this.handleKeyPress=(e=>{const t=e.charCode;let r=!1;if(!((t=t)>=48&&t<=57)){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)}),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.number)return s(e.number.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 s(e,t,r,n){const o=new RegExp(`[^0-9${i=t,i.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}]+`,"g");var i;let s=e.replace(o,"").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 c=s.indexOf(".")>-1,u=function(e){const t=e.toString().split(".");if(t.length>1)return t[1].length;return 0}(s);if(a%1!=0&&u>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 o=e.toString().split("."),i=o[0],s=o.length>1?o[1]:"",a=Math.floor(i.length/3);let c="";if(a>0)for(let e=1;e<=a;e++)c=i.substr(-3*e,3)+(e>1?t+c:"");const u=i.length%3;u>0&&(c=i.substr(0,u)+(c.length>0?t+c:""));n>-1&&(c+=r+s,n>s.length&&(c+=new Array(n-s.length).fill(0).join("")));return c}(a,r,t,c?Math.max(0,Math.min(u,n)):-1)}}i.defaultProps={decimal_character:".",group_separator:",",precision:2},r.d(t,"NumberTextfield",function(){return i})}])});
!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)}),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.number)return s(e.number.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 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.3.2",
"version": "1.3.3",
"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

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