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

ng-number-input

v1.0.2

Published

Angualr form input that adds group and decimal separators to numbers as you type.

Downloads

37

Readme

ng-number-input

Angualr form input that adds group and decimal separators to numbers as you type.

Built on top of HTML text input using ControlValueAccessor to support Angular forms API.

Formatting is mostly done using Intl.NumberFormat.

Demo

Play around with the API on StackBlitz. enter image description here

Usage Instructions

  1. Run the following command in your application's root directory to install the package.

    
    npm i ng-number-input --save
    
  2. Add NgNumberInputModule to the imports array of your module.

  3. Use the below component selector in your templates.

    
    <ng-number-input></ng-number-input>
    

API

Inputs

  • [mode]

    
    @Input() mode: string= 'default';
    

    This component runs in one of three modes, default, lazy or string.

    default:

    • As the name suggests, this is the default mode. In this mode the numbers are automatically formatted while the user is typing.

    • The values are stored as number and can only lie between negative Number.MAX_SAFE_INTEGER and Number.MAX_SAFE_INTEGER.

    string:

    • In this mode, the numbers are automatically formatted while the user is typing.

    • The values are stored as string and there is no limit on the number it can hold.

    • The formatting is done using regex in this mode. So [locale] input is not supported. The default formatting is done like 'en-US'.

    lazy:

    • In this mode, plain number is displayed while the user is interacting with the input, and formatted number is displayed once the user stops interacting.

    • The values are stored as number and can only lie between -Number.MAX_SAFE_INTEGER and Number.MAX_SAFE_INTEGER.

  • [locale]

    
    @Input() locale = ['en-US', {maximumFractionDigits:3}];
    

    With this input you can specify the locale used to format the number.

    It is an array of size 2 and its 0th element is a string and the 1st element is an options object.

    Example:

    ['en-US',{maximumFractionDigits:2}]

    Refer to the documentation on Intl.NumberFormat for more details.

    This input is ignored in string mode.

    Note: All locales and locale options are not supported in all modes. Please try out the demo with your preferred locale options. More locales and locale options will be supported in future and you are welcome to contribute.

  • [limitTo]

    
    @Input() limitTo: number = 3;
    

    Limit the maximum number of values after the decimal point(radix). You can specify a value between 1 - 3

    This input overrides maximumFractionDigits in locale options.

  • [max]

    
    @Input() max: number;
    

    maximum value the input can hold. It is capped at Number.MAX_SAFE_INTEGER.

  • [min]

    
    @Input() min:number;
    

    minimum value the input can hold. It is capped at -Number.MAX_SAFE_INTEGER.

  • [format]

    
    @Input() format;
    

    Use this function to append custom text to brfore or after the formatted number. The below example demonstrates how to pass a custom function that adds $ sign to the formatted number.

    Note: Do not use digits, fraction separators and group separators while formatting.

     example:
    
    	  
    
     ```
    
     format(text:string): string{
    
     return '$' + text
    
     }
    
     <ng-number-input
    
     [limitTo]="2"
    
     [(ngModel)]="test"
    
     [format]="format"
    
     required>
    
     </ng-number-input>
    
     ```
    
      
  • [name]

    
    @Input() name: string;
    

    Name attribute for the underlying input element.

  • [placeholder]

    
    @Input() placeholder: string = '';
    

    Placeholder attribute for the underlying input element.

  • [customStyle]

    
    @Input() customStyle: any = { height: '100%', width: '100%', border: 'none', outline: 'none', padding: '0px' };
    

    Add styles to the underlying html input element by passing as a json.

    Example:

    
    {
    
    height: '69px',
    
    width: '100%',
    
    maxWidth: '671px',
    
    margin: '0px auto',
    
    fontSize: '18px',
    
    left: '0px',
    
    padding: '0px 20px'
    
    }
    
  • [parseInt]

    
    @Input() parseInt:boolean = false;
    

    It is a boolean type input. If set to true, decimals will be restricted.

Source Code

You can clone the source code from this GitHub repository.

This library was generated with Angular CLI version 12.1.0.