Skip to content

nigivamu/currency

 
 

Repository files navigation

Currency

Build Status Coverage Status XO code style

The simple and tiny script for currency input mask

Install

$ npm i -S @tadashi/currency

API

new Currency(input [, opts])

parameter type required default description
input HTMLInputElement yes - Input element
opts Object no see below Options

opts

parameter type required default description
keyEvent String no input Event which trigger mask
triggerOnBlur Boolean no false Trigger the mask when blur event occurs
init Boolean no false Format value when create instance
backspace Boolean no false Allow cleanup the input
maskOpts Object no see below Mask Options

maskOpts

parameter type required default description
empty Boolean no false Keep input empty if value is 0
locales String or Array no pt-BR Same locales Intl.NumberFormat()
options Object no {minimumFractionDigits: 2} Same options Intl.NumberFormat()

Static methods

Currency.data(input)

Return the instance of Currency from HTMLInputElement.

parameter type required default description
input HTMLInputElement yes - Input element

Currency.masking(v [, opts])

Return the value formatted.

parameter type required default description
v String yes - Value which will be masked
opts Object no see above Mask Options

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>

License

MIT © Thiago Lagden

About

The simple and tiny script for currency input mask

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • JavaScript 87.6%
  • HTML 7.9%
  • Shell 4.5%