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

@canutin/svelte-currency-input

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@canutin/svelte-currency-input

A form input that converts numbers to currencies as you type in localized formats

  • 0.5.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
395
increased by7.63%
Maintainers
1
Weekly downloads
 
Created
Source

svelte-currency-input

A form input that converts numbers to localized currency formats as you type

image

👩‍💻 Play with it on REPL  —  💵 See it in a real project!


Features

Usage

npm install svelte-currency-input --save
<script lang="ts">
  import CurrencyInput from '@canutin/svelte-currency-input';
</script>

<CurrencyInput name="total" value={-420.69} locale="nl-NL" currency="EUR" />

How it works

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"
    value="-420.69"
  />

  <!-- Formatted value -->
  <input
    class="currencyInput__formatted"
    type="text"
    name="formatted-total"
    value="€ -420,69"
  />
</div>

API

OptionTypeDefaultDescription
valuenumberundefinedInitial value. If left undefined a formatted value of 0 is visible as a placeholder
localestringen-USOverrides default locale. Examples
currencystringUSDOverrides default currency. Examples
namestringtotalApplies the name to the input fields for unformatted (e.g [name=total]) and formatted (e.g. [name=formatted-total]) values
requiredbooleanfalseMarks the inputs as required
disabledbooleanfalseMarks the inputs as disabled
placeholdernumber null0Overrides the default placeholder. Setting the value to a number will display it as formatted. Setting it to null will not show a placeholder
isNegativeAllowedbooleantrueIf false, forces formatting only to positive values and ignores --positive and --negative styling modifiers
fractionDigitsnumber2Sets maximumFractionDigits in Intl.NumberFormat() constructor used for formatting the currency. Supported digits: 0 to 20

Styling

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 it's disabled */
  div.my-currency-input :global(input.currencyInput__formatted:disabled) { /* ... */ }

  /* 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>

Contributing

Here's ways in which you can contribute:

Developing

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

Keywords

FAQs

Package last updated on 17 Sep 2022

Did you know?

Socket

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.

Install

Related posts

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