Socket
Socket
Sign inDemoInstall

react-currency-mask

Package Overview
Dependencies
3
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.0 to 1.3.0

2

lib/functions/format.d.ts

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

export declare const formatCurrency: (value: number, currencyType?: string, hideSymbol?: boolean) => string;
export declare const formatCurrency: (locale: string | undefined, value: number, currencyType?: string, hideSymbol?: boolean) => string;

@@ -5,4 +5,4 @@ "use strict";

const SYMBOL_LENGTH = 3;
const formatCurrency = (value, currencyType = 'BRL', hideSymbol = false) => {
const formatter = new Intl.NumberFormat('pt-BR', {
const formatCurrency = (locale = 'pt-BR', value, currencyType = 'BRL', hideSymbol = false) => {
const formatter = new Intl.NumberFormat(locale, {
style: 'currency',

@@ -9,0 +9,0 @@ currency: currencyType,

export declare const clearNumber: (number: any) => number;
export declare const normalizeValue: (number: string | number) => number;
export declare const maskValues: (inputFieldValue: string | number | undefined, currency: string, shouldCutSymbol: boolean) => (string | number)[];
export declare const maskValues: (locale: string, inputFieldValue: string | number | undefined, currency: string, shouldCutSymbol: boolean) => (string | number)[];

@@ -32,9 +32,9 @@ "use strict";

exports.normalizeValue = normalizeValue;
const maskValues = (inputFieldValue, currency, shouldCutSymbol) => {
const maskValues = (locale, inputFieldValue, currency, shouldCutSymbol) => {
if (!inputFieldValue)
return [0, ''];
const value = (0, exports.normalizeValue)(inputFieldValue);
const maskedValue = (0, format_1.formatCurrency)(value, currency, shouldCutSymbol);
const maskedValue = (0, format_1.formatCurrency)(locale, value, currency, shouldCutSymbol);
return [value, maskedValue];
};
exports.maskValues = maskValues;

@@ -9,6 +9,6 @@ "use strict";

const helpers_1 = require("./functions/helpers");
exports.CurrencyInput = (0, react_2.forwardRef)(({ InputElement, value, defaultValue, hideSymbol = false, currency = 'BRL', max, autoSelect, autoReset, onChangeValue, onBlur, onFocus, onKeyPress, ...otherProps }, ref) => {
exports.CurrencyInput = (0, react_2.forwardRef)(({ InputElement, value, defaultValue, hideSymbol = false, currency = 'BRL', locale = 'pt-BR', max, autoSelect, autoReset, onChangeValue, onBlur, onFocus, onKeyPress, ...otherProps }, ref) => {
const [maskedValue, setMaskedValue] = (0, react_2.useState)('0');
const updateValues = (originalValue) => {
const [calculatedValue, calculatedMaskedValue] = (0, helpers_1.maskValues)(originalValue, currency, hideSymbol);
const [calculatedValue, calculatedMaskedValue] = (0, helpers_1.maskValues)(locale, originalValue, currency, hideSymbol);
if (!max || calculatedValue <= max) {

@@ -30,3 +30,3 @@ setMaskedValue(calculatedMaskedValue);

if (autoReset) {
(0, helpers_1.maskValues)(0, currency, hideSymbol);
(0, helpers_1.maskValues)(locale, 0, currency, hideSymbol);
}

@@ -49,3 +49,3 @@ if (maskedValue && onBlur) {

const currentValue = value || defaultValue || undefined;
const [, maskedValue] = (0, helpers_1.maskValues)(currentValue, currency, hideSymbol);
const [, maskedValue] = (0, helpers_1.maskValues)(locale, currentValue, currency, hideSymbol);
setMaskedValue(maskedValue);

@@ -52,0 +52,0 @@ }, [currency, defaultValue, hideSymbol, value]);

@@ -8,2 +8,3 @@ import { ChangeEvent, FocusEvent, KeyboardEvent, ReactElement } from 'react';

currency?: string;
locale?: string;
hideSymbol?: boolean;

@@ -10,0 +11,0 @@ autoSelect?: boolean;

{
"name": "react-currency-mask",
"version": "1.2.0",
"version": "1.3.0",
"description": "React Input that handles and apply currency masks in your own inputs",

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

@@ -69,2 +69,5 @@ # React Currency Mask

`locale`
Optional, locale you want to format currency. Default is `pt-BR`.
`hideSymbol`

@@ -121,3 +124,3 @@ Optional, boolean to control the currency symbol display.

<small style="color: #c08d78;"><u>\*This example uses a MUI TextField</u></small>
<u>\*This example uses a MUI TextField</u>

@@ -159,3 +162,3 @@ **Example output**

<small style="color: #c08d78;"><u>\*Input Element is optional, use it just if you want a custom input</u></small>
<u>\*Input Element is optional, use it just if you want a custom input</u>

@@ -162,0 +165,0 @@ ---

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc