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

react-currency-input-field

Package Overview
Dependencies
Maintainers
1
Versions
105
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-currency-input-field - npm Package Compare versions

Comparing version 3.5.1 to 3.6.0

4

dist/components/CurrencyInputProps.d.ts

@@ -153,3 +153,7 @@ import { Ref, ElementType } from 'react';

ref?: Ref<HTMLInputElement>;
/**
* Transform the raw value form the input before parsing
*/
transformRawValue?: (rawValue: string) => string;
}>;
export {};

4

dist/components/utils/cleanValue.d.ts
import { CurrencyInputProps } from '../CurrencyInputProps';
export declare type CleanValueOptions = Pick<CurrencyInputProps, 'decimalSeparator' | 'groupSeparator' | 'allowDecimals' | 'decimalsLimit' | 'allowNegativeValue' | 'disableAbbreviations' | 'prefix'> & {
export declare type CleanValueOptions = Pick<CurrencyInputProps, 'decimalSeparator' | 'groupSeparator' | 'allowDecimals' | 'decimalsLimit' | 'allowNegativeValue' | 'disableAbbreviations' | 'prefix' | 'transformRawValue'> & {
value: string;

@@ -8,2 +8,2 @@ };

*/
export declare const cleanValue: ({ value, groupSeparator, decimalSeparator, allowDecimals, decimalsLimit, allowNegativeValue, disableAbbreviations, prefix, }: CleanValueOptions) => string;
export declare const cleanValue: ({ value, groupSeparator, decimalSeparator, allowDecimals, decimalsLimit, allowNegativeValue, disableAbbreviations, prefix, transformRawValue, }: CleanValueOptions) => string;

@@ -98,16 +98,17 @@ import React, { forwardRef, useMemo, useState, useRef, useEffect } from 'react';

var cleanValue = function (_a) {
var value = _a.value, _b = _a.groupSeparator, groupSeparator = _b === void 0 ? ',' : _b, _c = _a.decimalSeparator, decimalSeparator = _c === void 0 ? '.' : _c, _d = _a.allowDecimals, allowDecimals = _d === void 0 ? true : _d, _e = _a.decimalsLimit, decimalsLimit = _e === void 0 ? 2 : _e, _f = _a.allowNegativeValue, allowNegativeValue = _f === void 0 ? true : _f, _g = _a.disableAbbreviations, disableAbbreviations = _g === void 0 ? false : _g, _h = _a.prefix, prefix = _h === void 0 ? '' : _h;
if (value === '-') {
return value;
var value = _a.value, _b = _a.groupSeparator, groupSeparator = _b === void 0 ? ',' : _b, _c = _a.decimalSeparator, decimalSeparator = _c === void 0 ? '.' : _c, _d = _a.allowDecimals, allowDecimals = _d === void 0 ? true : _d, _e = _a.decimalsLimit, decimalsLimit = _e === void 0 ? 2 : _e, _f = _a.allowNegativeValue, allowNegativeValue = _f === void 0 ? true : _f, _g = _a.disableAbbreviations, disableAbbreviations = _g === void 0 ? false : _g, _h = _a.prefix, prefix = _h === void 0 ? '' : _h, _j = _a.transformRawValue, transformRawValue = _j === void 0 ? function (rawValue) { return rawValue; } : _j;
var transformedValue = transformRawValue(value);
if (transformedValue === '-') {
return transformedValue;
}
var abbreviations = disableAbbreviations ? [] : ['k', 'm', 'b'];
var reg = new RegExp("((^|\\D)-\\d)|(-" + escapeRegExp(prefix) + ")");
var isNegative = reg.test(value);
var isNegative = reg.test(transformedValue);
// Is there a digit before the prefix? eg. 1$
var _j = RegExp("(\\d+)-?" + escapeRegExp(prefix)).exec(value) || [], prefixWithValue = _j[0], preValue = _j[1];
var _k = RegExp("(\\d+)-?" + escapeRegExp(prefix)).exec(value) || [], prefixWithValue = _k[0], preValue = _k[1];
var withoutPrefix = prefix
? prefixWithValue
? value.replace(prefixWithValue, '').concat(preValue)
: value.replace(prefix, '')
: value;
? transformedValue.replace(prefixWithValue, '').concat(preValue)
: transformedValue.replace(prefix, '')
: transformedValue;
var withoutSeparators = removeSeparators(withoutPrefix, groupSeparator);

@@ -131,3 +132,3 @@ var withoutInvalidChars = removeInvalidChars(withoutSeparators, __spreadArray([

if (decimalSeparator && valueOnly.includes(decimalSeparator)) {
var _k = withoutInvalidChars.split(decimalSeparator), int = _k[0], decimals = _k[1];
var _l = withoutInvalidChars.split(decimalSeparator), int = _l[0], decimals = _l[1];
var trimmedDecimals = decimalsLimit && decimals ? decimals.slice(0, decimalsLimit) : decimals;

@@ -336,3 +337,3 @@ var includeDecimals = allowDecimals ? "" + decimalSeparator + trimmedDecimals : '';

var CurrencyInput = forwardRef(function (_a, ref) {
var _b = _a.allowDecimals, allowDecimals = _b === void 0 ? true : _b, _c = _a.allowNegativeValue, allowNegativeValue = _c === void 0 ? true : _c, id = _a.id, name = _a.name, className = _a.className, customInput = _a.customInput, decimalsLimit = _a.decimalsLimit, defaultValue = _a.defaultValue, _d = _a.disabled, disabled = _d === void 0 ? false : _d, userMaxLength = _a.maxLength, userValue = _a.value, onValueChange = _a.onValueChange, fixedDecimalLength = _a.fixedDecimalLength, placeholder = _a.placeholder, decimalScale = _a.decimalScale, prefix = _a.prefix, suffix = _a.suffix, intlConfig = _a.intlConfig, step = _a.step, min = _a.min, max = _a.max, _e = _a.disableGroupSeparators, disableGroupSeparators = _e === void 0 ? false : _e, _f = _a.disableAbbreviations, disableAbbreviations = _f === void 0 ? false : _f, _decimalSeparator = _a.decimalSeparator, _groupSeparator = _a.groupSeparator, onChange = _a.onChange, onFocus = _a.onFocus, onBlur = _a.onBlur, onKeyDown = _a.onKeyDown, onKeyUp = _a.onKeyUp, props = __rest(_a, ["allowDecimals", "allowNegativeValue", "id", "name", "className", "customInput", "decimalsLimit", "defaultValue", "disabled", "maxLength", "value", "onValueChange", "fixedDecimalLength", "placeholder", "decimalScale", "prefix", "suffix", "intlConfig", "step", "min", "max", "disableGroupSeparators", "disableAbbreviations", "decimalSeparator", "groupSeparator", "onChange", "onFocus", "onBlur", "onKeyDown", "onKeyUp"]);
var _b = _a.allowDecimals, allowDecimals = _b === void 0 ? true : _b, _c = _a.allowNegativeValue, allowNegativeValue = _c === void 0 ? true : _c, id = _a.id, name = _a.name, className = _a.className, customInput = _a.customInput, decimalsLimit = _a.decimalsLimit, defaultValue = _a.defaultValue, _d = _a.disabled, disabled = _d === void 0 ? false : _d, userMaxLength = _a.maxLength, userValue = _a.value, onValueChange = _a.onValueChange, fixedDecimalLength = _a.fixedDecimalLength, placeholder = _a.placeholder, decimalScale = _a.decimalScale, prefix = _a.prefix, suffix = _a.suffix, intlConfig = _a.intlConfig, step = _a.step, min = _a.min, max = _a.max, _e = _a.disableGroupSeparators, disableGroupSeparators = _e === void 0 ? false : _e, _f = _a.disableAbbreviations, disableAbbreviations = _f === void 0 ? false : _f, _decimalSeparator = _a.decimalSeparator, _groupSeparator = _a.groupSeparator, onChange = _a.onChange, onFocus = _a.onFocus, onBlur = _a.onBlur, onKeyDown = _a.onKeyDown, onKeyUp = _a.onKeyUp, transformRawValue = _a.transformRawValue, props = __rest(_a, ["allowDecimals", "allowNegativeValue", "id", "name", "className", "customInput", "decimalsLimit", "defaultValue", "disabled", "maxLength", "value", "onValueChange", "fixedDecimalLength", "placeholder", "decimalScale", "prefix", "suffix", "intlConfig", "step", "min", "max", "disableGroupSeparators", "disableAbbreviations", "decimalSeparator", "groupSeparator", "onChange", "onFocus", "onBlur", "onKeyDown", "onKeyUp", "transformRawValue"]);
if (_decimalSeparator && isNumber(_decimalSeparator)) {

@@ -369,2 +370,3 @@ throw new Error('decimalSeparator cannot be a number');

prefix: prefix || localeConfig.prefix,
transformRawValue: transformRawValue,
};

@@ -371,0 +373,0 @@ var formattedStateValue = defaultValue !== undefined && defaultValue !== null

@@ -106,16 +106,17 @@ (function (global, factory) {

var cleanValue = function (_a) {
var value = _a.value, _b = _a.groupSeparator, groupSeparator = _b === void 0 ? ',' : _b, _c = _a.decimalSeparator, decimalSeparator = _c === void 0 ? '.' : _c, _d = _a.allowDecimals, allowDecimals = _d === void 0 ? true : _d, _e = _a.decimalsLimit, decimalsLimit = _e === void 0 ? 2 : _e, _f = _a.allowNegativeValue, allowNegativeValue = _f === void 0 ? true : _f, _g = _a.disableAbbreviations, disableAbbreviations = _g === void 0 ? false : _g, _h = _a.prefix, prefix = _h === void 0 ? '' : _h;
if (value === '-') {
return value;
var value = _a.value, _b = _a.groupSeparator, groupSeparator = _b === void 0 ? ',' : _b, _c = _a.decimalSeparator, decimalSeparator = _c === void 0 ? '.' : _c, _d = _a.allowDecimals, allowDecimals = _d === void 0 ? true : _d, _e = _a.decimalsLimit, decimalsLimit = _e === void 0 ? 2 : _e, _f = _a.allowNegativeValue, allowNegativeValue = _f === void 0 ? true : _f, _g = _a.disableAbbreviations, disableAbbreviations = _g === void 0 ? false : _g, _h = _a.prefix, prefix = _h === void 0 ? '' : _h, _j = _a.transformRawValue, transformRawValue = _j === void 0 ? function (rawValue) { return rawValue; } : _j;
var transformedValue = transformRawValue(value);
if (transformedValue === '-') {
return transformedValue;
}
var abbreviations = disableAbbreviations ? [] : ['k', 'm', 'b'];
var reg = new RegExp("((^|\\D)-\\d)|(-" + escapeRegExp(prefix) + ")");
var isNegative = reg.test(value);
var isNegative = reg.test(transformedValue);
// Is there a digit before the prefix? eg. 1$
var _j = RegExp("(\\d+)-?" + escapeRegExp(prefix)).exec(value) || [], prefixWithValue = _j[0], preValue = _j[1];
var _k = RegExp("(\\d+)-?" + escapeRegExp(prefix)).exec(value) || [], prefixWithValue = _k[0], preValue = _k[1];
var withoutPrefix = prefix
? prefixWithValue
? value.replace(prefixWithValue, '').concat(preValue)
: value.replace(prefix, '')
: value;
? transformedValue.replace(prefixWithValue, '').concat(preValue)
: transformedValue.replace(prefix, '')
: transformedValue;
var withoutSeparators = removeSeparators(withoutPrefix, groupSeparator);

@@ -139,3 +140,3 @@ var withoutInvalidChars = removeInvalidChars(withoutSeparators, __spreadArray([

if (decimalSeparator && valueOnly.includes(decimalSeparator)) {
var _k = withoutInvalidChars.split(decimalSeparator), int = _k[0], decimals = _k[1];
var _l = withoutInvalidChars.split(decimalSeparator), int = _l[0], decimals = _l[1];
var trimmedDecimals = decimalsLimit && decimals ? decimals.slice(0, decimalsLimit) : decimals;

@@ -344,3 +345,3 @@ var includeDecimals = allowDecimals ? "" + decimalSeparator + trimmedDecimals : '';

var CurrencyInput = React.forwardRef(function (_a, ref) {
var _b = _a.allowDecimals, allowDecimals = _b === void 0 ? true : _b, _c = _a.allowNegativeValue, allowNegativeValue = _c === void 0 ? true : _c, id = _a.id, name = _a.name, className = _a.className, customInput = _a.customInput, decimalsLimit = _a.decimalsLimit, defaultValue = _a.defaultValue, _d = _a.disabled, disabled = _d === void 0 ? false : _d, userMaxLength = _a.maxLength, userValue = _a.value, onValueChange = _a.onValueChange, fixedDecimalLength = _a.fixedDecimalLength, placeholder = _a.placeholder, decimalScale = _a.decimalScale, prefix = _a.prefix, suffix = _a.suffix, intlConfig = _a.intlConfig, step = _a.step, min = _a.min, max = _a.max, _e = _a.disableGroupSeparators, disableGroupSeparators = _e === void 0 ? false : _e, _f = _a.disableAbbreviations, disableAbbreviations = _f === void 0 ? false : _f, _decimalSeparator = _a.decimalSeparator, _groupSeparator = _a.groupSeparator, onChange = _a.onChange, onFocus = _a.onFocus, onBlur = _a.onBlur, onKeyDown = _a.onKeyDown, onKeyUp = _a.onKeyUp, props = __rest(_a, ["allowDecimals", "allowNegativeValue", "id", "name", "className", "customInput", "decimalsLimit", "defaultValue", "disabled", "maxLength", "value", "onValueChange", "fixedDecimalLength", "placeholder", "decimalScale", "prefix", "suffix", "intlConfig", "step", "min", "max", "disableGroupSeparators", "disableAbbreviations", "decimalSeparator", "groupSeparator", "onChange", "onFocus", "onBlur", "onKeyDown", "onKeyUp"]);
var _b = _a.allowDecimals, allowDecimals = _b === void 0 ? true : _b, _c = _a.allowNegativeValue, allowNegativeValue = _c === void 0 ? true : _c, id = _a.id, name = _a.name, className = _a.className, customInput = _a.customInput, decimalsLimit = _a.decimalsLimit, defaultValue = _a.defaultValue, _d = _a.disabled, disabled = _d === void 0 ? false : _d, userMaxLength = _a.maxLength, userValue = _a.value, onValueChange = _a.onValueChange, fixedDecimalLength = _a.fixedDecimalLength, placeholder = _a.placeholder, decimalScale = _a.decimalScale, prefix = _a.prefix, suffix = _a.suffix, intlConfig = _a.intlConfig, step = _a.step, min = _a.min, max = _a.max, _e = _a.disableGroupSeparators, disableGroupSeparators = _e === void 0 ? false : _e, _f = _a.disableAbbreviations, disableAbbreviations = _f === void 0 ? false : _f, _decimalSeparator = _a.decimalSeparator, _groupSeparator = _a.groupSeparator, onChange = _a.onChange, onFocus = _a.onFocus, onBlur = _a.onBlur, onKeyDown = _a.onKeyDown, onKeyUp = _a.onKeyUp, transformRawValue = _a.transformRawValue, props = __rest(_a, ["allowDecimals", "allowNegativeValue", "id", "name", "className", "customInput", "decimalsLimit", "defaultValue", "disabled", "maxLength", "value", "onValueChange", "fixedDecimalLength", "placeholder", "decimalScale", "prefix", "suffix", "intlConfig", "step", "min", "max", "disableGroupSeparators", "disableAbbreviations", "decimalSeparator", "groupSeparator", "onChange", "onFocus", "onBlur", "onKeyDown", "onKeyUp", "transformRawValue"]);
if (_decimalSeparator && isNumber(_decimalSeparator)) {

@@ -377,2 +378,3 @@ throw new Error('decimalSeparator cannot be a number');

prefix: prefix || localeConfig.prefix,
transformRawValue: transformRawValue,
};

@@ -379,0 +381,0 @@ var formattedStateValue = defaultValue !== undefined && defaultValue !== null

{
"name": "react-currency-input-field",
"version": "3.5.1",
"version": "3.6.0",
"description": "React <input/> component for formatting currency and numbers.",

@@ -15,3 +15,3 @@ "files": [

"start": "parcel src/examples/index.html",
"test": "jest --coverage",
"test": "jest --coverage --roots ./src",
"test-ci": "cross-env NODE_ICU_DATA=node_modules/full-icu jest --coverage",

@@ -18,0 +18,0 @@ "lint": "tsc && eslint 'src/**/*.{js,ts,tsx}' --max-warnings=0",

@@ -96,2 +96,3 @@ # React Currency Input Field Component

| step | `number` | | Incremental value change on arrow down and arrow up key press |
| transformRawValue | `function` | | Transform the raw value from the input before parsing. Needs to return `string`. |

@@ -98,0 +99,0 @@ ### Abbreviations

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