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

react-currency-input

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-currency-input - npm Package Compare versions

Comparing version 1.3.3 to 1.3.4

54

lib/index.js

@@ -51,2 +51,5 @@ 'use strict';

_this.state = _this.prepareProps(_this.props);
_this.inputSelectionStart = 0;
_this.inputSelectionEnd = 0;
return _this;

@@ -161,2 +164,16 @@ }

/**
* Component lifecycle function
* @returns {XML}
* @see https://facebook.github.io/react/docs/react-component.html#componentwillupdate
*/
}, {
key: 'componentWillUpdate',
value: function componentWillUpdate() {
var node = _reactDom2.default.findDOMNode(this.theInput);
this.inputSelectionStart = node.selectionStart;
this.inputSelectionEnd = node.selectionEnd;
}
/**
* Component lifecycle function.

@@ -172,8 +189,16 @@ * @returns {XML}

var node = _reactDom2.default.findDOMNode(this.theInput);
var selectionEnd = Math.min(this.state.selectionEnd, this.theInput.value.length - this.props.suffix.length);
var selectionStart = Math.min(this.state.selectionStart, selectionEnd);
var isNegative = (this.theInput.value.match(/-/g) || []).length % 2 === 1;
var minPos = this.props.prefix.length + (isNegative ? 1 : 0);
var selectionEnd = Math.max(minPos, Math.min(this.inputSelectionEnd, this.theInput.value.length - this.props.suffix.length));
var selectionStart = Math.max(minPos, Math.min(this.inputSelectionEnd, selectionEnd));
// moves the cursor to the right when digits are added.
var adjustment = Math.max(this.state.maskedValue.length - prevState.maskedValue.length - 1, 0);
var regexEscapeRegex = /[-[\]{}()*+?.,\\^$|#\s]/g;
var separatorsRegex = new RegExp(this.props.decimalSeparator.replace(regexEscapeRegex, '\\$&') + '|' + this.props.thousandSeparator.replace(regexEscapeRegex, '\\$&'), 'g');
var currSeparatorCount = (this.state.maskedValue.match(separatorsRegex) || []).length;
var prevSeparatorCount = (prevState.maskedValue.match(separatorsRegex) || []).length;
var adjustment = Math.max(currSeparatorCount - prevSeparatorCount, 0);
selectionEnd = selectionEnd + adjustment;
selectionStart = selectionStart + adjustment;
var baselength = this.props.suffix.length + this.props.prefix.length + this.props.decimalSeparator.length + Number(this.props.precision) + 1; // This is to account for the default '0' value that comes before the decimal separator

@@ -185,6 +210,7 @@

selectionStart = selectionEnd;
adjustment = 0;
}
node.setSelectionRange(selectionStart + adjustment, selectionEnd + adjustment);
node.setSelectionRange(selectionStart, selectionEnd);
this.inputSelectionStart = selectionStart;
this.inputSelectionEnd = selectionEnd;
}

@@ -208,6 +234,2 @@

var node = _reactDom2.default.findDOMNode(this.theInput);
var selectionEnd = Math.min(node.selectionEnd, this.theInput.value.length - this.props.suffix.length);
var selectionStart = Math.min(node.selectionStart, selectionEnd);
event.persist(); // fixes issue #23

@@ -231,5 +253,7 @@

var selectionEnd = this.theInput.value.length - this.props.suffix.length;
var selectionStart = this.props.prefix.length;
var isNegative = (this.theInput.value.match(/-/g) || []).length % 2 === 1;
var selectionStart = this.props.prefix.length + (isNegative ? 1 : 0);
event.target.setSelectionRange(selectionStart, selectionEnd);
this.setState({ selectionStart: selectionStart, selectionEnd: selectionEnd });
this.inputSelectionStart = selectionStart;
this.inputSelectionEnd = selectionEnd;
}

@@ -239,6 +263,4 @@ }, {

value: function handleBlur(event) {
this.setState({
selectionStart: null,
selectionEnd: null
});
this.inputSelectionStart = 0;
this.inputSelectionEnd = 0;
}

@@ -245,0 +267,0 @@

{
"name": "react-currency-input",
"version": "1.3.3",
"version": "1.3.4",
"description": "React component for inputing currency amounts",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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