1.0.0 • Published 4 years ago

rupiaf v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

Rupiaf.js

Rupiaf is a dead simple converter number to rupiah format. written with TypeScript and transform it to vanilla JS, no dependencies.

Features

  • Lightweight.
  • Flexible.
  • Support form element, but you must to use clean() method on submit event listener. See example below.

Note: demo above use my own css to styling input element, it's excluded from this library.

Build Tool (Webpack)

Coming soon.

Add To Your HTML Page

Load the production mode if you don't use any build tools.

index.html

...
<form method="get" action="#" id="nominalForm">
        <label class="label" for="nominal">Rp.</label>
        <input id="nominal" type="text" name="nominal" placeholder="Nominal" autocomplete="off">
</form>
<script src="dist/scripts/rupiaf.js"></script>
<script src="dist/scripts/app.js"></script>
...

app.js

document.addEventListener('DOMContentLoaded', function() {
        var nominalInput = document.querySelector('#nominal');
        var nominalForm = document.querySelector('#nominalForm');
        nominalInput.addEventListener('keyup', function(event) {
                var rupiaf = new Rupiaf(event.target.value);

                event.target.value = rupiaf.convert()
        })
        nominalForm.addEventListener('submit', function() {
                var rupiaf = new Rupiaf(nominalInput.value)
                nominalInput.value = rupiaf.clean()
        })
        
});
1.0.0

4 years ago