Playground: https://stackblitz.com/edit/mf-mask
$ npm install @myfarms/mf-mask --save
import { NgModule } from '@angular/core';
import { MfMaskModule } from '@myfarms/mf-mask';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent,
],
imports: [
MfMaskModule.forRoot(),
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
<input type='text' mfMask='(999) 999-9999' [(ngModel)]='model' />
Input | Type | Default | Description |
---|---|---|---|
mfMask | string |
"" |
The input mask |
You can pass in configuration options into the modules forRoot
method.
/* Types and defaults */
interface IPatterns {
[pattern: string]: RegExp;
}
interface IMasks {
[name: string]: string;
}
interface IConfig {
patterns: IPatterns;
preparedMasks: IMasks;
}
const initialConfig: IConfig = {
patterns: {
a: new RegExp(/[a-z]/),
A: new RegExp(/[A-Z]/),
Z: new RegExp(/[a-zA-Z]/),
9: new RegExp(/[0-9]/)
},
preparedMasks: {
PHONE: "(999) 999-9999"
}
};
/* In your module */
MfMaskModule.forRoot({
patterns: {
N: new RegExp(/[a-zA-Z0-9]/),
},
preparedMasks: {
PHONE: '999 999 9999',
CODE: 'NNNNN',
},
})
To generate all *.js
, *.d.ts
and *.metadata.json
files:
$ npm run build
To lint all *.ts
files:
$ npm run lint
MIT © MyFarms