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 |
|
19 | You can also try our NGX LOADER INDICATOR [check](https://www.npmjs.com/package/ngx-loader-indicator).
|
20 | You 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
|
26 | Angular version 17.x.x
|
27 | ```bash
|
28 | $ npm install --save ngx-mask
|
29 | ```
|
30 | Angular version 16.x.x
|
31 | ```bash
|
32 | $ npm install --save ngx-mask@16.4.2
|
33 | ```
|
34 | Angular version 15.x.x
|
35 | ```bash
|
36 | $ npm install --save ngx-mask@15.2.3
|
37 | ```
|
38 | Angular version 14.x.x
|
39 | ```bash
|
40 | $ npm install --save ngx-mask@14.3.3
|
41 | ```
|
42 | Angular 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 |
|
49 | Import **ngx-mask** directive, pipe and provide NgxMask providers with `provideNgxMask` function.
|
50 |
|
51 | ### With default config options application level
|
52 |
|
53 | ```typescript
|
54 | bootstrapApplication(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
|
66 | import { IConfig } from 'ngx-mask'
|
67 |
|
68 | const maskConfig: Partial<IConfig> = {
|
69 | validation: false,
|
70 | };
|
71 |
|
72 | bootstrapApplication(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
|
84 | const maskConfigFunction: () => Partial<IConfig> = () => {
|
85 | return {
|
86 | validation: false,
|
87 | };
|
88 | };
|
89 |
|
90 | bootstrapApplication(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 | })
|
114 | export class MyFeatureComponent {}
|
115 | ```
|
116 |
|
117 | Then, 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 |
|
132 | For version ngx-mask < 15.0.0
|
133 | Import **ngx-mask** module in Angular app.
|
134 |
|
135 | ### With default mask config options
|
136 |
|
137 | ```typescript
|
138 | import { NgxMaskModule, IConfig } from 'ngx-mask'
|
139 |
|
140 | export 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
|
152 | import { NgxMaskModule, IConfig } from 'ngx-mask'
|
153 |
|
154 | const maskConfig: Partial<IConfig> = {
|
155 | validation: false,
|
156 | };
|
157 |
|
158 | @NgModule({
|
159 | imports: [
|
160 | NgxMaskModule.forRoot(maskConfig),
|
161 | ],
|
162 | })
|
163 | ```
|
164 |
|
165 | Or using a function to get the config:
|
166 |
|
167 | ```typescript
|
168 | const maskConfigFunction: () => Partial<IConfig> = () => {
|
169 | return {
|
170 | validation: false,
|
171 | };
|
172 | };
|
173 |
|
174 | @NgModule({
|
175 | imports: [
|
176 | NgxMaskModule.forRoot(maskConfigFunction),
|
177 | ],
|
178 | })
|
179 | ```
|
180 |
|
181 | Then, just define masks in inputs.
|
182 |
|
183 | ## Usage
|
184 |
|
185 | Text [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
|
193 | We would love some contributions! Check out this [document](https://github.com/JsDaddy/ngx-mask/blob/develop/CONTRIBUTING.md) to get started.
|