Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@fnando/amount-input
Advanced tools
Readme
Add amount masking to inputs with this teeny-tiny-lib.
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";
.
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.
This is the minimum working example:
<input value="0.00">
<script>
amountInput(document.querySelector("input"));
</script>
Available at https://codepen.io/fnando/pen/VGExVv
(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.
FAQs
Add amount masking for inputs.
The npm package @fnando/amount-input receives a total of 11 weekly downloads. As such, @fnando/amount-input popularity was classified as not popular.
We found that @fnando/amount-input demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.