Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@canutin/svelte-currency-input
Advanced tools
An input field that formats numbers to currency as you type
A form input that converts numbers to currencies as you type in localized formats
Intl.NumberFormat
for localizing currency denominations and masking the inputnpm install svelte-currency-input --save
<script lang="ts">
import CurrencyInput from '@canutin/svelte-currency-input';
const locale = 'nl-NL';
const currency = 'EUR';
</script>
<CurrencyInput name="exchange-rate" value={-420.69} {locale} {currency} />
When the form is submitted you get unformatted or formatted values from two <input />
's.
This is more or less what <CurrencyInput />
looks like under the hood:
<div class="currencyInput">
<!-- Unformatted value -->
<input class="currencyInput__unformatted" type="hidden" name="total" />
<!-- Formatted value -->
<input class="currencyInput__formatted" type="text" name="formattedTotal" />
</div>
Option | Type | Default | Description |
---|---|---|---|
value | number | undefined | Initial value. If left undefined a formatted value of 0 is visible as a placeholder |
locale | string | en-US | Overrides default locale. Examples |
currency | string | USD | Overrides default currency. Examples |
name | string | total | Applies the name to the input fields for unformatted (e.g [name=total] ) and formatted (e.g. [name=formattedTotal] in camelCase) values |
required | boolean | false | Marks the inputs as required |
disabled | boolean | false | Marks the inputs as disabled |
isNegativeAllowed | boolean | true | If true , forces formatting only to positive values and ignores --positive and --negative styling modifiers |
The default styles use BEM naming conventions. To override the default styles apply your styles as shown below:
<div class="my-currency-input">
<CurrencyInput name="total" value={420.69} />
</div>
<style>
/* Container */
div.my-currency-input :global(div.currencyInput) { /* ... */}
/* Formatted input */
div.my-currency-input :global(input.currencyInput__formatted) { /* ... */}
/* Formatted input when the value is zero */
div.my-currency-input :global(input.currencyInput__formatted--zero) { /* ... */}
/* Formatted input when the value is positive */
div.my-currency-input :global(input.currencyInput__formatted--positive) { /* ... */}
/* Formatted input when the value is negative */
div.my-currency-input :global(input.currencyInput__formatted--negative) { /* ... */}
</style>
Here's ways in which you can contribute:
This package was generated with SvelteKit.
Install dependencies with npm install
, then start a development server:
npm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --open
FAQs
A form input that converts numbers to currencies as you type in localized formats
We found that @canutin/svelte-currency-input demonstrated a healthy version release cadence and project activity because the last version was released less than 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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.