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

ngx-mask-number

v1.0.1

Published

Angular directive to mask number inputs for display while keeping raw numeric values in forms.

Readme

ngx-mask-number

A lightweight Angular directive that formats number inputs for display using Intl.NumberFormat — while binding raw numeric values to your forms.
Just add the directive, and you're good to go!


✨ Features

  • 💡 Shows formatted numbers in the input (e.g. 1,234.56)
  • 💎 Emits raw numeric value to your form (e.g. 1234.56)
  • 🌍 Locale-aware formatting using Intl.NumberFormat
  • ✅ Works with both Reactive and Template-driven forms
  • 🔥 Compatible with Angular 15–18 (standalone + module support)

📦 Installation

npm install ngx-mask-number

💡 Live Demo

Live Demo

🚀 Usage

✅ 1. Import in Standalone Component (Angular 15+)

import { NgxNumberMaskDirective } from 'ngx-mask-number';

@Component({ standalone: true, selector: 'app-root', imports: [ReactiveFormsModule, NgxNumberMaskDirective], template: <form [formGroup]="form"> <label>Price:</label> <input formControlName="price" ngxNumberMask [locale]="'en-US'" /> <p>Raw Value: {{ form.value.price }}</p> </form> }) export class AppComponent { form = inject(FormBuilder).nonNullable.group({ price: [null] }); }

✅ 2. Or Import in NgModule (Angular 14+) import { NgxNumberMaskDirective } from 'ngx-mask-number';

@NgModule({ declarations: [...], imports: [ BrowserModule, ReactiveFormsModule, NgxNumberMaskDirective ], bootstrap: [AppComponent] }) export class AppModule {}


🧪 Reactive Forms Example

form = this.fb.group({ price: [null] });


💡 Template-driven Forms Example

<input type="text" [(ngModel)]="amount" name="amount" ngxNumberMask [locale]="'en-US'" />


✅ Supports any BCP-47 locale string (like 'de-DE', 'fr-FR', 'hi-IN', etc.)

💬 How It Works

🧠 While typing: formats input using the given locale

💾 Emits raw number to the form control (FormControl or ngModel)

🖱 On blur: final formatting is applied

🔢 Keeps cursor in the right place after formatting

🔒 Blocks multiple decimals, invalid characters, and ensures clean numeric entry

Because formatting numbers in Angular inputs is surprisingly tricky:

Built-in number inputs don’t support formatting

🧩 Libraries like ngx-mask can format inputs and emit raw values, but they often suffer from cursor jumping and inconsistent behavior with decimals — especially in dynamic forms.

This directive formats the input but gives you a clean raw value, ready for API use


💻 Compatibility

| Feature | Supported? | | ---------------- | ---------- | | Angular 15–18 | ✅ Yes | | Standalone apps | ✅ Yes | | Module-based | ✅ Yes | | SSR/Universal | ✅ Yes | | No external deps | ✅ Yes |


Made with ❤️ by TK