2.2.1 • Published 7 years ago

@fagnerlima/ng-mask v2.2.1

Weekly downloads
27
License
MIT
Repository
github
Last release
7 years ago

NgMask

npm.io

NgMask is a jQueryMaskPlugin Adapter for Angular.

Dependencies

Usage

  1. Install ng-mask using npm:
npm install @fagnerlima/ng-mask
  1. Import NgMaskModule into Module class:
// ...
import { NgMaskModule } from '@fagnerlima/ng-mask';

@NgModule({
  imports: [
    // ...
    NgMaskModule
  ],
  // ...
})
export class AppModule { }
  1. Insert the directive in form inputs with ngControl (ex. ngModel or formControlName):
import { Component } from '@angular/core';

import { Mask } from '@fagnerlima/ng-mask';

@Component({
  selector: 'app-root',
  template: `
    <h1>NgMask</h1>

    <input type="text" [(ngModel)]="money" [mask]="maskMoney" />
  `
})
export class AppComponent {

  // Masks
  readonly maskCep: string = 'brCep';
  readonly maskCoordinateLat: string = 'coordinateLat';
  readonly maskCoordinateLong: string = 'coordinateLong';
  readonly maskCpf: Mask = new Mask('000.000.000-00');
  readonly maskDecimal: string = 'decimal(10,2)';
  readonly maskInteger: string = 'integer(6)';
  readonly maskMoney: string = '#0.00?reverse=true';
  readonly maskPhone: string = '(00) 00000-0000';

  // Controls
  money: string;
}

Mask Types

Mask Object

Instance of Mask class.

import { Mask } from '@fagnerlima/ng-mask';

const dateMask: Mask = new Mask('00/00/0000');
const percentMask: Mask = new Mask('##0,00%', { reverse: true })

Default Mask

String that represents pattern attribute of Mask class, using default jokers of jQueryMaskPlugin, without extra options.

const dateMask: string = '00/00/0000';
PatternsjQueryMaskPlugin's Default Configuration
0{ pattern: /\d/ }
9{ pattern: /\d/, optional: true }
#{ pattern: /\d/, recursive: true }
A{ pattern: /[a-zA-Z0-9/ }
S{ pattern: /a-zA-Z/ }

QueryString Mask

String in the QueryString format that contains the pattern and extra options of Mask class.

const percentMask: string = '##0,00%?reverse=true&placeholder=000,00%';
Supported Extra Options
clearIfNotMatch
placeholder
reverse
selectOnFocus

Predefined Type Mask

String that contains a predefined type.

const coordinateLatMask: string = 'coordinateLat';
const coordinateLongMask: string = 'coordinateLong';
Predefined TypesPatternExample
brCelularnew Mask('(00) 00009-0000')(11) 95683-1298
brCepnew Mask('00000-000')58035-110
brCnpjnew Mask('00.000.000/0000-00')13.456.131/0000-12
brCpfnew Mask('000.000.000-00')034.465.789-13
brDatanew Mask('00/00/0000')15/10/2016
brMoedanew Mask('#.##0,00', { reverse: true })2.199,99
brTelefonenew Mask('(00) 0000-0000')(83) 3638-8973
usPhonenew Mask('(000) 000-0000')(581) 555-5895
coordinateLatnew Mask('000º00.0000\'~', { translation: { '~': { pattern: /N|S/ } } })123º54.7894'N
coordinateLongnew Mask('000º00.0000\'~', { translation: { '~': { pattern: /E|W/ } } })354º79.6452'E
datenew Mask('00/00/0000')01/31/2017
dateTimenew Mask('00/00/0000 00:00:00')05/18/2017 08:30:00
timenew Mask('00:00:00')19:15:00

Numeric Mask

String that contains a numeric type with your precision (and scale for decimal type), similar to many databases.

const integerMask: string = 'integer(6)';
const decimalMask: string = 'decimal(10,2)';
Numeric TypesExamples
integerinteger(6)
decimaldecimal(5,2)
2.2.1

7 years ago

2.2.0

7 years ago

2.1.4

7 years ago

2.1.3

7 years ago

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.1.0-beta.2

7 years ago

2.1.0-beta.1

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0-rc1

7 years ago

1.0.0

7 years ago