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

react-numeral-input

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-numeral-input - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

73

dist/index.js
// Generated by CoffeeScript 1.9.3
/** @jsx React.DOM */;
var NumeralInput, React, numeral, re;
var NumeralInput, React, getCaretPosition, numeral, re, setCaretPosition;

@@ -11,2 +11,29 @@ React = require('react');

getCaretPosition = function(oField) {
var iCaretPos, oSel;
iCaretPos = 0;
if (document.selection) {
oField.focus();
oSel = document.selection.createRange();
oSel.moveStart('character', -oField.value.length);
iCaretPos = oSel.text.length;
} else if (oField.selectionStart || oField.selectionStart === '0') {
iCaretPos = oField.selectionStart;
}
return iCaretPos;
};
setCaretPosition = function(oField, index) {
var range;
if (oField.setSelectionRange) {
return oField.setSelectionRange(index, index);
} else {
range = oField.createTextRange();
range.collapse(true);
range.moveEnd('character', index);
range.moveStart('character', index);
return range.select();
}
};
NumeralInput = React.createClass({

@@ -23,2 +50,21 @@ displayName: 'NumeralInput',

},
focusOnChar: function(val, index) {
var char, dotCount, finalIndex, formatVal, i;
formatVal = numeral(val).format(this.props.fmt);
dotCount = 0;
i = 0;
finalIndex = formatVal.length;
while (i < formatVal.length) {
char = formatVal[i];
if (char === ',') {
dotCount++;
}
if (i === (index + dotCount)) {
finalIndex = i;
break;
}
i++;
}
return finalIndex;
},
getInitialState: function() {

@@ -35,19 +81,32 @@ return {

componentWillReceiveProps: function(nextProps) {
var val;
var dot_sp, formatVal, node, val;
node = this.getDOMNode();
val = nextProps.value;
if (!re.test(val)) {
val = this.getNumeralValue(val);
formatVal = this.getNumeralValue(val);
dot_sp = formatVal.split(',');
}
return this.setState({
value: val
});
value: formatVal
}, (function(_this) {
return function() {
return setCaretPosition(node, _this.state.pos);
};
})(this));
},
changeHandler: function() {
var reTest, val;
val = this.getDOMNode().value;
var node, pos, reTest, val;
node = this.getDOMNode();
val = node.value;
pos = getCaretPosition(node);
reTest = re.test(val);
if (!reTest) {
val = numeral(val).value();
if ((this.state.value + '').length <= (val + '').length) {
pos = this.focusOnChar(val, pos);
pos++;
}
}
return this.setState({
pos: pos,
value: val

@@ -54,0 +113,0 @@ }, (function(_this) {

2

package.json
{
"name": "react-numeral-input",
"description": "numeral input",
"version": "0.0.8",
"version": "0.0.9",
"author": "Bingo Yang <blackbing@gmail.com>",

@@ -6,0 +6,0 @@ "browserify": {

Sorry, the diff of this file is too big to display

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