UNPKG

4.44 kBMarkdownView Raw
1<a href="http://jsdaddy.io/img/logo.png">
2 <h1 align="center">NGX MASK</h1>
3</a>
4
5<p align="center">
6 NGX MASK is the best directive to solve masking input with needed pattern
7</p>
8
9[![CI](https://github.com/JsDaddy/ngx-mask/actions/workflows/quality-check.yml/badge.svg?branch=develop)](https://github.com/JsDaddy/ngx-mask/actions/workflows/main.yml)
10[![npm](https://img.shields.io/npm/v/ngx-mask.svg)](https://www.npmjs.com/package/ngx-mask)
11[![npm downloads](https://img.shields.io/npm/dt/ngx-mask.svg)](https://npmjs.org/ngx-mask)
12
13[![npm](https://img.shields.io/npm/dm/ngx-mask.svg)](https://www.npmjs.com/package/ngx-mask)
14
15[![GitHub contributors](https://img.shields.io/github/contributors/JSDaddy/ngx-mask.svg?style=flat)](https://github.com/JSDaddy/ngx-mask)
16
17[![GitHub stars](https://img.shields.io/github/stars/JSDaddy/ngx-mask.svg?label=GitHub%20Stars&style=flat)](https://github.com/JSDaddy/ngx-mask)
18
19You can also try our NGX LOADER INDICATOR [check](https://www.npmjs.com/package/ngx-loader-indicator).
20You can also try our NGX COPYPASTE [check](https://www.npmjs.com/package/ngx-copypaste).
21
22### You can try live [documentation](https://jsdaddy.github.io/ngx-mask/) with examples
23
24
25## Installing
26Angular version 17.x.x
27```bash
28$ npm install --save ngx-mask
29```
30Angular version 16.x.x
31```bash
32$ npm install --save ngx-mask@16.4.2
33```
34Angular version 15.x.x
35```bash
36$ npm install --save ngx-mask@15.2.3
37```
38Angular version 14.x.x
39```bash
40$ npm install --save ngx-mask@14.3.3
41```
42Angular version 13.x.x or 12.x.x
43```bash
44$ npm install --save ngx-mask@13.2.2
45```
46
47## Quickstart if ngx-mask version >= 15.0.0
48
49Import **ngx-mask** directive, pipe and provide NgxMask providers with `provideNgxMask` function.
50
51### With default config options application level
52
53```typescript
54bootstrapApplication(AppComponent, {
55 providers: [
56 (...)
57 provideEnvironmentNgxMask(),
58 (...)
59 ],
60}).catch((err) => console.error(err));
61```
62
63### Passing your own mask config options
64
65```typescript
66import { IConfig } from 'ngx-mask'
67
68const maskConfig: Partial<IConfig> = {
69 validation: false,
70};
71
72bootstrapApplication(AppComponent, {
73 providers: [
74 (...)
75 provideEnvironmentNgxMask(maskConfig),
76 (...)
77 ],
78}).catch((err) => console.error(err));
79```
80
81### Using a function to configure:
82
83```typescript
84const maskConfigFunction: () => Partial<IConfig> = () => {
85 return {
86 validation: false,
87 };
88};
89
90bootstrapApplication(AppComponent, {
91 providers: [
92 (...)
93 provideEnvironmentNgxMask(maskConfigFunction),
94 (...)
95],
96}).catch((err) => console.error(err));
97```
98
99### With config options feature level
100
101```typescript
102@Component({
103 selector: 'my-feature',
104 templateUrl: './my-feature.component.html',
105 styleUrls: ['./my-feature.component.css'],
106 standalone: true,
107 imports: [NgxMaskDirective, (...)],
108 providers: [
109 (...)
110 provideNgxMask(),
111 (...)
112 ],
113})
114export class MyFeatureComponent {}
115```
116
117Then, import directive, pipe to needed standalone component and just define masks in inputs.
118
119### With Angular modules
120
121```typescript
122@NgModule({
123 imports: [
124 NgxMaskDirective, NgxMaskPipe
125 ],
126 providers: [provideNgxMask()]
127})
128```
129
130## Quickstart if ngx-mask version < 15.0.0
131
132For version ngx-mask < 15.0.0
133Import **ngx-mask** module in Angular app.
134
135### With default mask config options
136
137```typescript
138import { NgxMaskModule, IConfig } from 'ngx-mask'
139
140export const options: Partial<null|IConfig> | (() => Partial<IConfig>) = null;
141
142@NgModule({
143 imports: [
144 NgxMaskModule.forRoot(),
145 ],
146})
147```
148
149### Passing in your own mask config options
150
151```typescript
152import { NgxMaskModule, IConfig } from 'ngx-mask'
153
154const maskConfig: Partial<IConfig> = {
155 validation: false,
156};
157
158@NgModule({
159 imports: [
160 NgxMaskModule.forRoot(maskConfig),
161 ],
162})
163```
164
165Or using a function to get the config:
166
167```typescript
168const maskConfigFunction: () => Partial<IConfig> = () => {
169 return {
170 validation: false,
171 };
172};
173
174@NgModule({
175 imports: [
176 NgxMaskModule.forRoot(maskConfigFunction),
177 ],
178})
179```
180
181Then, just define masks in inputs.
182
183## Usage
184
185Text [documentation](https://github.com/JsDaddy/ngx-mask/blob/develop/USAGE.md)
186
187## Setup hooks
188```bash
189$ npm run init:hooks
190```
191
192## Contributing
193We would love some contributions! Check out this [document](https://github.com/JsDaddy/ngx-mask/blob/develop/CONTRIBUTING.md) to get started.