Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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.1.0 to 1.1.1

104

lib/index.js

@@ -7,6 +7,3 @@ 'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; /**
*
*
*/
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

@@ -17,5 +14,5 @@ var _react = require('react');

var _mask4 = require('./mask.js');
var _mask3 = require('./mask.js');
var _mask5 = _interopRequireDefault(_mask4);
var _mask4 = _interopRequireDefault(_mask3);

@@ -29,3 +26,4 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
* Prop validation. See: https://facebook.github.io/react/docs/component-specs.html#proptypes
* Prop validation.
* @see https://facebook.github.io/react/docs/component-specs.html#proptypes
*/

@@ -40,2 +38,3 @@ propTypes: {

allowNegative: _react.PropTypes.bool,
allowEmpty: _react.PropTypes.bool,
prefix: _react.PropTypes.string,

@@ -46,3 +45,3 @@ suffix: _react.PropTypes.string

/**
* Component lifecycle function. See: https://facebook.github.io/react/docs/component-specs.html#getdefaultprops
* Component lifecycle function.
*

@@ -52,12 +51,12 @@ * Invoked once and cached when the class is created. Values in the mapping will be set on this.props if that

*
* @returns {{onChange: onChange, value: string, decimalSeparator: string, thousandSeparator: string, precision: number, inputType: string, allowNegative: boolean}}
* @see https://facebook.github.io/react/docs/component-specs.html#getdefaultprops
*/
getDefaultProps: function getDefaultProps() {
return {
onChange: function onChange(maskValue, value) {/*no-op*/},
value: "0",
decimalSeparator: ".",
thousandSeparator: ",",
precision: "2",
inputType: "text",
onChange: function onChange(maskValue, value, event) {/*no-op*/},
value: '0',
decimalSeparator: '.',
thousandSeparator: ',',
precision: '2',
inputType: 'text',
allowNegative: false,

@@ -71,10 +70,7 @@ prefix: '',

/**
* Component lifecycle function. See: https://facebook.github.io/react/docs/component-specs.html#getinitialstate
*
* Invoked once before the component is mounted. The return value will be used as the initial value of this.state
*
* @returns {{maskedValue, customProps: *}}
* General function used to cleanup and define the final props used for rendering
* @returns {{ maskedValue: {String}, value: {Number}, customProps: {Object} }}
*/
getInitialState: function getInitialState() {
var customProps = Object.assign({}, this.props); //polyfilled for environments that do not support it.
prepareProps: function prepareProps(props) {
var customProps = Object.assign({}, props); //polyfilled for environments that do not support it.
delete customProps.onChange;

@@ -87,7 +83,13 @@ delete customProps.value;

delete customProps.allowNegative;
delete customProps.allowEmpty;
delete customProps.prefix;
delete customProps.suffix;
var _mask = (0, _mask5.default)(this.props.value, this.props.precision, this.props.decimalSeparator, this.props.thousandSeparator, this.props.allowNegative, this.props.prefix, this.props.suffix);
var initialValue = props.value;
if (!initialValue) {
initialValue = props.allowEmpty ? null : '';
}
var _mask = (0, _mask4.default)(initialValue, props.precision, props.decimalSeparator, props.thousandSeparator, props.allowNegative, props.prefix, props.suffix);
var maskedValue = _mask.maskedValue;

@@ -97,7 +99,3 @@ var value = _mask.value;

return {
maskedValue: maskedValue,
value: value,
customProps: customProps
};
return { maskedValue: maskedValue, value: value, customProps: customProps };
},

@@ -107,31 +105,22 @@

/**
* Component lifecycle function. See: https://facebook.github.io/react/docs/component-specs.html#updating-componentwillreceiveprops
* Component lifecycle function.
* Invoked once before the component is mounted. The return value will be used as the initial value of this.state
*
* @returns {{ maskedValue: {String}, value: {Number}, customProps: {Object} }}
* @see https://facebook.github.io/react/docs/component-specs.html#getinitialstate
*/
getInitialState: function getInitialState() {
return this.prepareProps(this.props);
},
/**
* Component lifecycle function.
* Invoked when a component is receiving new props. This method is not called for the initial render.
*
* @param nextProps
* @see https://facebook.github.io/react/docs/component-specs.html#updating-componentwillreceiveprops
*/
componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
var customProps = Object.assign({}, nextProps); //polyfilled for environments that do not support it.
delete customProps.onChange;
delete customProps.value;
delete customProps.decimalSeparator;
delete customProps.thousandSeparator;
delete customProps.precision;
delete customProps.inputType;
delete customProps.allowNegative;
delete customProps.prefix;
delete customProps.suffix;
var _mask2 = (0, _mask5.default)(nextProps.value, nextProps.precision, nextProps.decimalSeparator, nextProps.thousandSeparator, nextProps.allowNegative, nextProps.prefix, nextProps.suffix);
var maskedValue = _mask2.maskedValue;
var value = _mask2.value;
this.setState({
maskedValue: maskedValue,
value: value,
customProps: customProps
});
this.setState(this.prepareProps(nextProps));
},

@@ -143,3 +132,3 @@

*
* @returns {*}
* @returns {String}
*/

@@ -158,9 +147,9 @@ getMaskedValue: function getMaskedValue() {

var _mask3 = (0, _mask5.default)(event.target.value, this.props.precision, this.props.decimalSeparator, this.props.thousandSeparator, this.props.allowNegative, this.props.prefix, this.props.suffix);
var _mask2 = (0, _mask4.default)(event.target.value, this.props.precision, this.props.decimalSeparator, this.props.thousandSeparator, this.props.allowNegative, this.props.prefix, this.props.suffix);
var maskedValue = _mask3.maskedValue;
var value = _mask3.value;
var maskedValue = _mask2.maskedValue;
var value = _mask2.value;
this.setState({ maskedValue: maskedValue, value: value });
this.props.onChange(maskedValue, value);
this.props.onChange(maskedValue, value, event);
},

@@ -170,4 +159,5 @@

/**
* Component lifecycle function. See: https://facebook.github.io/react/docs/component-specs.html#render
* Component lifecycle function.
* @returns {XML}
* @see https://facebook.github.io/react/docs/component-specs.html#render
*/

@@ -174,0 +164,0 @@ render: function render() {

@@ -1,2 +0,2 @@

"use strict";
'use strict';

@@ -7,29 +7,37 @@ Object.defineProperty(exports, "__esModule", {

exports.default = mask;
function mask(value, precision, decimalSeparator, thousandSeparator, allowNegative, prefix, suffix) {
function mask(value) {
var precision = arguments.length <= 1 || arguments[1] === undefined ? 2 : arguments[1];
var decimalSeparator = arguments.length <= 2 || arguments[2] === undefined ? '.' : arguments[2];
var thousandSeparator = arguments.length <= 3 || arguments[3] === undefined ? ',' : arguments[3];
var allowNegative = arguments.length <= 4 || arguments[4] === undefined ? false : arguments[4];
var prefix = arguments.length <= 5 || arguments[5] === undefined ? '' : arguments[5];
var suffix = arguments.length <= 6 || arguments[6] === undefined ? '' : arguments[6];
// provide some default values and arg validation.
if (decimalSeparator === undefined) {
decimalSeparator = ".";
} // default to '.' as decimal separator
if (thousandSeparator === undefined) {
thousandSeparator = ",";
} // default to ',' as thousand separator
if (allowNegative === undefined) {
allowNegative = false;
} // default to not allowing negative numbers
if (precision === undefined) {
precision = 2;
} // by default, 2 decimal places
if (precision < 0) {
precision = 0;
} // precision cannot be negative.
} // precision cannot be negative
if (precision > 20) {
precision = 20;
} // precision cannot greater than 20
if (prefix === undefined) {
prefix = '';
} // default prefix to empty string
if (suffix === undefined) {
suffix = '';
} // default suffix to empty string
} // precision cannot be greater than 20
if (value === null || value === undefined) {
return {
value: 0,
maskedValue: ''
};
}
value = String(value); //if the given value is a Number, let's convert into String to manipulate that
if (value.length == 0) {
return {
value: 0,
maskedValue: ''
};
}
// extract digits. if no digits, fill in a zero.
var digits = value.match(/\d/g) || ['0'];
var numberIsNegative = false;

@@ -42,10 +50,4 @@ if (allowNegative) {

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
// if every digit in the array is '0', then the number should never be negative
var allDigitsAreZero = true;

@@ -52,0 +54,0 @@ for (var idx = 0; idx < digits.length; idx += 1) {

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

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

@@ -132,1 +132,4 @@ # react-currency-input

**Note:** Enabling any mask-related features such as prefix, suffix or separators
with an inputType="number" or "tel" could trigger errors. Most of those characters
would be invalid in such input types.
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