MCPcopy Index your code
hub / github.com/NepipenkoIgor/ngx-mask

github.com/NepipenkoIgor/ngx-mask @v2.2.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.2.0 ↗ · + Follow
363 symbols 936 edges 119 files 32 documented · 9% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ngx-mask

A powerful Angular directive for input masking with customizable patterns

CI npm version npm downloads npm monthly downloads Bundle size TypeScript support License GitHub contributors GitHub Stars

ngx-mask gives Angular forms real-time input masking without hand-rolling regex-based Validators.pattern hacks or reaching for a generic, framework-agnostic library like text-mask/imask that needs its own Angular adapter. It ships as a standalone directive and pipe (NgxMaskDirective / NgxMaskPipe) with first-class ControlValueAccessor and Reactive Forms integration, built-in patterns for numbers, dates, and custom masks with prefixes/suffixes and multiple alternatives, and no runtime dependencies beyond Angular itself — install it, provide it once, and apply a mask with a single input binding.

Table of Contents

Features

NGX-MASK is a feature-rich input mask directive for Angular applications that provides:

### 🎯 Masking Patterns • Custom patterns & expressions • Multiple mask patterns (|) • Built-in common patterns • Prefix & suffix support ### 🔢 Number Formatting • Thousand separators • Decimal markers • Negative numbers • Leading zeros ### ⚡ Input Control • Real-time validation • Clear on non-match • Show/hide mask typing • Keep character positions
### 📅 Date & Time • Leading zero handling • AM/PM support • Custom separators • Multiple formats ### 🛠️ Customization • Custom placeholders • Special characters • Transform functions • Custom validation ### 📋 Form Integration • Reactive Forms • ControlValueAccessor • Built-in validation • Standalone support

Demo

Check out our live documentation and examples

Installation

# For Angular 17 and above
$ npm install ngx-mask    # Using npm
$ bun add ngx-mask       # Using bun

# For specific Angular versions:
# Angular 16.x.x
$ npm install ngx-mask@16.4.2    # Using npm
$ bun add ngx-mask@16.4.2       # Using bun

# Angular 15.x.x
$ npm install ngx-mask@15.2.3    # Using npm
$ bun add ngx-mask@15.2.3       # Using bun

# Angular 14.x.x
$ npm install ngx-mask@14.3.3    # Using npm
$ bun add ngx-mask@14.3.3       # Using bun

# Angular 13.x.x or 12.x.x
$ npm install ngx-mask@13.2.2    # Using npm
$ bun add ngx-mask@13.2.2       # Using bun

Package Manager Note: You can use either npm or bun based on your preference. Both package managers will work equally well with ngx-mask.

Version Compatibility

NGX-MASK follows Angular's official support policy, supporting Active and LTS versions. Currently supported:

  • Angular 17 and newer (latest features and updates)
  • For older Angular versions, use the corresponding NGX-MASK version as specified above

Note: Versions for Angular older than v17 will not receive new features or updates.

Quick Start

ngx-mask ships as a standalone directive (NgxMaskDirective) and pipe (NgxMaskPipe) — there is no NgxMaskModule in current versions. Configuration is registered through one of two provider functions:

  • provideEnvironmentNgxMask(config?) — application-wide config. Use it once in bootstrapApplication / app.config.ts (or a root NgModule's providers).
  • provideNgxMask(config?) — injector-level config. Use it in a component's or feature's providers to configure/override the options for that subtree only.

Directive inputs (e.g. [thousandSeparator]) always override any provider config. See USAGE.md for the full decision guide, examples, and common pitfalls.

Standalone Applications

Application-wide Setup with Default Config

bootstrapApplication(AppComponent, { providers: [provideEnvironmentNgxMask()] }).catch((err) =>
    console.error(err)
);

With Custom Configuration

import { NgxMaskConfig } from 'ngx-mask';

const maskConfig: Partial<NgxMaskConfig> = { validation: false };

bootstrapApplication(AppComponent, { providers: [provideEnvironmentNgxMask(maskConfig)] }).catch(
    (err) => console.error(err)
);

Feature-level Configuration

@Component({
    selector: 'my-feature',
    standalone: true,
    imports: [NgxMaskDirective],
    providers: [provideNgxMask()],
})
export class MyFeatureComponent {}

NgModule-based Applications

Module-based apps import the standalone directive/pipe into imports and register the provider function:

import { NgxMaskDirective, NgxMaskPipe, provideEnvironmentNgxMask } from 'ngx-mask';

@NgModule({
    imports: [NgxMaskDirective, NgxMaskPipe],
    exports: [NgxMaskDirective, NgxMaskPipe],
    providers: [provideEnvironmentNgxMask()],
})
export class AppModule {}

Migrating from ngx-mask ≤ 14 (NgxMaskModule)

NgxMaskModule.forRoot() / forChild() only exist in ngx-mask 14.x and older (Angular < 15):

// Before (ngx-mask <= 14)
@NgModule({ imports: [NgxMaskModule.forRoot(maskConfig)] })
export class AppModule {}

// After (current ngx-mask)
@NgModule({
    imports: [NgxMaskDirective],
    providers: [provideEnvironmentNgxMask(maskConfig)],
})
export class AppModule {}

Related Projects

Contributing

We welcome contributions! Please read our contributing guidelines to learn about our development process and how you can propose bugfixes and improvements.


Maintained by Igor Nepipenko

Extension points exported contracts — how you extend this code

Chainable (Interface)
(no doc)
cypress/support/component.ts

Core symbols most depended-on inside this repo

equal
called by 1898
projects/ngx-mask-lib/src/test/utils/test-functions.component.ts
provideNgxMask
called by 114
projects/ngx-mask-lib/src/lib/ngx-mask.providers.ts
transform
called by 76
projects/ngx-mask-lib/src/lib/ngx-mask.pipe.ts
typeTest
called by 71
projects/ngx-mask-lib/src/test/utils/test-functions.component.ts
equalTextarea
called by 40
projects/ngx-mask-lib/src/test/utils/test-functions.component.ts
createTriModeFixture
called by 24
projects/ngx-mask-lib/src/test/utils/tri-mode-harness.ts
match
called by 20
projects/ngx-mask-lib/src/lib/ngx-mask.directive.ts
focus
called by 19
projects/ngx-mask-lib/src/lib/ngx-mask.directive.ts

Shape

Class 190
Method 120
Function 51
Enum 1
Interface 1

Languages

TypeScript100%

Modules by API surface

projects/ngx-mask-lib/src/lib/ngx-mask.directive.ts40 symbols
projects/ngx-mask-lib/src/test/show-mask-typed-initial-value.cy-spec.ts37 symbols
projects/ngx-mask-lib/src/test/dirty-state.cy-spec.ts36 symbols
projects/ngx-mask-lib/src/lib/ngx-mask.service.ts35 symbols
projects/ngx-mask-lib/src/test/forms.spec.ts29 symbols
projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts15 symbols
projects/ngx-mask-lib/src/test/utils/tri-mode-harness.ts14 symbols
src/test-setup.ts11 symbols
src/app/options/options.component.spec.ts11 symbols
src/app/shared/accordion/accordion.component.ts10 symbols
projects/ngx-mask-lib/src/test/issue-1590.spec.ts9 symbols
projects/ngx-mask-lib/src/test/issue-1379.spec.ts8 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add ngx-mask \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact