
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
format-currency-input
Advanced tools
format-currency-input is a small utility that reformats currency in an input and also exposes some helper functions.
Check out a demo.
Intl.NumberFormat; your environment must support it or have the appropriate polyfill.npm i format-currency-input
CommonJS Require:
const formatCurrencyInput = require('format-currency-input')
ES6 Import:
import formatCurrencyInput from 'format-currency-input'
The watch method accepts an input selector and options. It will find all inputs with a given selector via querySelectorAll and then reformat the input on blur.
formatCurrencyInput.watch('.currency-input')
With options:
formatCurrencyInput.watch('.currency-input', {
removeCents: true,
removeSymbol: true,
})
The format and cents methods expose a couple internal helper functions.
formatCurrencyInput.format('2500') // $2,500.00
formatCurrencyInput.format('2500.235') // $2,500.24
formatCurrencyInput.format(200) // $200.00
formatCurrencyInput.format(200, { removeSymbol: true, removeCents: true }) // 200
formatCurrencyInput.cents('$2,500') // 250000
formatCurrencyInput.cents('$2,500.55') // 250055
formatCurrencyInput.cents(2) // 200
formatCurrencyInput.cents(300) // 30000
data-cents AttributeReformatting text in an input is good practice to ensure your users are inputting their amount correctly, but we need to ensure the data we send to our servers is properly formatted – probably in cents.
Upon reformatting, this utility also sets the currency value in cents as the value of data-cents on the input element.
The second argument of any method is an optional options object.
| Option | Default | Use |
|---|---|---|
removeCents | false | Remove cents ($2,500) |
removeSymbol | false | Remove symbol (2,500.00) |
removeCommas | false | Remove commas ($2500.00) |
removeDataCentsAttribute | false | Don't set data-cents after format |
MIT
FAQs
Reformat inputted currency text.
We found that format-currency-input demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.