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

@fagnerlima/ng-mask

v2.2.1

Published

jQueryMaskPlugin Adapter for Angular

Downloads

489

Readme

NgMask

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';

| Patterns | jQueryMaskPlugin'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 Types | Pattern | Example | |-|-|-| | brCelular | new Mask('(00) 00009-0000') | (11) 95683-1298 | | brCep | new Mask('00000-000') | 58035-110 | | brCnpj | new Mask('00.000.000/0000-00') | 13.456.131/0000-12 | | brCpf | new Mask('000.000.000-00') | 034.465.789-13 | | brData | new Mask('00/00/0000') | 15/10/2016 | | brMoeda | new Mask('#.##0,00', { reverse: true }) | 2.199,99 | | brTelefone | new Mask('(00) 0000-0000') | (83) 3638-8973 | | usPhone | new Mask('(000) 000-0000') | (581) 555-5895 | | coordinateLat | new Mask('000º00.0000\'~', { translation: { '~': { pattern: /[N|S]/ } } }) | 123º54.7894'N | | coordinateLong | new Mask('000º00.0000\'~', { translation: { '~': { pattern: /[E|W]/ } } }) | 354º79.6452'E | | date | new Mask('00/00/0000') | 01/31/2017 | | dateTime | new Mask('00/00/0000 00:00:00') | 05/18/2017 08:30:00 | | time | new 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 Types | Examples | |-|-| | integer | integer(6) | | decimal | decimal(5,2) |