ngx-mask 14.2.2 → 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.
@@ -91,7 +91,7 @@ class MaskApplierService {
91
91
  this.actualValue = '';
92
92
  this.shownMaskExpression = '';
93
93
  this._formatWithSeparators = (str, thousandSeparatorChar, decimalChars, precision) => {
94
- var _a, _b;
94
+ var _a, _b, _c;
95
95
  let x = [];
96
96
  let decimalChar = '';
97
97
  if (Array.isArray(decimalChars)) {
@@ -104,7 +104,7 @@ class MaskApplierService {
104
104
  decimalChar = decimalChars;
105
105
  }
106
106
  const decimals = x.length > 1 ? `${decimalChar}${x[1]}` : '';
107
- let res = x[0];
107
+ let res = (_c = x[0]) !== null && _c !== void 0 ? _c : '';
108
108
  const separatorLimit = this.separatorLimit.replace(/\s/g, '');
109
109
  if (separatorLimit && +separatorLimit) {
110
110
  if (res[0] === '-') {
@@ -124,7 +124,7 @@ class MaskApplierService {
124
124
  else if (precision === 0) {
125
125
  return res;
126
126
  }
127
- return res + decimals.substr(0, precision + 1);
127
+ return res + decimals.substring(0, precision + 1);
128
128
  };
129
129
  this.percentage = (str) => {
130
130
  return Number(str) >= 0 && Number(str) <= 100;
@@ -137,17 +137,20 @@ class MaskApplierService {
137
137
  return Infinity;
138
138
  };
139
139
  this.checkAndRemoveSuffix = (inputValue) => {
140
- var _a, _b, _c;
140
+ var _a, _b, _c, _d;
141
141
  for (let i = ((_a = this.suffix) === null || _a === void 0 ? void 0 : _a.length) - 1; i >= 0; i--) {
142
- const substr = this.suffix.substr(i, (_b = this.suffix) === null || _b === void 0 ? void 0 : _b.length);
142
+ const substr = this.suffix.substring(i, (_b = this.suffix) === null || _b === void 0 ? void 0 : _b.length);
143
143
  if (inputValue.includes(substr) &&
144
- (i - 1 < 0 || !inputValue.includes(this.suffix.substr(i - 1, (_c = this.suffix) === null || _c === void 0 ? void 0 : _c.length)))) {
144
+ i !== ((_c = this.suffix) === null || _c === void 0 ? void 0 : _c.length) - 1 &&
145
+ (i - 1 < 0 ||
146
+ !inputValue.includes(this.suffix.substring(i - 1, (_d = this.suffix) === null || _d === void 0 ? void 0 : _d.length)))) {
145
147
  return inputValue.replace(substr, '');
146
148
  }
147
149
  }
148
150
  return inputValue;
149
151
  };
150
152
  this.checkInputPrecision = (inputValue, precision, decimalMarker) => {
153
+ var _a, _b, _c;
151
154
  if (precision < Infinity) {
152
155
  // TODO need think about decimalMarker
153
156
  if (Array.isArray(decimalMarker)) {
@@ -156,9 +159,10 @@ class MaskApplierService {
156
159
  decimalMarker = marker ? marker : decimalMarker[0];
157
160
  }
158
161
  const precisionRegEx = new RegExp(this._charToRegExpExpression(decimalMarker) + `\\d{${precision}}.*$`);
159
- const precisionMatch = inputValue.match(precisionRegEx);
160
- if (precisionMatch && precisionMatch[0].length - 1 > precision) {
161
- const diff = precisionMatch[0].length - 1 - precision;
162
+ const precisionMatch = (_a = inputValue.match(precisionRegEx)) !== null && _a !== void 0 ? _a : [];
163
+ const precisionMatchLength = (_c = (_b = precisionMatch[0]) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
164
+ if (precisionMatchLength - 1 > precision) {
165
+ const diff = precisionMatchLength - 1 - precision;
162
166
  // eslint-disable-next-line no-param-reassign
163
167
  inputValue = inputValue.substring(0, inputValue.length - diff);
164
168
  }
@@ -192,8 +196,10 @@ class MaskApplierService {
192
196
  this.customPattern = customPattern;
193
197
  return this.applyMask(inputValue, mask);
194
198
  }
195
- applyMask(inputValue, maskExpression, position = 0, justPasted = false, backspaced = false, cb = () => { }) {
196
- var _a, _b;
199
+ applyMask(inputValue, maskExpression, position = 0, justPasted = false, backspaced = false,
200
+ // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
201
+ cb = () => { }) {
202
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
197
203
  if (!maskExpression || typeof inputValue !== 'string') {
198
204
  return '';
199
205
  }
@@ -221,7 +227,7 @@ class MaskApplierService {
221
227
  const arr = [];
222
228
  for (let i = 0; i < inputValue.length; i++) {
223
229
  if ((_a = inputValue[i]) === null || _a === void 0 ? void 0 : _a.match('\\d')) {
224
- arr.push(inputValue[i]);
230
+ arr.push((_b = inputValue[i]) !== null && _b !== void 0 ? _b : '');
225
231
  }
226
232
  }
227
233
  if (maskExpression === 'CPF_CNPJ') {
@@ -237,6 +243,7 @@ class MaskApplierService {
237
243
  }
238
244
  if (maskExpression.startsWith('percent')) {
239
245
  if (inputValue.match('[a-z]|[A-Z]') ||
246
+ // eslint-disable-next-line no-useless-escape
240
247
  inputValue.match(/[-!$%^&*()_+|~=`{}\[\]:";'<>?,\/.]/)) {
241
248
  // eslint-disable-next-line no-param-reassign
242
249
  inputValue = this._stripToDecimal(inputValue);
@@ -261,7 +268,7 @@ class MaskApplierService {
261
268
  if (inputValue.match('[wа-яА-Я]') ||
262
269
  inputValue.match('[ЁёА-я]') ||
263
270
  inputValue.match('[a-z]|[A-Z]') ||
264
- inputValue.match(/[-@#!$%\\^&*()_£¬'+|~=`{}\[\]:";<>.?\/]/) ||
271
+ inputValue.match(/[-@#!$%\\^&*()_£¬'+|~=`{}\]:";<>.?/]/) ||
265
272
  inputValue.match('[^A-Za-z0-9,]')) {
266
273
  // eslint-disable-next-line no-param-reassign
267
274
  inputValue = this._stripToDecimal(inputValue);
@@ -270,9 +277,10 @@ class MaskApplierService {
270
277
  inputValue =
271
278
  inputValue.length > 1 &&
272
279
  inputValue[0] === '0' &&
280
+ inputValue[1] !== this.thousandSeparator &&
273
281
  !this._compareOrIncludes(inputValue[1], this.decimalMarker, this.thousandSeparator) &&
274
282
  !backspaced
275
- ? inputValue.slice(1, inputValue.length)
283
+ ? inputValue.slice(0, inputValue.length - 1)
276
284
  : inputValue;
277
285
  if (backspaced) {
278
286
  // eslint-disable-next-line no-param-reassign
@@ -315,7 +323,9 @@ class MaskApplierService {
315
323
  _shift++;
316
324
  } while (_shift < shiftStep);
317
325
  }
318
- else if ((commaShift !== 0 && position > 0 && !(result.indexOf(',') >= position && position > 3)) ||
326
+ else if ((commaShift !== 0 &&
327
+ position > 0 &&
328
+ !(result.indexOf(',') >= position && position > 3)) ||
319
329
  (!(result.indexOf('.') >= position && position > 3) && shiftStep <= 0)) {
320
330
  this._shift.clear();
321
331
  backspaceShift = true;
@@ -331,33 +341,33 @@ class MaskApplierService {
331
341
  else {
332
342
  for (
333
343
  // eslint-disable-next-line
334
- let i = 0, inputSymbol = inputArray[0]; i < inputArray.length; i++, inputSymbol = inputArray[i]) {
344
+ let i = 0, inputSymbol = inputArray[0]; i < inputArray.length; i++, inputSymbol = (_c = inputArray[i]) !== null && _c !== void 0 ? _c : '') {
335
345
  if (cursor === maskExpression.length) {
336
346
  break;
337
347
  }
338
- if (this._checkSymbolMask(inputSymbol, maskExpression[cursor]) &&
348
+ if (this._checkSymbolMask(inputSymbol, (_d = maskExpression[cursor]) !== null && _d !== void 0 ? _d : '') &&
339
349
  maskExpression[cursor + 1] === '?') {
340
350
  result += inputSymbol;
341
351
  cursor += 2;
342
352
  }
343
353
  else if (maskExpression[cursor + 1] === '*' &&
344
354
  multi &&
345
- this._checkSymbolMask(inputSymbol, maskExpression[cursor + 2])) {
355
+ this._checkSymbolMask(inputSymbol, (_e = maskExpression[cursor + 2]) !== null && _e !== void 0 ? _e : '')) {
346
356
  result += inputSymbol;
347
357
  cursor += 3;
348
358
  multi = false;
349
359
  }
350
- else if (this._checkSymbolMask(inputSymbol, maskExpression[cursor]) &&
360
+ else if (this._checkSymbolMask(inputSymbol, (_f = maskExpression[cursor]) !== null && _f !== void 0 ? _f : '') &&
351
361
  maskExpression[cursor + 1] === '*') {
352
362
  result += inputSymbol;
353
363
  multi = true;
354
364
  }
355
365
  else if (maskExpression[cursor + 1] === '?' &&
356
- this._checkSymbolMask(inputSymbol, maskExpression[cursor + 2])) {
366
+ this._checkSymbolMask(inputSymbol, (_g = maskExpression[cursor + 2]) !== null && _g !== void 0 ? _g : '')) {
357
367
  result += inputSymbol;
358
368
  cursor += 3;
359
369
  }
360
- else if (this._checkSymbolMask(inputSymbol, maskExpression[cursor])) {
370
+ else if (this._checkSymbolMask(inputSymbol, (_h = maskExpression[cursor]) !== null && _h !== void 0 ? _h : '')) {
361
371
  if (maskExpression[cursor] === 'H') {
362
372
  if (Number(inputSymbol) > 2) {
363
373
  cursor += 1;
@@ -467,15 +477,15 @@ class MaskApplierService {
467
477
  result += inputSymbol;
468
478
  cursor++;
469
479
  }
470
- else if (this.maskSpecialCharacters.indexOf(maskExpression[cursor]) !== -1) {
480
+ else if (this.maskSpecialCharacters.indexOf((_j = maskExpression[cursor]) !== null && _j !== void 0 ? _j : '') !== -1) {
471
481
  result += maskExpression[cursor];
472
482
  cursor++;
473
483
  this._shiftStep(maskExpression, cursor, inputArray.length);
474
484
  i--;
475
485
  }
476
486
  else if (this.maskSpecialCharacters.indexOf(inputSymbol) > -1 &&
477
- this.maskAvailablePatterns[maskExpression[cursor]] &&
478
- ((_b = this.maskAvailablePatterns[maskExpression[cursor]]) === null || _b === void 0 ? void 0 : _b.optional)) {
487
+ this.maskAvailablePatterns[(_k = maskExpression[cursor]) !== null && _k !== void 0 ? _k : ''] &&
488
+ ((_m = this.maskAvailablePatterns[(_l = maskExpression[cursor]) !== null && _l !== void 0 ? _l : '']) === null || _m === void 0 ? void 0 : _m.optional)) {
479
489
  if (!!inputArray[cursor] &&
480
490
  maskExpression !== '099.099.099.099' &&
481
491
  maskExpression !== '000.000.000-00' &&
@@ -487,14 +497,14 @@ class MaskApplierService {
487
497
  i--;
488
498
  }
489
499
  else if (this.maskExpression[cursor + 1] === '*' &&
490
- this._findSpecialChar(this.maskExpression[cursor + 2]) &&
500
+ this._findSpecialChar((_o = this.maskExpression[cursor + 2]) !== null && _o !== void 0 ? _o : '') &&
491
501
  this._findSpecialChar(inputSymbol) === this.maskExpression[cursor + 2] &&
492
502
  multi) {
493
503
  cursor += 3;
494
504
  result += inputSymbol;
495
505
  }
496
506
  else if (this.maskExpression[cursor + 1] === '?' &&
497
- this._findSpecialChar(this.maskExpression[cursor + 2]) &&
507
+ this._findSpecialChar((_p = this.maskExpression[cursor + 2]) !== null && _p !== void 0 ? _p : '') &&
498
508
  this._findSpecialChar(inputSymbol) === this.maskExpression[cursor + 2] &&
499
509
  multi) {
500
510
  cursor += 3;
@@ -508,7 +518,8 @@ class MaskApplierService {
508
518
  }
509
519
  }
510
520
  if (result.length + 1 === maskExpression.length &&
511
- this.maskSpecialCharacters.indexOf(maskExpression[maskExpression.length - 1]) !== -1) {
521
+ this.maskSpecialCharacters.indexOf((_q = maskExpression[maskExpression.length - 1]) !== null && _q !== void 0 ? _q : '') !==
522
+ -1) {
512
523
  result += maskExpression[maskExpression.length - 1];
513
524
  }
514
525
  let newPosition = position + 1;
@@ -542,21 +553,24 @@ class MaskApplierService {
542
553
  return this.maskSpecialCharacters.find((val) => val === inputSymbol);
543
554
  }
544
555
  _checkSymbolMask(inputSymbol, maskSymbol) {
556
+ var _a, _b, _c;
545
557
  this.maskAvailablePatterns = this.customPattern
546
558
  ? this.customPattern
547
559
  : this.maskAvailablePatterns;
548
- return (this.maskAvailablePatterns[maskSymbol] &&
549
- this.maskAvailablePatterns[maskSymbol].pattern &&
550
- this.maskAvailablePatterns[maskSymbol].pattern.test(inputSymbol));
560
+ return ((_c = (((_a = this.maskAvailablePatterns[maskSymbol]) === null || _a === void 0 ? void 0 : _a.pattern) &&
561
+ ((_b = this.maskAvailablePatterns[maskSymbol]) === null || _b === void 0 ? void 0 : _b.pattern.test(inputSymbol)))) !== null && _c !== void 0 ? _c : false);
551
562
  }
552
563
  _stripToDecimal(str) {
553
564
  return str
554
565
  .split('')
555
566
  .filter((i, idx) => {
567
+ const isDecimalMarker = typeof this.decimalMarker === 'string'
568
+ ? i === this.decimalMarker
569
+ : // TODO (inepipenko) use utility type
570
+ this.decimalMarker.includes(i);
556
571
  return (i.match('^-?\\d') ||
557
- i.match('\\s') ||
558
- i === '.' ||
559
- i === ',' ||
572
+ i === this.thousandSeparator ||
573
+ isDecimalMarker ||
560
574
  (i === '-' && idx === 0 && this.allowNegativeNumbers));
561
575
  })
562
576
  .join('');
@@ -572,7 +586,9 @@ class MaskApplierService {
572
586
  return char;
573
587
  }
574
588
  _shiftStep(maskExpression, cursor, inputLength) {
575
- const shiftStep = /[*?]/g.test(maskExpression.slice(0, cursor)) ? inputLength : cursor;
589
+ const shiftStep = /[*?]/g.test(maskExpression.slice(0, cursor))
590
+ ? inputLength
591
+ : cursor;
576
592
  this._shift.add(shiftStep + this.prefix.length || 0);
577
593
  }
578
594
  _compareOrIncludes(value, comparedValue, excludedValue) {
@@ -590,9 +606,9 @@ class MaskApplierService {
590
606
  }));
591
607
  }
592
608
  }
593
- MaskApplierService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskApplierService, deps: [{ token: config }], target: i0.ɵɵFactoryTarget.Injectable });
594
- MaskApplierService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskApplierService });
595
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskApplierService, decorators: [{
609
+ MaskApplierService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskApplierService, deps: [{ token: config }], target: i0.ɵɵFactoryTarget.Injectable });
610
+ MaskApplierService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskApplierService });
611
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskApplierService, decorators: [{
596
612
  type: Injectable
597
613
  }], ctorParameters: function () {
598
614
  return [{ type: undefined, decorators: [{
@@ -621,10 +637,14 @@ class MaskService extends MaskApplierService {
621
637
  this.writingValue = false;
622
638
  this.maskChanged = false;
623
639
  this.triggerOnMaskChange = false;
640
+ // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
624
641
  this.onChange = (_) => { };
625
642
  }
626
643
  // eslint-disable-next-line complexity
627
- applyMask(inputValue, maskExpression, position = 0, justPasted = false, backspaced = false, cb = () => { }) {
644
+ applyMask(inputValue, maskExpression, position = 0, justPasted = false, backspaced = false,
645
+ // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
646
+ cb = () => { }) {
647
+ var _a;
628
648
  if (!maskExpression) {
629
649
  return inputValue !== this.actualValue ? this.actualValue : inputValue;
630
650
  }
@@ -639,7 +659,9 @@ class MaskService extends MaskApplierService {
639
659
  this.formControlResult(this.prefix);
640
660
  return this.prefix + this.maskIsShown;
641
661
  }
642
- const getSymbol = !!inputValue && typeof this.selStart === 'number' ? inputValue[this.selStart] : '';
662
+ const getSymbol = !!inputValue && typeof this.selStart === 'number'
663
+ ? (_a = inputValue[this.selStart]) !== null && _a !== void 0 ? _a : ''
664
+ : '';
643
665
  let newInputValue = '';
644
666
  if (this.hiddenInput !== undefined && !this.writingValue) {
645
667
  let actualResult = this.actualValue.split('');
@@ -680,12 +702,15 @@ class MaskService extends MaskApplierService {
680
702
  }
681
703
  // b) remove decimal marker from list of special characters to mask
682
704
  if (this.maskExpression.startsWith('separator') && this.dropSpecialCharacters === true) {
683
- this.maskSpecialCharacters = this.maskSpecialCharacters.filter((item) => !this._compareOrIncludes(item, this.decimalMarker, this.thousandSeparator));
705
+ this.maskSpecialCharacters = this.maskSpecialCharacters.filter((item) => !this._compareOrIncludes(item, this.decimalMarker, this.thousandSeparator) //item !== this.decimalMarker, // !
706
+ );
684
707
  }
685
708
  this.formControlResult(result);
686
709
  if (!this.showMaskTyped) {
687
710
  if (this.hiddenInput) {
688
- return result && result.length ? this.hideInput(result, this.maskExpression) : result;
711
+ return result && result.length
712
+ ? this.hideInput(result, this.maskExpression)
713
+ : result;
689
714
  }
690
715
  return result;
691
716
  }
@@ -711,7 +736,9 @@ class MaskService extends MaskApplierService {
711
736
  }
712
737
  return countSkipedSymbol;
713
738
  }
714
- applyValueChanges(position, justPasted, backspaced, cb = () => { }) {
739
+ applyValueChanges(position, justPasted, backspaced,
740
+ // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
741
+ cb = () => { }) {
715
742
  const formElement = this._elementRef.nativeElement;
716
743
  formElement.value = this.applyMask(formElement.value, this.maskExpression, position, justPasted, backspaced, cb);
717
744
  if (formElement === this._getActiveElement()) {
@@ -723,11 +750,11 @@ class MaskService extends MaskApplierService {
723
750
  return inputValue
724
751
  .split('')
725
752
  .map((curr, index) => {
726
- var _a, _b;
753
+ var _a, _b, _c, _d, _e;
727
754
  if (this.maskAvailablePatterns &&
728
- this.maskAvailablePatterns[maskExpression[index]] &&
729
- ((_a = this.maskAvailablePatterns[maskExpression[index]]) === null || _a === void 0 ? void 0 : _a.symbol)) {
730
- return (_b = this.maskAvailablePatterns[maskExpression[index]]) === null || _b === void 0 ? void 0 : _b.symbol;
755
+ this.maskAvailablePatterns[(_a = maskExpression[index]) !== null && _a !== void 0 ? _a : ''] &&
756
+ ((_c = this.maskAvailablePatterns[(_b = maskExpression[index]) !== null && _b !== void 0 ? _b : '']) === null || _c === void 0 ? void 0 : _c.symbol)) {
757
+ return (_e = this.maskAvailablePatterns[(_d = maskExpression[index]) !== null && _d !== void 0 ? _d : '']) === null || _e === void 0 ? void 0 : _e.symbol;
731
758
  }
732
759
  return curr;
733
760
  })
@@ -735,11 +762,12 @@ class MaskService extends MaskApplierService {
735
762
  }
736
763
  // this function is not necessary, it checks result against maskExpression
737
764
  getActualValue(res) {
738
- const compare = res
739
- .split('')
740
- .filter((symbol, i) => this._checkSymbolMask(symbol, this.maskExpression[i]) ||
741
- (this.maskSpecialCharacters.includes(this.maskExpression[i]) &&
742
- symbol === this.maskExpression[i]));
765
+ const compare = res.split('').filter((symbol, i) => {
766
+ var _a;
767
+ const maskChar = (_a = this.maskExpression[i]) !== null && _a !== void 0 ? _a : '';
768
+ return (this._checkSymbolMask(symbol, maskChar) ||
769
+ (this.maskSpecialCharacters.includes(maskChar) && symbol === maskChar));
770
+ });
743
771
  if (compare.join('') === res) {
744
772
  return compare.join('');
745
773
  }
@@ -749,7 +777,8 @@ class MaskService extends MaskApplierService {
749
777
  let symbolToReplace = '';
750
778
  const newInputValue = (inputValue &&
751
779
  inputValue.split('').map((currSymbol, index) => {
752
- if (this.maskSpecialCharacters.includes(inputValue[index + 1]) &&
780
+ var _a;
781
+ if (this.maskSpecialCharacters.includes((_a = inputValue[index + 1]) !== null && _a !== void 0 ? _a : '') &&
753
782
  inputValue[index + 1] !== this.maskExpression[index + 1]) {
754
783
  symbolToReplace = currSymbol;
755
784
  return inputValue[index + 1];
@@ -813,7 +842,9 @@ class MaskService extends MaskApplierService {
813
842
  Promise.resolve().then(() => this._renderer.setProperty(this._elementRef.nativeElement, name, value));
814
843
  }
815
844
  checkSpecialCharAmount(mask) {
816
- const chars = mask.split('').filter((item) => this._findSpecialChar(item));
845
+ const chars = mask
846
+ .split('')
847
+ .filter((item) => this._findSpecialChar(item));
817
848
  return chars.length;
818
849
  }
819
850
  removeMask(inputValue) {
@@ -826,8 +857,12 @@ class MaskService extends MaskApplierService {
826
857
  }
827
858
  const arr = [];
828
859
  for (let i = 0; i < inputVal.length; i++) {
829
- if ((_a = inputVal[i]) === null || _a === void 0 ? void 0 : _a.match('\\d')) {
830
- arr.push(inputVal[i]);
860
+ const value = (_a = inputVal[i]) !== null && _a !== void 0 ? _a : '';
861
+ if (!value) {
862
+ continue;
863
+ }
864
+ if (value.match('\\d')) {
865
+ arr.push(value);
831
866
  }
832
867
  }
833
868
  if (arr.length <= 3) {
@@ -860,8 +895,12 @@ class MaskService extends MaskApplierService {
860
895
  }
861
896
  const arr = [];
862
897
  for (let i = 0; i < inputVal.length; i++) {
863
- if ((_a = inputVal[i]) === null || _a === void 0 ? void 0 : _a.match('\\d')) {
864
- arr.push(inputVal[i]);
898
+ const value = (_a = inputVal[i]) !== null && _a !== void 0 ? _a : '';
899
+ if (!value) {
900
+ continue;
901
+ }
902
+ if (value.match('\\d')) {
903
+ arr.push(value);
865
904
  }
866
905
  }
867
906
  if (arr.length <= 3) {
@@ -954,7 +993,9 @@ class MaskService extends MaskApplierService {
954
993
  return new RegExp(specialCharactersForRemove.map((item) => `\\${item}`).join('|'), 'gi');
955
994
  }
956
995
  _replaceDecimalMarkerToDot(value) {
957
- const markers = Array.isArray(this.decimalMarker) ? this.decimalMarker : [this.decimalMarker];
996
+ const markers = Array.isArray(this.decimalMarker)
997
+ ? this.decimalMarker
998
+ : [this.decimalMarker];
958
999
  return value.replace(this._regExpForRemove(markers), '.');
959
1000
  }
960
1001
  _checkSymbols(result) {
@@ -988,12 +1029,12 @@ class MaskService extends MaskApplierService {
988
1029
  return Number(separatorValue);
989
1030
  }
990
1031
  }
991
- MaskService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskService, deps: [{ token: DOCUMENT }, { token: config }, { token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Injectable });
992
- MaskService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskService });
993
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskService, decorators: [{
1032
+ 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 });
1033
+ MaskService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskService });
1034
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskService, decorators: [{
994
1035
  type: Injectable
995
1036
  }], ctorParameters: function () {
996
- return [{ type: undefined, decorators: [{
1037
+ return [{ type: Document, decorators: [{
997
1038
  type: Inject,
998
1039
  args: [DOCUMENT]
999
1040
  }] }, { type: undefined, decorators: [{
@@ -1032,7 +1073,9 @@ class MaskDirective {
1032
1073
  this._position = null;
1033
1074
  this._maskExpressionArray = [];
1034
1075
  this._justPasted = false;
1076
+ // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
1035
1077
  this.onChange = (_) => { };
1078
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
1036
1079
  this.onTouch = () => { };
1037
1080
  }
1038
1081
  ngOnChanges(changes) {
@@ -1110,7 +1153,8 @@ class MaskDirective {
1110
1153
  if (allowNegativeNumbers) {
1111
1154
  this._maskService.allowNegativeNumbers = allowNegativeNumbers.currentValue;
1112
1155
  if (this._maskService.allowNegativeNumbers) {
1113
- this._maskService.maskSpecialCharacters = this._maskService.maskSpecialCharacters.filter((c) => c !== '-');
1156
+ this._maskService.maskSpecialCharacters =
1157
+ this._maskService.maskSpecialCharacters.filter((c) => c !== '-');
1114
1158
  }
1115
1159
  }
1116
1160
  if (leadZeroDateTime) {
@@ -1123,6 +1167,7 @@ class MaskDirective {
1123
1167
  }
1124
1168
  // eslint-disable-next-line complexity
1125
1169
  validate({ value }) {
1170
+ var _a, _b;
1126
1171
  if (!this._maskService.validation || !this._maskValue) {
1127
1172
  return null;
1128
1173
  }
@@ -1147,7 +1192,7 @@ class MaskDirective {
1147
1192
  if (value && value.toString().length >= 1) {
1148
1193
  let counterOfOpt = 0;
1149
1194
  for (const key in this._maskService.maskAvailablePatterns) {
1150
- if (this._maskService.maskAvailablePatterns[key].optional) {
1195
+ if ((_a = this._maskService.maskAvailablePatterns[key]) === null || _a === void 0 ? void 0 : _a.optional) {
1151
1196
  if (this._maskValue.indexOf(key) !== this._maskValue.lastIndexOf(key)) {
1152
1197
  const opt = this._maskValue
1153
1198
  .split('')
@@ -1169,7 +1214,9 @@ class MaskDirective {
1169
1214
  }
1170
1215
  if (this._maskValue.indexOf('{') === 1 &&
1171
1216
  value.toString().length ===
1172
- this._maskValue.length + Number(this._maskValue.split('{')[1].split('}')[0]) - 4) {
1217
+ this._maskValue.length +
1218
+ Number(((_b = this._maskValue.split('{')[1]) !== null && _b !== void 0 ? _b : '').split('}')[0]) -
1219
+ 4) {
1173
1220
  return null;
1174
1221
  }
1175
1222
  if (this._maskValue.indexOf('*') === 1 || this._maskValue.indexOf('?') === 1) {
@@ -1204,7 +1251,8 @@ class MaskDirective {
1204
1251
  }
1205
1252
  onModelChange(value) {
1206
1253
  // on form reset we need to update the actualValue
1207
- if ((value === '' || value === null || value === undefined) && this._maskService.actualValue) {
1254
+ if ((value === '' || value === null || value === undefined) &&
1255
+ this._maskService.actualValue) {
1208
1256
  this._maskService.actualValue = this._maskService.getActualValue('');
1209
1257
  }
1210
1258
  }
@@ -1230,7 +1278,8 @@ class MaskDirective {
1230
1278
  if (this._getActiveElement() !== el) {
1231
1279
  return;
1232
1280
  }
1233
- this._position = this._position === 1 && this._inputValue.length === 1 ? null : this._position;
1281
+ this._position =
1282
+ this._position === 1 && this._inputValue.length === 1 ? null : this._position;
1234
1283
  let positionToApply = this._position
1235
1284
  ? this._inputValue.length + position + caretShift
1236
1285
  : position + (this._code === 'Backspace' && !backspaceShift ? 0 : caretShift);
@@ -1280,27 +1329,29 @@ class MaskDirective {
1280
1329
  }
1281
1330
  }
1282
1331
  }
1283
- const nextValue = !el.value || el.value === this._maskService.prefix
1284
- ? this._maskService.prefix + this._maskService.maskIsShown
1285
- : el.value;
1332
+ const nextValue = el &&
1333
+ (!el.value || el.value === this._maskService.prefix
1334
+ ? this._maskService.prefix + this._maskService.maskIsShown
1335
+ : el.value);
1286
1336
  /** Fix of cursor position jumping to end in most browsers no matter where cursor is inserted onFocus */
1287
- if (el.value !== nextValue) {
1337
+ if (el && el.value !== nextValue) {
1288
1338
  el.value = nextValue;
1289
1339
  }
1290
1340
  /** fix of cursor position with prefix when mouse click occur */
1291
- if ((el.selectionStart || el.selectionEnd) <=
1292
- this._maskService.prefix.length) {
1341
+ if (el &&
1342
+ (el.selectionStart || el.selectionEnd) <=
1343
+ this._maskService.prefix.length) {
1293
1344
  el.selectionStart = this._maskService.prefix.length;
1294
1345
  return;
1295
1346
  }
1296
1347
  /** select only inserted text */
1297
- if (el.selectionEnd > this._getActualInputLength()) {
1348
+ if (el && el.selectionEnd > this._getActualInputLength()) {
1298
1349
  el.selectionEnd = this._getActualInputLength();
1299
1350
  }
1300
1351
  }
1301
1352
  // eslint-disable-next-line complexity
1302
1353
  onKeyDown(e) {
1303
- var _a;
1354
+ var _a, _b;
1304
1355
  if (!this._maskValue) {
1305
1356
  return;
1306
1357
  }
@@ -1326,8 +1377,9 @@ class MaskDirective {
1326
1377
  else {
1327
1378
  if (this._inputValue.length !== el.selectionStart &&
1328
1379
  el.selectionStart !== 1) {
1329
- while (this.specialCharacters.includes(this._inputValue[el.selectionStart - 1].toString()) &&
1330
- ((this.prefix.length >= 1 && el.selectionStart > this.prefix.length) ||
1380
+ while (this.specialCharacters.includes(((_b = this._inputValue[el.selectionStart - 1]) !== null && _b !== void 0 ? _b : '').toString()) &&
1381
+ ((this.prefix.length >= 1 &&
1382
+ el.selectionStart > this.prefix.length) ||
1331
1383
  this.prefix.length === 0)) {
1332
1384
  el.setSelectionRange(el.selectionStart - 1, el.selectionEnd);
1333
1385
  }
@@ -1380,7 +1432,9 @@ class MaskDirective {
1380
1432
  if (!Array.isArray(this.decimalMarker)) {
1381
1433
  // eslint-disable-next-line no-param-reassign
1382
1434
  inputValue =
1383
- this.decimalMarker !== '.' ? inputValue.replace('.', this.decimalMarker) : inputValue;
1435
+ this.decimalMarker !== '.'
1436
+ ? inputValue.replace('.', this.decimalMarker)
1437
+ : inputValue;
1384
1438
  }
1385
1439
  this._maskService.isNumberValue = true;
1386
1440
  }
@@ -1393,7 +1447,7 @@ class MaskDirective {
1393
1447
  if ((inputValue && this._maskService.maskExpression) ||
1394
1448
  (this._maskService.maskExpression &&
1395
1449
  (this._maskService.prefix || this._maskService.showMaskTyped))) {
1396
- // Let the service we know we are writing value so that triggering onChange function wont happen during applyMask
1450
+ // Let the service we know we are writing value so that triggering onChange function won't happen during applyMask
1397
1451
  this._maskService.writingValue = true;
1398
1452
  this._maskService.formElementProperty = [
1399
1453
  'value',
@@ -1409,8 +1463,7 @@ class MaskDirective {
1409
1463
  });
1410
1464
  }
1411
1465
  registerOnChange(fn) {
1412
- this.onChange = fn;
1413
- this._maskService.onChange = this.onChange;
1466
+ this._maskService.onChange = this.onChange = fn;
1414
1467
  }
1415
1468
  registerOnTouched(fn) {
1416
1469
  this.onTouch = fn;
@@ -1435,10 +1488,14 @@ class MaskDirective {
1435
1488
  }
1436
1489
  _repeatPatternSymbols(maskExp) {
1437
1490
  return ((maskExp.match(/{[0-9]+}/) &&
1438
- maskExp.split('').reduce((accum, currval, index) => {
1439
- this._start = currval === '{' ? index : this._start;
1440
- if (currval !== '}') {
1441
- return this._maskService._findSpecialChar(currval) ? accum + currval : accum;
1491
+ maskExp
1492
+ .split('')
1493
+ .reduce((accum, currVal, index) => {
1494
+ this._start = currVal === '{' ? index : this._start;
1495
+ if (currVal !== '}') {
1496
+ return this._maskService._findSpecialChar(currVal)
1497
+ ? accum + currVal
1498
+ : accum;
1442
1499
  }
1443
1500
  this._end = index;
1444
1501
  const repeatNumber = Number(maskExp.slice(this._start + 1, this._end));
@@ -1456,11 +1513,14 @@ class MaskDirective {
1456
1513
  ];
1457
1514
  }
1458
1515
  _validateTime(value) {
1459
- const rowMaskLen = this._maskValue.split('').filter((s) => s !== ':').length;
1516
+ var _a;
1517
+ const rowMaskLen = this._maskValue
1518
+ .split('')
1519
+ .filter((s) => s !== ':').length;
1460
1520
  if (!value) {
1461
1521
  return null; // Don't validate empty values to allow for optional form control
1462
1522
  }
1463
- if ((+value[value.length - 1] === 0 && value.length < rowMaskLen) ||
1523
+ if ((+((_a = value[value.length - 1]) !== null && _a !== void 0 ? _a : -1) === 0 && value.length < rowMaskLen) ||
1464
1524
  value.length <= rowMaskLen - 2) {
1465
1525
  return this._createValidationError(value);
1466
1526
  }
@@ -1481,7 +1541,7 @@ class MaskDirective {
1481
1541
  _setMask() {
1482
1542
  if (this._maskExpressionArray.length > 0) {
1483
1543
  this._maskExpressionArray.some((mask) => {
1484
- var _a, _b;
1544
+ var _a, _b, _c;
1485
1545
  const test = ((_a = this._maskService.removeMask(this._inputValue)) === null || _a === void 0 ? void 0 : _a.length) <=
1486
1546
  ((_b = this._maskService.removeMask(mask)) === null || _b === void 0 ? void 0 : _b.length);
1487
1547
  if (this._inputValue && test) {
@@ -1491,17 +1551,18 @@ class MaskDirective {
1491
1551
  return test;
1492
1552
  }
1493
1553
  else {
1494
- this._maskValue = this._maskExpressionArray[this._maskExpressionArray.length - 1];
1495
- this.maskExpression = this._maskExpressionArray[this._maskExpressionArray.length - 1];
1496
- this._maskService.maskExpression =
1497
- this._maskExpressionArray[this._maskExpressionArray.length - 1];
1554
+ const expression = (_c = this._maskExpressionArray[this._maskExpressionArray.length - 1]) !== null && _c !== void 0 ? _c : '';
1555
+ this._maskValue =
1556
+ this.maskExpression =
1557
+ this._maskService.maskExpression =
1558
+ expression;
1498
1559
  }
1499
1560
  });
1500
1561
  }
1501
1562
  }
1502
1563
  }
1503
- MaskDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskDirective, deps: [{ token: DOCUMENT }, { token: MaskService }, { token: config }], target: i0.ɵɵFactoryTarget.Directive });
1504
- MaskDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.1", 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: [
1564
+ 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 });
1565
+ 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: [
1505
1566
  {
1506
1567
  provide: NG_VALUE_ACCESSOR,
1507
1568
  useExisting: forwardRef(() => MaskDirective),
@@ -1514,7 +1575,7 @@ MaskDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version:
1514
1575
  },
1515
1576
  MaskService,
1516
1577
  ], exportAs: ["mask", "ngxMask"], usesOnChanges: true, ngImport: i0 });
1517
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskDirective, decorators: [{
1578
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskDirective, decorators: [{
1518
1579
  type: Directive,
1519
1580
  args: [{
1520
1581
  selector: 'input[mask], textarea[mask]',
@@ -1534,7 +1595,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.1", ngImpor
1534
1595
  exportAs: 'mask,ngxMask',
1535
1596
  }]
1536
1597
  }], ctorParameters: function () {
1537
- return [{ type: undefined, decorators: [{
1598
+ return [{ type: Document, decorators: [{
1538
1599
  type: Inject,
1539
1600
  args: [DOCUMENT]
1540
1601
  }] }, { type: MaskService }, { type: undefined, decorators: [{
@@ -1619,9 +1680,9 @@ class MaskPipe {
1619
1680
  return this._maskService.applyMaskWithPattern(`${value}`, mask);
1620
1681
  }
1621
1682
  }
1622
- MaskPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskPipe, deps: [{ token: MaskApplierService }], target: i0.ɵɵFactoryTarget.Pipe });
1623
- MaskPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.2.1", ngImport: i0, type: MaskPipe, name: "mask" });
1624
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskPipe, decorators: [{
1683
+ MaskPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskPipe, deps: [{ token: MaskApplierService }], target: i0.ɵɵFactoryTarget.Pipe });
1684
+ MaskPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.2.8", ngImport: i0, type: MaskPipe, name: "mask" });
1685
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskPipe, decorators: [{
1625
1686
  type: Pipe,
1626
1687
  args: [{
1627
1688
  name: 'mask',
@@ -1664,10 +1725,10 @@ class NgxMaskModule {
1664
1725
  };
1665
1726
  }
1666
1727
  }
1667
- NgxMaskModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: NgxMaskModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1668
- NgxMaskModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.1", ngImport: i0, type: NgxMaskModule, declarations: [MaskDirective, MaskPipe], exports: [MaskDirective, MaskPipe] });
1669
- NgxMaskModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: NgxMaskModule });
1670
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: NgxMaskModule, decorators: [{
1728
+ NgxMaskModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: NgxMaskModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1729
+ NgxMaskModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.8", ngImport: i0, type: NgxMaskModule, declarations: [MaskDirective, MaskPipe], exports: [MaskDirective, MaskPipe] });
1730
+ NgxMaskModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: NgxMaskModule });
1731
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: NgxMaskModule, decorators: [{
1671
1732
  type: NgModule,
1672
1733
  args: [{
1673
1734
  exports: [MaskDirective, MaskPipe],
@@ -1686,6 +1747,7 @@ const commonjsGlobal = typeof globalThis !== 'undefined'
1686
1747
  : {};
1687
1748
  (function () {
1688
1749
  if (!commonjsGlobal.KeyboardEvent) {
1750
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
1689
1751
  commonjsGlobal.KeyboardEvent = function (_eventType, _init) { };
1690
1752
  }
1691
1753
  })();