3.4.0 • Published 2 months ago

@tadashi/currency v3.4.0

Weekly downloads
40
License
MIT
Repository
github
Last release
2 months ago

Currency

Build Status Coverage Status

The simple and tiny script for currency input mask

Install

$ npm i @tadashi/currency

API

new Currency(input [, opts])

Constructs a new Currency instance for a given input element.

parametertyperequireddefaultdescription
inputHTMLElementyes-The input element
optsObjectnosee belowOptional settings

opts

parametertyperequireddefaultdescription
keyEventStringnoinputThe event type for input
triggerOnBlurBooleannofalseTrigger event on blur
initBooleannofalseInitialize masking on instance creation
backspaceBooleannofalseHandle backspace
maskOptsObjectnosee belowMasking options

maskOpts

parametertyperequireddefaultdescription
digitsNumberno2The number of digits after the decimal point
emptyBooleannofalseAllow empty value
localesString or Arraynopt-BRThe locales to use for formatting - Intl.NumberFormat()
optionsObjectno-Additional options for formatting - Intl.NumberFormat()
viaInputBooleannofalseSpecify if the value is coming directly from an input

getUnmasked()

Get the unmasked value of the input.


Static methods

Currency.data(input)

Check if input has a Currency instance.

parametertyperequireddefaultdescription
inputHTMLInputElementyes-The input element

Currency.masking(v [, opts])

Formats a numeric value as a currency string with masking.

parametertyperequireddefaultdescription
vStringNumberyes-
optsObjectnosee aboveMasking options

Currency.unmasking(v)

Convert a masked value into an unmasked numeric value.

parametertyperequireddefaultdescription
vStringyes-The masked input value.
digitsNumberno2The number of digits after the decimal point.

Usage

Codepen example: https://codepen.io/lagden/pen/jOrZVjg?editors=1010

<input id="money" type="text" inputmode="numeric">

<script type="module">
  import Currency from 'https://unpkg.com/@tadashi/currency@{version}/src/currency.js'

  // Instance
  const mask = new Currency(money)

  // Static mode
  Currency.masking(1100) // => 1.100,00
</script>

Buy Me a Coffee

BTC: bc1q7famhuj5f25n6qvlm3sssnymk2qpxrfwpyq7g4

License

MIT © Thiago Lagden

3.4.0

2 months ago

3.3.3

2 months ago

3.3.1

7 months ago

3.3.0

7 months ago

3.3.2

6 months ago

3.2.0

3 years ago

3.1.0

3 years ago

3.0.0

3 years ago

2.0.0

3 years ago

1.2.0

3 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago