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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@lightweightform/numeric-input

v4.13.0

Published

Lightweightform's numeric input

Downloads

6

Readme

Numeric input

Framework-agnostic numeric input elements. This library was created after successive attempts at implementing some numeric input requirements using multiple libraries for the creation of masked inputs such as Inputmask and Text Mask. These libraries offer generic solutions for the creation of masked inputs; unfortunately, some of our requirements for numeric inputs do not fit well with the notion of masks. As such, when attempting to use these libraries we continuously felt the need to override or patch certain library-imposed behaviours. It was thus simpler to create a library tailored to our numeric input needs.

This library converts <input> elements into numeric inputs which support the following:

  • Numbers have a set number of decimal places (scale) and begin to be written from the right-most decimal place, i.e. if the number is set to have a scale of 2 and the user types in 1, the resulting value is '0.01'.
  • Numbers support an arbitrary number of leading zeroes, i.e. if the number is set to have 4 leading zeroes and the user types in 1, the resulting value is '0001'.
  • The numeric input may represent an integer or a floating number; this means that the value '0.01' displayed in the input element may represent either the number 1 (integer) or the number 0.01 (float). Representing numbers as integers removes the risk of floating point errors.
  • Numeric inputs may set their minimum and maximum values which are validated as appropriate while the user is typing. Out of bound values may still be programmatically set on the numeric input.
  • A number's signal may be toggled by typing - anywhere in the input element.
  • Prefixes and suffixes are supported, e.g. specifying a prefix of '$' will result in the number 0.01 to be formatted as '$0.01'; a suffix of '€' results in '0.01 €'.
  • The decimal and thousands separators of the numeric input may be specified, this means that we may choose to display the number 1234567.89 as '1.234.567,89' by setting the decimal separator as ',' and the thousands separator as '.'.
  • A number being written is automatically formatted as it is being written and the caret position is properly updated.
  • Empty values are supported (they represent null) and result from deleting the whole input element's text or from pressing Backspace or Delete when the numeric input's value is 0.

Allowed <input> elements

The library will work with inputs of type text, search, tel, and password; unfortunately, the number type is not supported. It is currently recommended to use a type of text as the tel type forces a virtual keyboard which, in some devices, does not contain a - key. In the future, the recommended way of forcing a numeric virtual keyboard should be with the attribute inputmode set to "numeric", see: Can I use... for browser compatibility.

Example usage

import { NumericInput } from '@lightweightform/numeric-input';

const inputElement = document.getElementById('some-input-element');
const numericInput = new NumericInput(inputElement, {
  numericRepresentation: 'int',
  scale: 2,
  suffix: ' €',
  decimalSeparator: ',',
  thousandsSeparator: ' ',
});

numericInput.update('1234567');
numericInput.toString(); // `'1 234,67 €'`
numericInput.toNumber(); // `1234567`

API

The @lightweightform/numeric-input API is available at: https://docs.lightweightform.io/api/numeric-input.

Support

  • Internet Explorer: 11 (requires a String.prototype.repeat() polyfill)
  • Other browsers: Latest 2 versions

Limitations

  • We use Number.prototype.toFixed(scale) to help format numbers. Most browsers support scale up to 100 (maximum value the numeric input API allows), however, some browsers only support scale up to 20 (which is valid according to the spec), so set scale > 20 at your own risk (will throw an exception in unsupported browsers).