Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

react-currency-input

Package Overview
Dependencies
Maintainers
1
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.0.5
to
1.0.6
.npmignore

Sorry, the diff of this file is not supported yet

+10
-6

@@ -35,3 +35,4 @@ 'use strict';

precision: _react.PropTypes.oneOfType([_react.PropTypes.number, _react.PropTypes.string]),
inputType: _react.PropTypes.string
inputType: _react.PropTypes.string,
allowNegative: _react.PropTypes.bool
},

@@ -45,3 +46,3 @@

*
* @returns {{onChange: onChange, value: string, decimalSeparator: string, thousandSeparator: string, precision: number}}
* @returns {{onChange: onChange, value: string, decimalSeparator: string, thousandSeparator: string, precision: number, inputType: string, allowNegative: boolean}}
*/

@@ -55,3 +56,4 @@ getDefaultProps: function getDefaultProps() {

precision: "2",
inputType: "text"
inputType: "text",
allowNegative: false
};

@@ -76,4 +78,5 @@ },

delete customProps.inputType;
delete customProps.allowNegative;
return {
maskedValue: (0, _mask2.default)(this.props.value, this.props.precision, this.props.decimalSeparator, this.props.thousandSeparator),
maskedValue: (0, _mask2.default)(this.props.value, this.props.precision, this.props.decimalSeparator, this.props.thousandSeparator, this.props.allowNegative),
customProps: customProps

@@ -99,4 +102,5 @@ };

delete customProps.inputType;
delete customProps.allowNegative;
this.setState({
maskedValue: (0, _mask2.default)(nextProps.value, nextProps.precision, nextProps.decimalSeparator, nextProps.thousandSeparator),
maskedValue: (0, _mask2.default)(nextProps.value, nextProps.precision, nextProps.decimalSeparator, nextProps.thousandSeparator, nextProps.allowNegative),
customProps: customProps

@@ -123,3 +127,3 @@ });

event.preventDefault();
var maskedValue = (0, _mask2.default)(event.target.value, this.props.precision, this.props.decimalSeparator, this.props.thousandSeparator);
var maskedValue = (0, _mask2.default)(event.target.value, this.props.precision, this.props.decimalSeparator, this.props.thousandSeparator, this.props.allowNegative);
this.setState({ maskedValue: maskedValue });

@@ -126,0 +130,0 @@ this.props.onChange(maskedValue);

@@ -7,3 +7,3 @@ "use strict";

exports.default = mask;
function mask(value, precision, decimalSeparator, thousandSeparator) {
function mask(value, precision, decimalSeparator, thousandSeparator, allowNegative) {
// provide some default values and arg validation.

@@ -16,2 +16,5 @@ if (decimalSeparator === undefined) {

} // default to ',' as thousand separator
if (allowNegative === undefined) {
allowNegative = false;
} // default to not allowing negative numbers
if (precision === undefined) {

@@ -27,5 +30,29 @@ precision = 2;

var numberIsNegative = false;
if (allowNegative) {
var negativeSignCount = (value.match(/-/g) || []).length;
// number will be negative if we have an odd number of "-"
// ideally, we should only ever have 0, 1 or 2 (positive number, making a number negative
// and making a negative number positive, respectively)
numberIsNegative = negativeSignCount % 2 === 1;
}
// extract digits. if no digits, fill in a zero.
var digits = value.match(/\d/g) || ['0'];
if (allowNegative) {
// if every digit in the array is '0', then the number should
// never be negative
var allDigitsAreZero = true;
for (var idx = 0; idx < digits.length; idx += 1) {
if (digits[idx] !== '0') {
allDigitsAreZero = false;
break;
}
}
if (allDigitsAreZero) {
numberIsNegative = false;
}
}
// zero-pad a input

@@ -58,3 +85,9 @@ while (digits.length <= precision) {

// if the number is negative, insert a "-" to
// the front of the array
if (allowNegative && numberIsNegative) {
digits.unshift('-');
}
return digits.join('');
}
{
"name": "react-currency-input",
"version": "1.0.5",
"version": "1.0.6",
"description": "React component for inputing currency amounts",

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

@@ -104,3 +104,4 @@ # react-currency-input

| inputType | "text" | Input field tag type. You may want to use `number` or `tel` |
| allowNegative | false | Allows negative numbers in the input |
The MIT License (MIT)
Copyright (c) 2015 Cedric Dugas
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.