npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fnando/amount-input

v0.2.5

Published

Add amount masking for inputs.

Downloads

38

Readme

amount-input

Add amount masking to inputs with this teeny-tiny-lib.

Instalation

This lib is available as a NPM package. To install it, use the following command:

npm install @fnando/amount-input --save

If you're using Yarn (and you should):

yarn add @fnando/amount-input

You'll have to call amountInput.amountInput(input, options) directly if you're loading the script without compiling your script (e.g. webpack). Otherwise you can simply import amountInput from "@fnando/amount-input";.

API

amountInput(input, options = {})

Enable the amountInput behaviour on input. You can customize it with the following options:

  • input: The <input> element you want to control.
  • options: This optional argument allows you to further customize the input behaviour. The available options are:
    • precision: Sets the level of precision (defaults to 2). When precision is 0, then only integers will be accepted.
    • separator: Sets the separator between the units (defaults to .).
    • delimiter: Sets the thousands delimiter (defaults to ,).
    • willAcceptAmount: Sets the callback that will validate the acceptance of the new amount. If this callback returns false, then the amount won't be accepted and the onRejectAmount callback will be executed. Defaults to a callback that accepts any amount. The callback signature is callback(newAmount).
    • onAcceptAmount: Sets the the callback that will be executed after an amount has been accepted. Default to a no-op callback. The callback signature is callback(input, amount).
    • onRejectAmount: Sets the the callback that will be executed when an amount is rejected by willAcceptAmount. The callback signature is callback(input, rejectedAmount, amount).

This function allow us to update the amount hold by amountInput. Otherwise, you won't be able to set an arbitrary value. Notice that the new amount that's being set is subjected to the willAcceptAmount condition.

amountInput.format(number, options)

Stand-alone formatting numbers. Accept precision, separator, and delimiter options, like described above.

Usage

This is the minimum working example:

<input value="0.00">

<script>
  amountInput(document.querySelector("input"));
</script>

Examples

Available at https://codepen.io/fnando/pen/VGExVv

License

(The MIT License)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.