
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
@ericblade/react-currency-input
Advanced tools
Modern React component for currency input. Fork from https://github.com/jsillitoe/react-currency-input
Supports custom decimal and thousand separators as well as precision.
Uniquely formats while inputting, including decimal and thousands separators, precision, prefixes and suffixes. I have not found any other currency inputs that do this, and the original hasn't been touched for quite a long time, so that is why I fork this.
There is a CodePen available which you may use to see the component in action, and play with all of it's various parameters to see how it works. It is written with React and TypeScript. Codepen Link
There is a second CodePen, which mirrors the demonstration application in the "examples" directory here in the source: Codepen Link
npm install react-currency-input --save
You can store the value passed in to the change handler in your state.
import React from 'react'
import CurrencyInput from 'react-currency-input';
const MyApp = React.createClass({
getInitialState(){
return ({amount: "0.00"});
},
handleChange(event, maskedvalue, floatvalue){
this.setState({amount: maskedvalue});
},
render() {
return (
<div>
<CurrencyInput value={this.state.amount} onChangeEvent={this.handleChange}/>
</div>
);
}
});
export default MyApp
You can also assign a reference then access the value using a call to getMaskedValue().
import React from 'react'
import CurrencyInput from 'react-currency-input';
const MyApp = React.createClass({
handleSubmit(event){
event.preventDefault();
console.log(this.refs.myinput.getMaskedValue())
},
render() {
return (
<form onSubmit={this.handleSubmit}>
<CurrencyInput ref="myinput" />
</form>
);
}
});
export default MyApp
Specify custom decimal and thousand separators:
// 1.234.567,89
<CurrencyInput decimalSeparator="," thousandSeparator="." />
Specify a specific precision:
// 123,456.789
<CurrencyInput precision="3" />
// 123,456,789
<CurrencyInput precision="0" />
Optionally set a currency symbol as a prefix or suffix
// $1,234,567.89
<CurrencyInput prefix="$" />
// 1,234,567.89 kr
<CurrencyInput suffix=" kr" />
Negative signs come before the prefix
// -$20.00
<CurrencyInput prefix="$" value="-20.00" />
All other attributes are applied to the input element. For example, you can integrate bootstrap styling:
<CurrencyInput className="form-control" />
Option | Default Value | Description |
---|---|---|
value | 0 | The initial currency value |
onChangeEvent | n/a | Callback function to handle value changes |
precision | 2 | Number of digits after the decimal separator |
decimalSeparator | '.' | The decimal separator |
thousandSeparator | ',' | The thousand separator |
inputType | "text" | Input field tag type. You may want to use number or tel * |
allowNegative | false | Allows negative numbers in the input |
allowEmpty | false | If no value is given, defines if it starts as null (true ) or '' (false ) |
selectAllOnFocus | false | Selects all text on focus or does not |
prefix | '' | Currency prefix |
suffix | '' | Currency suffix |
autoFocus | false | Autofocus |
onClick | none | Passed through to input |
onFocus | none | Called after internal focus handling |
onBlur | none | Called after internal blur handling |
style | none | Passed through to input |
id | none | Passed through to input |
tabIndex | none | Passed through to 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.
FAQs
React component for inputting currency amounts
The npm package @ericblade/react-currency-input receives a total of 890 weekly downloads. As such, @ericblade/react-currency-input popularity was classified as not popular.
We found that @ericblade/react-currency-input demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.