ngx-mask 14.2.3 → 14.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/lib/config.mjs +1 -1
- package/esm2020/lib/custom-keyboard-event.mjs +2 -1
- package/esm2020/lib/mask-applier.service.mjs +42 -31
- package/esm2020/lib/mask.directive.mjs +50 -31
- package/esm2020/lib/mask.pipe.mjs +4 -4
- package/esm2020/lib/mask.service.mjs +47 -25
- package/esm2020/lib/ngx-mask.module.mjs +5 -5
- package/fesm2015/ngx-mask.mjs +156 -97
- package/fesm2015/ngx-mask.mjs.map +1 -1
- package/fesm2020/ngx-mask.mjs +144 -91
- package/fesm2020/ngx-mask.mjs.map +1 -1
- package/lib/mask-applier.service.d.ts +1 -1
- package/lib/mask.directive.d.ts +5 -5
- package/lib/mask.service.d.ts +3 -3
- package/package.json +1 -1
package/fesm2020/ngx-mask.mjs
CHANGED
|
@@ -102,7 +102,7 @@ class MaskApplierService {
|
|
|
102
102
|
decimalChar = decimalChars;
|
|
103
103
|
}
|
|
104
104
|
const decimals = x.length > 1 ? `${decimalChar}${x[1]}` : '';
|
|
105
|
-
let res = x[0];
|
|
105
|
+
let res = x[0] ?? '';
|
|
106
106
|
const separatorLimit = this.separatorLimit.replace(/\s/g, '');
|
|
107
107
|
if (separatorLimit && +separatorLimit) {
|
|
108
108
|
if (res[0] === '-') {
|
|
@@ -122,7 +122,7 @@ class MaskApplierService {
|
|
|
122
122
|
else if (precision === 0) {
|
|
123
123
|
return res;
|
|
124
124
|
}
|
|
125
|
-
return res + decimals.
|
|
125
|
+
return res + decimals.substring(0, precision + 1);
|
|
126
126
|
};
|
|
127
127
|
this.percentage = (str) => {
|
|
128
128
|
return Number(str) >= 0 && Number(str) <= 100;
|
|
@@ -136,9 +136,11 @@ class MaskApplierService {
|
|
|
136
136
|
};
|
|
137
137
|
this.checkAndRemoveSuffix = (inputValue) => {
|
|
138
138
|
for (let i = this.suffix?.length - 1; i >= 0; i--) {
|
|
139
|
-
const substr = this.suffix.
|
|
139
|
+
const substr = this.suffix.substring(i, this.suffix?.length);
|
|
140
140
|
if (inputValue.includes(substr) &&
|
|
141
|
-
|
|
141
|
+
i !== this.suffix?.length - 1 &&
|
|
142
|
+
(i - 1 < 0 ||
|
|
143
|
+
!inputValue.includes(this.suffix.substring(i - 1, this.suffix?.length)))) {
|
|
142
144
|
return inputValue.replace(substr, '');
|
|
143
145
|
}
|
|
144
146
|
}
|
|
@@ -153,9 +155,10 @@ class MaskApplierService {
|
|
|
153
155
|
decimalMarker = marker ? marker : decimalMarker[0];
|
|
154
156
|
}
|
|
155
157
|
const precisionRegEx = new RegExp(this._charToRegExpExpression(decimalMarker) + `\\d{${precision}}.*$`);
|
|
156
|
-
const precisionMatch = inputValue.match(precisionRegEx);
|
|
157
|
-
|
|
158
|
-
|
|
158
|
+
const precisionMatch = inputValue.match(precisionRegEx) ?? [];
|
|
159
|
+
const precisionMatchLength = precisionMatch[0]?.length ?? 0;
|
|
160
|
+
if (precisionMatchLength - 1 > precision) {
|
|
161
|
+
const diff = precisionMatchLength - 1 - precision;
|
|
159
162
|
// eslint-disable-next-line no-param-reassign
|
|
160
163
|
inputValue = inputValue.substring(0, inputValue.length - diff);
|
|
161
164
|
}
|
|
@@ -189,7 +192,9 @@ class MaskApplierService {
|
|
|
189
192
|
this.customPattern = customPattern;
|
|
190
193
|
return this.applyMask(inputValue, mask);
|
|
191
194
|
}
|
|
192
|
-
applyMask(inputValue, maskExpression, position = 0, justPasted = false, backspaced = false,
|
|
195
|
+
applyMask(inputValue, maskExpression, position = 0, justPasted = false, backspaced = false,
|
|
196
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
|
|
197
|
+
cb = () => { }) {
|
|
193
198
|
if (!maskExpression || typeof inputValue !== 'string') {
|
|
194
199
|
return '';
|
|
195
200
|
}
|
|
@@ -217,7 +222,7 @@ class MaskApplierService {
|
|
|
217
222
|
const arr = [];
|
|
218
223
|
for (let i = 0; i < inputValue.length; i++) {
|
|
219
224
|
if (inputValue[i]?.match('\\d')) {
|
|
220
|
-
arr.push(inputValue[i]);
|
|
225
|
+
arr.push(inputValue[i] ?? '');
|
|
221
226
|
}
|
|
222
227
|
}
|
|
223
228
|
if (maskExpression === 'CPF_CNPJ') {
|
|
@@ -233,6 +238,7 @@ class MaskApplierService {
|
|
|
233
238
|
}
|
|
234
239
|
if (maskExpression.startsWith('percent')) {
|
|
235
240
|
if (inputValue.match('[a-z]|[A-Z]') ||
|
|
241
|
+
// eslint-disable-next-line no-useless-escape
|
|
236
242
|
inputValue.match(/[-!$%^&*()_+|~=`{}\[\]:";'<>?,\/.]/)) {
|
|
237
243
|
// eslint-disable-next-line no-param-reassign
|
|
238
244
|
inputValue = this._stripToDecimal(inputValue);
|
|
@@ -257,7 +263,7 @@ class MaskApplierService {
|
|
|
257
263
|
if (inputValue.match('[wа-яА-Я]') ||
|
|
258
264
|
inputValue.match('[ЁёА-я]') ||
|
|
259
265
|
inputValue.match('[a-z]|[A-Z]') ||
|
|
260
|
-
inputValue.match(/[-@#!$%\\^&*()_£¬'+|~=`{}\
|
|
266
|
+
inputValue.match(/[-@#!$%\\^&*()_£¬'+|~=`{}\]:";<>.?/]/) ||
|
|
261
267
|
inputValue.match('[^A-Za-z0-9,]')) {
|
|
262
268
|
// eslint-disable-next-line no-param-reassign
|
|
263
269
|
inputValue = this._stripToDecimal(inputValue);
|
|
@@ -312,7 +318,9 @@ class MaskApplierService {
|
|
|
312
318
|
_shift++;
|
|
313
319
|
} while (_shift < shiftStep);
|
|
314
320
|
}
|
|
315
|
-
else if ((commaShift !== 0 &&
|
|
321
|
+
else if ((commaShift !== 0 &&
|
|
322
|
+
position > 0 &&
|
|
323
|
+
!(result.indexOf(',') >= position && position > 3)) ||
|
|
316
324
|
(!(result.indexOf('.') >= position && position > 3) && shiftStep <= 0)) {
|
|
317
325
|
this._shift.clear();
|
|
318
326
|
backspaceShift = true;
|
|
@@ -328,33 +336,33 @@ class MaskApplierService {
|
|
|
328
336
|
else {
|
|
329
337
|
for (
|
|
330
338
|
// eslint-disable-next-line
|
|
331
|
-
let i = 0, inputSymbol = inputArray[0]; i < inputArray.length; i++, inputSymbol = inputArray[i]) {
|
|
339
|
+
let i = 0, inputSymbol = inputArray[0]; i < inputArray.length; i++, inputSymbol = inputArray[i] ?? '') {
|
|
332
340
|
if (cursor === maskExpression.length) {
|
|
333
341
|
break;
|
|
334
342
|
}
|
|
335
|
-
if (this._checkSymbolMask(inputSymbol, maskExpression[cursor]) &&
|
|
343
|
+
if (this._checkSymbolMask(inputSymbol, maskExpression[cursor] ?? '') &&
|
|
336
344
|
maskExpression[cursor + 1] === '?') {
|
|
337
345
|
result += inputSymbol;
|
|
338
346
|
cursor += 2;
|
|
339
347
|
}
|
|
340
348
|
else if (maskExpression[cursor + 1] === '*' &&
|
|
341
349
|
multi &&
|
|
342
|
-
this._checkSymbolMask(inputSymbol, maskExpression[cursor + 2])) {
|
|
350
|
+
this._checkSymbolMask(inputSymbol, maskExpression[cursor + 2] ?? '')) {
|
|
343
351
|
result += inputSymbol;
|
|
344
352
|
cursor += 3;
|
|
345
353
|
multi = false;
|
|
346
354
|
}
|
|
347
|
-
else if (this._checkSymbolMask(inputSymbol, maskExpression[cursor]) &&
|
|
355
|
+
else if (this._checkSymbolMask(inputSymbol, maskExpression[cursor] ?? '') &&
|
|
348
356
|
maskExpression[cursor + 1] === '*') {
|
|
349
357
|
result += inputSymbol;
|
|
350
358
|
multi = true;
|
|
351
359
|
}
|
|
352
360
|
else if (maskExpression[cursor + 1] === '?' &&
|
|
353
|
-
this._checkSymbolMask(inputSymbol, maskExpression[cursor + 2])) {
|
|
361
|
+
this._checkSymbolMask(inputSymbol, maskExpression[cursor + 2] ?? '')) {
|
|
354
362
|
result += inputSymbol;
|
|
355
363
|
cursor += 3;
|
|
356
364
|
}
|
|
357
|
-
else if (this._checkSymbolMask(inputSymbol, maskExpression[cursor])) {
|
|
365
|
+
else if (this._checkSymbolMask(inputSymbol, maskExpression[cursor] ?? '')) {
|
|
358
366
|
if (maskExpression[cursor] === 'H') {
|
|
359
367
|
if (Number(inputSymbol) > 2) {
|
|
360
368
|
cursor += 1;
|
|
@@ -464,15 +472,15 @@ class MaskApplierService {
|
|
|
464
472
|
result += inputSymbol;
|
|
465
473
|
cursor++;
|
|
466
474
|
}
|
|
467
|
-
else if (this.maskSpecialCharacters.indexOf(maskExpression[cursor]) !== -1) {
|
|
475
|
+
else if (this.maskSpecialCharacters.indexOf(maskExpression[cursor] ?? '') !== -1) {
|
|
468
476
|
result += maskExpression[cursor];
|
|
469
477
|
cursor++;
|
|
470
478
|
this._shiftStep(maskExpression, cursor, inputArray.length);
|
|
471
479
|
i--;
|
|
472
480
|
}
|
|
473
481
|
else if (this.maskSpecialCharacters.indexOf(inputSymbol) > -1 &&
|
|
474
|
-
this.maskAvailablePatterns[maskExpression[cursor]] &&
|
|
475
|
-
this.maskAvailablePatterns[maskExpression[cursor]]?.optional) {
|
|
482
|
+
this.maskAvailablePatterns[maskExpression[cursor] ?? ''] &&
|
|
483
|
+
this.maskAvailablePatterns[maskExpression[cursor] ?? '']?.optional) {
|
|
476
484
|
if (!!inputArray[cursor] &&
|
|
477
485
|
maskExpression !== '099.099.099.099' &&
|
|
478
486
|
maskExpression !== '000.000.000-00' &&
|
|
@@ -484,14 +492,14 @@ class MaskApplierService {
|
|
|
484
492
|
i--;
|
|
485
493
|
}
|
|
486
494
|
else if (this.maskExpression[cursor + 1] === '*' &&
|
|
487
|
-
this._findSpecialChar(this.maskExpression[cursor + 2]) &&
|
|
495
|
+
this._findSpecialChar(this.maskExpression[cursor + 2] ?? '') &&
|
|
488
496
|
this._findSpecialChar(inputSymbol) === this.maskExpression[cursor + 2] &&
|
|
489
497
|
multi) {
|
|
490
498
|
cursor += 3;
|
|
491
499
|
result += inputSymbol;
|
|
492
500
|
}
|
|
493
501
|
else if (this.maskExpression[cursor + 1] === '?' &&
|
|
494
|
-
this._findSpecialChar(this.maskExpression[cursor + 2]) &&
|
|
502
|
+
this._findSpecialChar(this.maskExpression[cursor + 2] ?? '') &&
|
|
495
503
|
this._findSpecialChar(inputSymbol) === this.maskExpression[cursor + 2] &&
|
|
496
504
|
multi) {
|
|
497
505
|
cursor += 3;
|
|
@@ -505,7 +513,8 @@ class MaskApplierService {
|
|
|
505
513
|
}
|
|
506
514
|
}
|
|
507
515
|
if (result.length + 1 === maskExpression.length &&
|
|
508
|
-
this.maskSpecialCharacters.indexOf(maskExpression[maskExpression.length - 1]
|
|
516
|
+
this.maskSpecialCharacters.indexOf(maskExpression[maskExpression.length - 1] ?? '') !==
|
|
517
|
+
-1) {
|
|
509
518
|
result += maskExpression[maskExpression.length - 1];
|
|
510
519
|
}
|
|
511
520
|
let newPosition = position + 1;
|
|
@@ -542,9 +551,9 @@ class MaskApplierService {
|
|
|
542
551
|
this.maskAvailablePatterns = this.customPattern
|
|
543
552
|
? this.customPattern
|
|
544
553
|
: this.maskAvailablePatterns;
|
|
545
|
-
return (this.maskAvailablePatterns[maskSymbol] &&
|
|
546
|
-
this.maskAvailablePatterns[maskSymbol].
|
|
547
|
-
|
|
554
|
+
return ((this.maskAvailablePatterns[maskSymbol]?.pattern &&
|
|
555
|
+
this.maskAvailablePatterns[maskSymbol]?.pattern.test(inputSymbol)) ??
|
|
556
|
+
false);
|
|
548
557
|
}
|
|
549
558
|
_stripToDecimal(str) {
|
|
550
559
|
return str
|
|
@@ -572,7 +581,9 @@ class MaskApplierService {
|
|
|
572
581
|
return char;
|
|
573
582
|
}
|
|
574
583
|
_shiftStep(maskExpression, cursor, inputLength) {
|
|
575
|
-
const shiftStep = /[*?]/g.test(maskExpression.slice(0, cursor))
|
|
584
|
+
const shiftStep = /[*?]/g.test(maskExpression.slice(0, cursor))
|
|
585
|
+
? inputLength
|
|
586
|
+
: cursor;
|
|
576
587
|
this._shift.add(shiftStep + this.prefix.length || 0);
|
|
577
588
|
}
|
|
578
589
|
_compareOrIncludes(value, comparedValue, excludedValue) {
|
|
@@ -590,9 +601,9 @@ class MaskApplierService {
|
|
|
590
601
|
}));
|
|
591
602
|
}
|
|
592
603
|
}
|
|
593
|
-
MaskApplierService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
594
|
-
MaskApplierService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.
|
|
595
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
604
|
+
MaskApplierService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskApplierService, deps: [{ token: config }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
605
|
+
MaskApplierService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskApplierService });
|
|
606
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskApplierService, decorators: [{
|
|
596
607
|
type: Injectable
|
|
597
608
|
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
598
609
|
type: Inject,
|
|
@@ -619,10 +630,13 @@ class MaskService extends MaskApplierService {
|
|
|
619
630
|
this.writingValue = false;
|
|
620
631
|
this.maskChanged = false;
|
|
621
632
|
this.triggerOnMaskChange = false;
|
|
633
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
|
|
622
634
|
this.onChange = (_) => { };
|
|
623
635
|
}
|
|
624
636
|
// eslint-disable-next-line complexity
|
|
625
|
-
applyMask(inputValue, maskExpression, position = 0, justPasted = false, backspaced = false,
|
|
637
|
+
applyMask(inputValue, maskExpression, position = 0, justPasted = false, backspaced = false,
|
|
638
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
|
|
639
|
+
cb = () => { }) {
|
|
626
640
|
if (!maskExpression) {
|
|
627
641
|
return inputValue !== this.actualValue ? this.actualValue : inputValue;
|
|
628
642
|
}
|
|
@@ -637,7 +651,9 @@ class MaskService extends MaskApplierService {
|
|
|
637
651
|
this.formControlResult(this.prefix);
|
|
638
652
|
return this.prefix + this.maskIsShown;
|
|
639
653
|
}
|
|
640
|
-
const getSymbol = !!inputValue && typeof this.selStart === 'number'
|
|
654
|
+
const getSymbol = !!inputValue && typeof this.selStart === 'number'
|
|
655
|
+
? inputValue[this.selStart] ?? ''
|
|
656
|
+
: '';
|
|
641
657
|
let newInputValue = '';
|
|
642
658
|
if (this.hiddenInput !== undefined && !this.writingValue) {
|
|
643
659
|
let actualResult = this.actualValue.split('');
|
|
@@ -678,12 +694,15 @@ class MaskService extends MaskApplierService {
|
|
|
678
694
|
}
|
|
679
695
|
// b) remove decimal marker from list of special characters to mask
|
|
680
696
|
if (this.maskExpression.startsWith('separator') && this.dropSpecialCharacters === true) {
|
|
681
|
-
this.maskSpecialCharacters = this.maskSpecialCharacters.filter((item) => !this._compareOrIncludes(item, this.decimalMarker, this.thousandSeparator)
|
|
697
|
+
this.maskSpecialCharacters = this.maskSpecialCharacters.filter((item) => !this._compareOrIncludes(item, this.decimalMarker, this.thousandSeparator) //item !== this.decimalMarker, // !
|
|
698
|
+
);
|
|
682
699
|
}
|
|
683
700
|
this.formControlResult(result);
|
|
684
701
|
if (!this.showMaskTyped) {
|
|
685
702
|
if (this.hiddenInput) {
|
|
686
|
-
return result && result.length
|
|
703
|
+
return result && result.length
|
|
704
|
+
? this.hideInput(result, this.maskExpression)
|
|
705
|
+
: result;
|
|
687
706
|
}
|
|
688
707
|
return result;
|
|
689
708
|
}
|
|
@@ -709,7 +728,9 @@ class MaskService extends MaskApplierService {
|
|
|
709
728
|
}
|
|
710
729
|
return countSkipedSymbol;
|
|
711
730
|
}
|
|
712
|
-
applyValueChanges(position, justPasted, backspaced,
|
|
731
|
+
applyValueChanges(position, justPasted, backspaced,
|
|
732
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
|
|
733
|
+
cb = () => { }) {
|
|
713
734
|
const formElement = this._elementRef.nativeElement;
|
|
714
735
|
formElement.value = this.applyMask(formElement.value, this.maskExpression, position, justPasted, backspaced, cb);
|
|
715
736
|
if (formElement === this._getActiveElement()) {
|
|
@@ -722,9 +743,9 @@ class MaskService extends MaskApplierService {
|
|
|
722
743
|
.split('')
|
|
723
744
|
.map((curr, index) => {
|
|
724
745
|
if (this.maskAvailablePatterns &&
|
|
725
|
-
this.maskAvailablePatterns[maskExpression[index]] &&
|
|
726
|
-
this.maskAvailablePatterns[maskExpression[index]]?.symbol) {
|
|
727
|
-
return this.maskAvailablePatterns[maskExpression[index]]?.symbol;
|
|
746
|
+
this.maskAvailablePatterns[maskExpression[index] ?? ''] &&
|
|
747
|
+
this.maskAvailablePatterns[maskExpression[index] ?? '']?.symbol) {
|
|
748
|
+
return this.maskAvailablePatterns[maskExpression[index] ?? '']?.symbol;
|
|
728
749
|
}
|
|
729
750
|
return curr;
|
|
730
751
|
})
|
|
@@ -732,11 +753,11 @@ class MaskService extends MaskApplierService {
|
|
|
732
753
|
}
|
|
733
754
|
// this function is not necessary, it checks result against maskExpression
|
|
734
755
|
getActualValue(res) {
|
|
735
|
-
const compare = res
|
|
736
|
-
.
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
756
|
+
const compare = res.split('').filter((symbol, i) => {
|
|
757
|
+
const maskChar = this.maskExpression[i] ?? '';
|
|
758
|
+
return (this._checkSymbolMask(symbol, maskChar) ||
|
|
759
|
+
(this.maskSpecialCharacters.includes(maskChar) && symbol === maskChar));
|
|
760
|
+
});
|
|
740
761
|
if (compare.join('') === res) {
|
|
741
762
|
return compare.join('');
|
|
742
763
|
}
|
|
@@ -746,7 +767,7 @@ class MaskService extends MaskApplierService {
|
|
|
746
767
|
let symbolToReplace = '';
|
|
747
768
|
const newInputValue = (inputValue &&
|
|
748
769
|
inputValue.split('').map((currSymbol, index) => {
|
|
749
|
-
if (this.maskSpecialCharacters.includes(inputValue[index + 1]) &&
|
|
770
|
+
if (this.maskSpecialCharacters.includes(inputValue[index + 1] ?? '') &&
|
|
750
771
|
inputValue[index + 1] !== this.maskExpression[index + 1]) {
|
|
751
772
|
symbolToReplace = currSymbol;
|
|
752
773
|
return inputValue[index + 1];
|
|
@@ -810,7 +831,9 @@ class MaskService extends MaskApplierService {
|
|
|
810
831
|
Promise.resolve().then(() => this._renderer.setProperty(this._elementRef.nativeElement, name, value));
|
|
811
832
|
}
|
|
812
833
|
checkSpecialCharAmount(mask) {
|
|
813
|
-
const chars = mask
|
|
834
|
+
const chars = mask
|
|
835
|
+
.split('')
|
|
836
|
+
.filter((item) => this._findSpecialChar(item));
|
|
814
837
|
return chars.length;
|
|
815
838
|
}
|
|
816
839
|
removeMask(inputValue) {
|
|
@@ -822,8 +845,12 @@ class MaskService extends MaskApplierService {
|
|
|
822
845
|
}
|
|
823
846
|
const arr = [];
|
|
824
847
|
for (let i = 0; i < inputVal.length; i++) {
|
|
825
|
-
|
|
826
|
-
|
|
848
|
+
const value = inputVal[i] ?? '';
|
|
849
|
+
if (!value) {
|
|
850
|
+
continue;
|
|
851
|
+
}
|
|
852
|
+
if (value.match('\\d')) {
|
|
853
|
+
arr.push(value);
|
|
827
854
|
}
|
|
828
855
|
}
|
|
829
856
|
if (arr.length <= 3) {
|
|
@@ -855,8 +882,12 @@ class MaskService extends MaskApplierService {
|
|
|
855
882
|
}
|
|
856
883
|
const arr = [];
|
|
857
884
|
for (let i = 0; i < inputVal.length; i++) {
|
|
858
|
-
|
|
859
|
-
|
|
885
|
+
const value = inputVal[i] ?? '';
|
|
886
|
+
if (!value) {
|
|
887
|
+
continue;
|
|
888
|
+
}
|
|
889
|
+
if (value.match('\\d')) {
|
|
890
|
+
arr.push(value);
|
|
860
891
|
}
|
|
861
892
|
}
|
|
862
893
|
if (arr.length <= 3) {
|
|
@@ -948,7 +979,9 @@ class MaskService extends MaskApplierService {
|
|
|
948
979
|
return new RegExp(specialCharactersForRemove.map((item) => `\\${item}`).join('|'), 'gi');
|
|
949
980
|
}
|
|
950
981
|
_replaceDecimalMarkerToDot(value) {
|
|
951
|
-
const markers = Array.isArray(this.decimalMarker)
|
|
982
|
+
const markers = Array.isArray(this.decimalMarker)
|
|
983
|
+
? this.decimalMarker
|
|
984
|
+
: [this.decimalMarker];
|
|
952
985
|
return value.replace(this._regExpForRemove(markers), '.');
|
|
953
986
|
}
|
|
954
987
|
_checkSymbols(result) {
|
|
@@ -982,11 +1015,11 @@ class MaskService extends MaskApplierService {
|
|
|
982
1015
|
return Number(separatorValue);
|
|
983
1016
|
}
|
|
984
1017
|
}
|
|
985
|
-
MaskService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
986
|
-
MaskService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.
|
|
987
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
1018
|
+
MaskService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskService, deps: [{ token: DOCUMENT }, { token: config }, { token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1019
|
+
MaskService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskService });
|
|
1020
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskService, decorators: [{
|
|
988
1021
|
type: Injectable
|
|
989
|
-
}], ctorParameters: function () { return [{ type:
|
|
1022
|
+
}], ctorParameters: function () { return [{ type: Document, decorators: [{
|
|
990
1023
|
type: Inject,
|
|
991
1024
|
args: [DOCUMENT]
|
|
992
1025
|
}] }, { type: undefined, decorators: [{
|
|
@@ -1024,7 +1057,9 @@ class MaskDirective {
|
|
|
1024
1057
|
this._position = null;
|
|
1025
1058
|
this._maskExpressionArray = [];
|
|
1026
1059
|
this._justPasted = false;
|
|
1060
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
|
|
1027
1061
|
this.onChange = (_) => { };
|
|
1062
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
1028
1063
|
this.onTouch = () => { };
|
|
1029
1064
|
}
|
|
1030
1065
|
ngOnChanges(changes) {
|
|
@@ -1102,7 +1137,8 @@ class MaskDirective {
|
|
|
1102
1137
|
if (allowNegativeNumbers) {
|
|
1103
1138
|
this._maskService.allowNegativeNumbers = allowNegativeNumbers.currentValue;
|
|
1104
1139
|
if (this._maskService.allowNegativeNumbers) {
|
|
1105
|
-
this._maskService.maskSpecialCharacters =
|
|
1140
|
+
this._maskService.maskSpecialCharacters =
|
|
1141
|
+
this._maskService.maskSpecialCharacters.filter((c) => c !== '-');
|
|
1106
1142
|
}
|
|
1107
1143
|
}
|
|
1108
1144
|
if (leadZeroDateTime) {
|
|
@@ -1139,7 +1175,7 @@ class MaskDirective {
|
|
|
1139
1175
|
if (value && value.toString().length >= 1) {
|
|
1140
1176
|
let counterOfOpt = 0;
|
|
1141
1177
|
for (const key in this._maskService.maskAvailablePatterns) {
|
|
1142
|
-
if (this._maskService.maskAvailablePatterns[key]
|
|
1178
|
+
if (this._maskService.maskAvailablePatterns[key]?.optional) {
|
|
1143
1179
|
if (this._maskValue.indexOf(key) !== this._maskValue.lastIndexOf(key)) {
|
|
1144
1180
|
const opt = this._maskValue
|
|
1145
1181
|
.split('')
|
|
@@ -1161,7 +1197,9 @@ class MaskDirective {
|
|
|
1161
1197
|
}
|
|
1162
1198
|
if (this._maskValue.indexOf('{') === 1 &&
|
|
1163
1199
|
value.toString().length ===
|
|
1164
|
-
this._maskValue.length +
|
|
1200
|
+
this._maskValue.length +
|
|
1201
|
+
Number((this._maskValue.split('{')[1] ?? '').split('}')[0]) -
|
|
1202
|
+
4) {
|
|
1165
1203
|
return null;
|
|
1166
1204
|
}
|
|
1167
1205
|
if (this._maskValue.indexOf('*') === 1 || this._maskValue.indexOf('?') === 1) {
|
|
@@ -1196,7 +1234,8 @@ class MaskDirective {
|
|
|
1196
1234
|
}
|
|
1197
1235
|
onModelChange(value) {
|
|
1198
1236
|
// on form reset we need to update the actualValue
|
|
1199
|
-
if ((value === '' || value === null || value === undefined) &&
|
|
1237
|
+
if ((value === '' || value === null || value === undefined) &&
|
|
1238
|
+
this._maskService.actualValue) {
|
|
1200
1239
|
this._maskService.actualValue = this._maskService.getActualValue('');
|
|
1201
1240
|
}
|
|
1202
1241
|
}
|
|
@@ -1222,7 +1261,8 @@ class MaskDirective {
|
|
|
1222
1261
|
if (this._getActiveElement() !== el) {
|
|
1223
1262
|
return;
|
|
1224
1263
|
}
|
|
1225
|
-
this._position =
|
|
1264
|
+
this._position =
|
|
1265
|
+
this._position === 1 && this._inputValue.length === 1 ? null : this._position;
|
|
1226
1266
|
let positionToApply = this._position
|
|
1227
1267
|
? this._inputValue.length + position + caretShift
|
|
1228
1268
|
: position + (this._code === 'Backspace' && !backspaceShift ? 0 : caretShift);
|
|
@@ -1272,21 +1312,23 @@ class MaskDirective {
|
|
|
1272
1312
|
}
|
|
1273
1313
|
}
|
|
1274
1314
|
}
|
|
1275
|
-
const nextValue =
|
|
1276
|
-
|
|
1277
|
-
|
|
1315
|
+
const nextValue = el &&
|
|
1316
|
+
(!el.value || el.value === this._maskService.prefix
|
|
1317
|
+
? this._maskService.prefix + this._maskService.maskIsShown
|
|
1318
|
+
: el.value);
|
|
1278
1319
|
/** Fix of cursor position jumping to end in most browsers no matter where cursor is inserted onFocus */
|
|
1279
|
-
if (el.value !== nextValue) {
|
|
1320
|
+
if (el && el.value !== nextValue) {
|
|
1280
1321
|
el.value = nextValue;
|
|
1281
1322
|
}
|
|
1282
1323
|
/** fix of cursor position with prefix when mouse click occur */
|
|
1283
|
-
if (
|
|
1284
|
-
|
|
1324
|
+
if (el &&
|
|
1325
|
+
(el.selectionStart || el.selectionEnd) <=
|
|
1326
|
+
this._maskService.prefix.length) {
|
|
1285
1327
|
el.selectionStart = this._maskService.prefix.length;
|
|
1286
1328
|
return;
|
|
1287
1329
|
}
|
|
1288
1330
|
/** select only inserted text */
|
|
1289
|
-
if (el.selectionEnd > this._getActualInputLength()) {
|
|
1331
|
+
if (el && el.selectionEnd > this._getActualInputLength()) {
|
|
1290
1332
|
el.selectionEnd = this._getActualInputLength();
|
|
1291
1333
|
}
|
|
1292
1334
|
}
|
|
@@ -1317,8 +1359,9 @@ class MaskDirective {
|
|
|
1317
1359
|
else {
|
|
1318
1360
|
if (this._inputValue.length !== el.selectionStart &&
|
|
1319
1361
|
el.selectionStart !== 1) {
|
|
1320
|
-
while (this.specialCharacters.includes(this._inputValue[el.selectionStart - 1].toString()) &&
|
|
1321
|
-
((this.prefix.length >= 1 &&
|
|
1362
|
+
while (this.specialCharacters.includes((this._inputValue[el.selectionStart - 1] ?? '').toString()) &&
|
|
1363
|
+
((this.prefix.length >= 1 &&
|
|
1364
|
+
el.selectionStart > this.prefix.length) ||
|
|
1322
1365
|
this.prefix.length === 0)) {
|
|
1323
1366
|
el.setSelectionRange(el.selectionStart - 1, el.selectionEnd);
|
|
1324
1367
|
}
|
|
@@ -1370,7 +1413,9 @@ class MaskDirective {
|
|
|
1370
1413
|
if (!Array.isArray(this.decimalMarker)) {
|
|
1371
1414
|
// eslint-disable-next-line no-param-reassign
|
|
1372
1415
|
inputValue =
|
|
1373
|
-
this.decimalMarker !== '.'
|
|
1416
|
+
this.decimalMarker !== '.'
|
|
1417
|
+
? inputValue.replace('.', this.decimalMarker)
|
|
1418
|
+
: inputValue;
|
|
1374
1419
|
}
|
|
1375
1420
|
this._maskService.isNumberValue = true;
|
|
1376
1421
|
}
|
|
@@ -1383,7 +1428,7 @@ class MaskDirective {
|
|
|
1383
1428
|
if ((inputValue && this._maskService.maskExpression) ||
|
|
1384
1429
|
(this._maskService.maskExpression &&
|
|
1385
1430
|
(this._maskService.prefix || this._maskService.showMaskTyped))) {
|
|
1386
|
-
// Let the service we know we are writing value so that triggering onChange function
|
|
1431
|
+
// Let the service we know we are writing value so that triggering onChange function won't happen during applyMask
|
|
1387
1432
|
this._maskService.writingValue = true;
|
|
1388
1433
|
this._maskService.formElementProperty = [
|
|
1389
1434
|
'value',
|
|
@@ -1422,10 +1467,14 @@ class MaskDirective {
|
|
|
1422
1467
|
}
|
|
1423
1468
|
_repeatPatternSymbols(maskExp) {
|
|
1424
1469
|
return ((maskExp.match(/{[0-9]+}/) &&
|
|
1425
|
-
maskExp
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1470
|
+
maskExp
|
|
1471
|
+
.split('')
|
|
1472
|
+
.reduce((accum, currVal, index) => {
|
|
1473
|
+
this._start = currVal === '{' ? index : this._start;
|
|
1474
|
+
if (currVal !== '}') {
|
|
1475
|
+
return this._maskService._findSpecialChar(currVal)
|
|
1476
|
+
? accum + currVal
|
|
1477
|
+
: accum;
|
|
1429
1478
|
}
|
|
1430
1479
|
this._end = index;
|
|
1431
1480
|
const repeatNumber = Number(maskExp.slice(this._start + 1, this._end));
|
|
@@ -1443,11 +1492,13 @@ class MaskDirective {
|
|
|
1443
1492
|
];
|
|
1444
1493
|
}
|
|
1445
1494
|
_validateTime(value) {
|
|
1446
|
-
const rowMaskLen = this._maskValue
|
|
1495
|
+
const rowMaskLen = this._maskValue
|
|
1496
|
+
.split('')
|
|
1497
|
+
.filter((s) => s !== ':').length;
|
|
1447
1498
|
if (!value) {
|
|
1448
1499
|
return null; // Don't validate empty values to allow for optional form control
|
|
1449
1500
|
}
|
|
1450
|
-
if ((+value[value.length - 1] === 0 && value.length < rowMaskLen) ||
|
|
1501
|
+
if ((+(value[value.length - 1] ?? -1) === 0 && value.length < rowMaskLen) ||
|
|
1451
1502
|
value.length <= rowMaskLen - 2) {
|
|
1452
1503
|
return this._createValidationError(value);
|
|
1453
1504
|
}
|
|
@@ -1477,17 +1528,18 @@ class MaskDirective {
|
|
|
1477
1528
|
return test;
|
|
1478
1529
|
}
|
|
1479
1530
|
else {
|
|
1480
|
-
|
|
1481
|
-
this.
|
|
1482
|
-
|
|
1483
|
-
|
|
1531
|
+
const expression = this._maskExpressionArray[this._maskExpressionArray.length - 1] ?? '';
|
|
1532
|
+
this._maskValue =
|
|
1533
|
+
this.maskExpression =
|
|
1534
|
+
this._maskService.maskExpression =
|
|
1535
|
+
expression;
|
|
1484
1536
|
}
|
|
1485
1537
|
});
|
|
1486
1538
|
}
|
|
1487
1539
|
}
|
|
1488
1540
|
}
|
|
1489
|
-
MaskDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
1490
|
-
MaskDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.
|
|
1541
|
+
MaskDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskDirective, deps: [{ token: DOCUMENT }, { token: MaskService }, { token: config }], target: i0.ɵɵFactoryTarget.Directive });
|
|
1542
|
+
MaskDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.8", type: MaskDirective, selector: "input[mask], textarea[mask]", inputs: { maskExpression: ["mask", "maskExpression"], specialCharacters: "specialCharacters", patterns: "patterns", prefix: "prefix", suffix: "suffix", thousandSeparator: "thousandSeparator", decimalMarker: "decimalMarker", dropSpecialCharacters: "dropSpecialCharacters", hiddenInput: "hiddenInput", showMaskTyped: "showMaskTyped", placeHolderCharacter: "placeHolderCharacter", shownMaskExpression: "shownMaskExpression", showTemplate: "showTemplate", clearIfNotMatch: "clearIfNotMatch", validation: "validation", separatorLimit: "separatorLimit", allowNegativeNumbers: "allowNegativeNumbers", leadZeroDateTime: "leadZeroDateTime", triggerOnMaskChange: "triggerOnMaskChange" }, outputs: { maskFilled: "maskFilled" }, host: { listeners: { "paste": "onPaste()", "ngModelChange": "onModelChange($event)", "input": "onInput($event)", "blur": "onBlur()", "click": "onClick($event)", "keydown": "onKeyDown($event)" } }, providers: [
|
|
1491
1543
|
{
|
|
1492
1544
|
provide: NG_VALUE_ACCESSOR,
|
|
1493
1545
|
useExisting: forwardRef(() => MaskDirective),
|
|
@@ -1500,7 +1552,7 @@ MaskDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version:
|
|
|
1500
1552
|
},
|
|
1501
1553
|
MaskService,
|
|
1502
1554
|
], exportAs: ["mask", "ngxMask"], usesOnChanges: true, ngImport: i0 });
|
|
1503
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
1555
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskDirective, decorators: [{
|
|
1504
1556
|
type: Directive,
|
|
1505
1557
|
args: [{
|
|
1506
1558
|
selector: 'input[mask], textarea[mask]',
|
|
@@ -1519,7 +1571,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.1", ngImpor
|
|
|
1519
1571
|
],
|
|
1520
1572
|
exportAs: 'mask,ngxMask',
|
|
1521
1573
|
}]
|
|
1522
|
-
}], ctorParameters: function () { return [{ type:
|
|
1574
|
+
}], ctorParameters: function () { return [{ type: Document, decorators: [{
|
|
1523
1575
|
type: Inject,
|
|
1524
1576
|
args: [DOCUMENT]
|
|
1525
1577
|
}] }, { type: MaskService }, { type: undefined, decorators: [{
|
|
@@ -1603,9 +1655,9 @@ class MaskPipe {
|
|
|
1603
1655
|
return this._maskService.applyMaskWithPattern(`${value}`, mask);
|
|
1604
1656
|
}
|
|
1605
1657
|
}
|
|
1606
|
-
MaskPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
1607
|
-
MaskPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.2.
|
|
1608
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
1658
|
+
MaskPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskPipe, deps: [{ token: MaskApplierService }], target: i0.ɵɵFactoryTarget.Pipe });
|
|
1659
|
+
MaskPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.2.8", ngImport: i0, type: MaskPipe, name: "mask" });
|
|
1660
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskPipe, decorators: [{
|
|
1609
1661
|
type: Pipe,
|
|
1610
1662
|
args: [{
|
|
1611
1663
|
name: 'mask',
|
|
@@ -1649,10 +1701,10 @@ class NgxMaskModule {
|
|
|
1649
1701
|
};
|
|
1650
1702
|
}
|
|
1651
1703
|
}
|
|
1652
|
-
NgxMaskModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.
|
|
1653
|
-
NgxMaskModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.
|
|
1654
|
-
NgxMaskModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.
|
|
1655
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.
|
|
1704
|
+
NgxMaskModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: NgxMaskModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1705
|
+
NgxMaskModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.8", ngImport: i0, type: NgxMaskModule, declarations: [MaskDirective, MaskPipe], exports: [MaskDirective, MaskPipe] });
|
|
1706
|
+
NgxMaskModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: NgxMaskModule });
|
|
1707
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: NgxMaskModule, decorators: [{
|
|
1656
1708
|
type: NgModule,
|
|
1657
1709
|
args: [{
|
|
1658
1710
|
exports: [MaskDirective, MaskPipe],
|
|
@@ -1671,6 +1723,7 @@ const commonjsGlobal = typeof globalThis !== 'undefined'
|
|
|
1671
1723
|
: {};
|
|
1672
1724
|
(function () {
|
|
1673
1725
|
if (!commonjsGlobal.KeyboardEvent) {
|
|
1726
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
1674
1727
|
commonjsGlobal.KeyboardEvent = function (_eventType, _init) { };
|
|
1675
1728
|
}
|
|
1676
1729
|
})();
|