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.
@@ -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.substr(0, precision + 1);
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.substr(i, this.suffix?.length);
139
+ const substr = this.suffix.substring(i, this.suffix?.length);
140
140
  if (inputValue.includes(substr) &&
141
- (i - 1 < 0 || !inputValue.includes(this.suffix.substr(i - 1, this.suffix?.length)))) {
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
- if (precisionMatch && precisionMatch[0].length - 1 > precision) {
158
- const diff = precisionMatch[0].length - 1 - precision;
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, cb = () => { }) {
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);
@@ -266,9 +272,10 @@ class MaskApplierService {
266
272
  inputValue =
267
273
  inputValue.length > 1 &&
268
274
  inputValue[0] === '0' &&
275
+ inputValue[1] !== this.thousandSeparator &&
269
276
  !this._compareOrIncludes(inputValue[1], this.decimalMarker, this.thousandSeparator) &&
270
277
  !backspaced
271
- ? inputValue.slice(1, inputValue.length)
278
+ ? inputValue.slice(0, inputValue.length - 1)
272
279
  : inputValue;
273
280
  if (backspaced) {
274
281
  // eslint-disable-next-line no-param-reassign
@@ -311,7 +318,9 @@ class MaskApplierService {
311
318
  _shift++;
312
319
  } while (_shift < shiftStep);
313
320
  }
314
- else if ((commaShift !== 0 && position > 0 && !(result.indexOf(',') >= position && position > 3)) ||
321
+ else if ((commaShift !== 0 &&
322
+ position > 0 &&
323
+ !(result.indexOf(',') >= position && position > 3)) ||
315
324
  (!(result.indexOf('.') >= position && position > 3) && shiftStep <= 0)) {
316
325
  this._shift.clear();
317
326
  backspaceShift = true;
@@ -327,33 +336,33 @@ class MaskApplierService {
327
336
  else {
328
337
  for (
329
338
  // eslint-disable-next-line
330
- 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] ?? '') {
331
340
  if (cursor === maskExpression.length) {
332
341
  break;
333
342
  }
334
- if (this._checkSymbolMask(inputSymbol, maskExpression[cursor]) &&
343
+ if (this._checkSymbolMask(inputSymbol, maskExpression[cursor] ?? '') &&
335
344
  maskExpression[cursor + 1] === '?') {
336
345
  result += inputSymbol;
337
346
  cursor += 2;
338
347
  }
339
348
  else if (maskExpression[cursor + 1] === '*' &&
340
349
  multi &&
341
- this._checkSymbolMask(inputSymbol, maskExpression[cursor + 2])) {
350
+ this._checkSymbolMask(inputSymbol, maskExpression[cursor + 2] ?? '')) {
342
351
  result += inputSymbol;
343
352
  cursor += 3;
344
353
  multi = false;
345
354
  }
346
- else if (this._checkSymbolMask(inputSymbol, maskExpression[cursor]) &&
355
+ else if (this._checkSymbolMask(inputSymbol, maskExpression[cursor] ?? '') &&
347
356
  maskExpression[cursor + 1] === '*') {
348
357
  result += inputSymbol;
349
358
  multi = true;
350
359
  }
351
360
  else if (maskExpression[cursor + 1] === '?' &&
352
- this._checkSymbolMask(inputSymbol, maskExpression[cursor + 2])) {
361
+ this._checkSymbolMask(inputSymbol, maskExpression[cursor + 2] ?? '')) {
353
362
  result += inputSymbol;
354
363
  cursor += 3;
355
364
  }
356
- else if (this._checkSymbolMask(inputSymbol, maskExpression[cursor])) {
365
+ else if (this._checkSymbolMask(inputSymbol, maskExpression[cursor] ?? '')) {
357
366
  if (maskExpression[cursor] === 'H') {
358
367
  if (Number(inputSymbol) > 2) {
359
368
  cursor += 1;
@@ -463,15 +472,15 @@ class MaskApplierService {
463
472
  result += inputSymbol;
464
473
  cursor++;
465
474
  }
466
- else if (this.maskSpecialCharacters.indexOf(maskExpression[cursor]) !== -1) {
475
+ else if (this.maskSpecialCharacters.indexOf(maskExpression[cursor] ?? '') !== -1) {
467
476
  result += maskExpression[cursor];
468
477
  cursor++;
469
478
  this._shiftStep(maskExpression, cursor, inputArray.length);
470
479
  i--;
471
480
  }
472
481
  else if (this.maskSpecialCharacters.indexOf(inputSymbol) > -1 &&
473
- this.maskAvailablePatterns[maskExpression[cursor]] &&
474
- this.maskAvailablePatterns[maskExpression[cursor]]?.optional) {
482
+ this.maskAvailablePatterns[maskExpression[cursor] ?? ''] &&
483
+ this.maskAvailablePatterns[maskExpression[cursor] ?? '']?.optional) {
475
484
  if (!!inputArray[cursor] &&
476
485
  maskExpression !== '099.099.099.099' &&
477
486
  maskExpression !== '000.000.000-00' &&
@@ -483,14 +492,14 @@ class MaskApplierService {
483
492
  i--;
484
493
  }
485
494
  else if (this.maskExpression[cursor + 1] === '*' &&
486
- this._findSpecialChar(this.maskExpression[cursor + 2]) &&
495
+ this._findSpecialChar(this.maskExpression[cursor + 2] ?? '') &&
487
496
  this._findSpecialChar(inputSymbol) === this.maskExpression[cursor + 2] &&
488
497
  multi) {
489
498
  cursor += 3;
490
499
  result += inputSymbol;
491
500
  }
492
501
  else if (this.maskExpression[cursor + 1] === '?' &&
493
- this._findSpecialChar(this.maskExpression[cursor + 2]) &&
502
+ this._findSpecialChar(this.maskExpression[cursor + 2] ?? '') &&
494
503
  this._findSpecialChar(inputSymbol) === this.maskExpression[cursor + 2] &&
495
504
  multi) {
496
505
  cursor += 3;
@@ -504,7 +513,8 @@ class MaskApplierService {
504
513
  }
505
514
  }
506
515
  if (result.length + 1 === maskExpression.length &&
507
- this.maskSpecialCharacters.indexOf(maskExpression[maskExpression.length - 1]) !== -1) {
516
+ this.maskSpecialCharacters.indexOf(maskExpression[maskExpression.length - 1] ?? '') !==
517
+ -1) {
508
518
  result += maskExpression[maskExpression.length - 1];
509
519
  }
510
520
  let newPosition = position + 1;
@@ -541,18 +551,21 @@ class MaskApplierService {
541
551
  this.maskAvailablePatterns = this.customPattern
542
552
  ? this.customPattern
543
553
  : this.maskAvailablePatterns;
544
- return (this.maskAvailablePatterns[maskSymbol] &&
545
- this.maskAvailablePatterns[maskSymbol].pattern &&
546
- this.maskAvailablePatterns[maskSymbol].pattern.test(inputSymbol));
554
+ return ((this.maskAvailablePatterns[maskSymbol]?.pattern &&
555
+ this.maskAvailablePatterns[maskSymbol]?.pattern.test(inputSymbol)) ??
556
+ false);
547
557
  }
548
558
  _stripToDecimal(str) {
549
559
  return str
550
560
  .split('')
551
561
  .filter((i, idx) => {
562
+ const isDecimalMarker = typeof this.decimalMarker === 'string'
563
+ ? i === this.decimalMarker
564
+ : // TODO (inepipenko) use utility type
565
+ this.decimalMarker.includes(i);
552
566
  return (i.match('^-?\\d') ||
553
- i.match('\\s') ||
554
- i === '.' ||
555
- i === ',' ||
567
+ i === this.thousandSeparator ||
568
+ isDecimalMarker ||
556
569
  (i === '-' && idx === 0 && this.allowNegativeNumbers));
557
570
  })
558
571
  .join('');
@@ -568,7 +581,9 @@ class MaskApplierService {
568
581
  return char;
569
582
  }
570
583
  _shiftStep(maskExpression, cursor, inputLength) {
571
- const shiftStep = /[*?]/g.test(maskExpression.slice(0, cursor)) ? inputLength : cursor;
584
+ const shiftStep = /[*?]/g.test(maskExpression.slice(0, cursor))
585
+ ? inputLength
586
+ : cursor;
572
587
  this._shift.add(shiftStep + this.prefix.length || 0);
573
588
  }
574
589
  _compareOrIncludes(value, comparedValue, excludedValue) {
@@ -586,9 +601,9 @@ class MaskApplierService {
586
601
  }));
587
602
  }
588
603
  }
589
- MaskApplierService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskApplierService, deps: [{ token: config }], target: i0.ɵɵFactoryTarget.Injectable });
590
- MaskApplierService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskApplierService });
591
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskApplierService, decorators: [{
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: [{
592
607
  type: Injectable
593
608
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
594
609
  type: Inject,
@@ -615,10 +630,13 @@ class MaskService extends MaskApplierService {
615
630
  this.writingValue = false;
616
631
  this.maskChanged = false;
617
632
  this.triggerOnMaskChange = false;
633
+ // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
618
634
  this.onChange = (_) => { };
619
635
  }
620
636
  // eslint-disable-next-line complexity
621
- applyMask(inputValue, maskExpression, position = 0, justPasted = false, backspaced = false, cb = () => { }) {
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 = () => { }) {
622
640
  if (!maskExpression) {
623
641
  return inputValue !== this.actualValue ? this.actualValue : inputValue;
624
642
  }
@@ -633,7 +651,9 @@ class MaskService extends MaskApplierService {
633
651
  this.formControlResult(this.prefix);
634
652
  return this.prefix + this.maskIsShown;
635
653
  }
636
- const getSymbol = !!inputValue && typeof this.selStart === 'number' ? inputValue[this.selStart] : '';
654
+ const getSymbol = !!inputValue && typeof this.selStart === 'number'
655
+ ? inputValue[this.selStart] ?? ''
656
+ : '';
637
657
  let newInputValue = '';
638
658
  if (this.hiddenInput !== undefined && !this.writingValue) {
639
659
  let actualResult = this.actualValue.split('');
@@ -674,12 +694,15 @@ class MaskService extends MaskApplierService {
674
694
  }
675
695
  // b) remove decimal marker from list of special characters to mask
676
696
  if (this.maskExpression.startsWith('separator') && this.dropSpecialCharacters === true) {
677
- 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
+ );
678
699
  }
679
700
  this.formControlResult(result);
680
701
  if (!this.showMaskTyped) {
681
702
  if (this.hiddenInput) {
682
- return result && result.length ? this.hideInput(result, this.maskExpression) : result;
703
+ return result && result.length
704
+ ? this.hideInput(result, this.maskExpression)
705
+ : result;
683
706
  }
684
707
  return result;
685
708
  }
@@ -705,7 +728,9 @@ class MaskService extends MaskApplierService {
705
728
  }
706
729
  return countSkipedSymbol;
707
730
  }
708
- applyValueChanges(position, justPasted, backspaced, cb = () => { }) {
731
+ applyValueChanges(position, justPasted, backspaced,
732
+ // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
733
+ cb = () => { }) {
709
734
  const formElement = this._elementRef.nativeElement;
710
735
  formElement.value = this.applyMask(formElement.value, this.maskExpression, position, justPasted, backspaced, cb);
711
736
  if (formElement === this._getActiveElement()) {
@@ -718,9 +743,9 @@ class MaskService extends MaskApplierService {
718
743
  .split('')
719
744
  .map((curr, index) => {
720
745
  if (this.maskAvailablePatterns &&
721
- this.maskAvailablePatterns[maskExpression[index]] &&
722
- this.maskAvailablePatterns[maskExpression[index]]?.symbol) {
723
- return this.maskAvailablePatterns[maskExpression[index]]?.symbol;
746
+ this.maskAvailablePatterns[maskExpression[index] ?? ''] &&
747
+ this.maskAvailablePatterns[maskExpression[index] ?? '']?.symbol) {
748
+ return this.maskAvailablePatterns[maskExpression[index] ?? '']?.symbol;
724
749
  }
725
750
  return curr;
726
751
  })
@@ -728,11 +753,11 @@ class MaskService extends MaskApplierService {
728
753
  }
729
754
  // this function is not necessary, it checks result against maskExpression
730
755
  getActualValue(res) {
731
- const compare = res
732
- .split('')
733
- .filter((symbol, i) => this._checkSymbolMask(symbol, this.maskExpression[i]) ||
734
- (this.maskSpecialCharacters.includes(this.maskExpression[i]) &&
735
- symbol === this.maskExpression[i]));
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
+ });
736
761
  if (compare.join('') === res) {
737
762
  return compare.join('');
738
763
  }
@@ -742,7 +767,7 @@ class MaskService extends MaskApplierService {
742
767
  let symbolToReplace = '';
743
768
  const newInputValue = (inputValue &&
744
769
  inputValue.split('').map((currSymbol, index) => {
745
- if (this.maskSpecialCharacters.includes(inputValue[index + 1]) &&
770
+ if (this.maskSpecialCharacters.includes(inputValue[index + 1] ?? '') &&
746
771
  inputValue[index + 1] !== this.maskExpression[index + 1]) {
747
772
  symbolToReplace = currSymbol;
748
773
  return inputValue[index + 1];
@@ -806,7 +831,9 @@ class MaskService extends MaskApplierService {
806
831
  Promise.resolve().then(() => this._renderer.setProperty(this._elementRef.nativeElement, name, value));
807
832
  }
808
833
  checkSpecialCharAmount(mask) {
809
- const chars = mask.split('').filter((item) => this._findSpecialChar(item));
834
+ const chars = mask
835
+ .split('')
836
+ .filter((item) => this._findSpecialChar(item));
810
837
  return chars.length;
811
838
  }
812
839
  removeMask(inputValue) {
@@ -818,8 +845,12 @@ class MaskService extends MaskApplierService {
818
845
  }
819
846
  const arr = [];
820
847
  for (let i = 0; i < inputVal.length; i++) {
821
- if (inputVal[i]?.match('\\d')) {
822
- arr.push(inputVal[i]);
848
+ const value = inputVal[i] ?? '';
849
+ if (!value) {
850
+ continue;
851
+ }
852
+ if (value.match('\\d')) {
853
+ arr.push(value);
823
854
  }
824
855
  }
825
856
  if (arr.length <= 3) {
@@ -851,8 +882,12 @@ class MaskService extends MaskApplierService {
851
882
  }
852
883
  const arr = [];
853
884
  for (let i = 0; i < inputVal.length; i++) {
854
- if (inputVal[i]?.match('\\d')) {
855
- arr.push(inputVal[i]);
885
+ const value = inputVal[i] ?? '';
886
+ if (!value) {
887
+ continue;
888
+ }
889
+ if (value.match('\\d')) {
890
+ arr.push(value);
856
891
  }
857
892
  }
858
893
  if (arr.length <= 3) {
@@ -944,7 +979,9 @@ class MaskService extends MaskApplierService {
944
979
  return new RegExp(specialCharactersForRemove.map((item) => `\\${item}`).join('|'), 'gi');
945
980
  }
946
981
  _replaceDecimalMarkerToDot(value) {
947
- const markers = Array.isArray(this.decimalMarker) ? this.decimalMarker : [this.decimalMarker];
982
+ const markers = Array.isArray(this.decimalMarker)
983
+ ? this.decimalMarker
984
+ : [this.decimalMarker];
948
985
  return value.replace(this._regExpForRemove(markers), '.');
949
986
  }
950
987
  _checkSymbols(result) {
@@ -978,11 +1015,11 @@ class MaskService extends MaskApplierService {
978
1015
  return Number(separatorValue);
979
1016
  }
980
1017
  }
981
- 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 });
982
- MaskService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskService });
983
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskService, decorators: [{
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: [{
984
1021
  type: Injectable
985
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1022
+ }], ctorParameters: function () { return [{ type: Document, decorators: [{
986
1023
  type: Inject,
987
1024
  args: [DOCUMENT]
988
1025
  }] }, { type: undefined, decorators: [{
@@ -1020,7 +1057,9 @@ class MaskDirective {
1020
1057
  this._position = null;
1021
1058
  this._maskExpressionArray = [];
1022
1059
  this._justPasted = false;
1060
+ // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
1023
1061
  this.onChange = (_) => { };
1062
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
1024
1063
  this.onTouch = () => { };
1025
1064
  }
1026
1065
  ngOnChanges(changes) {
@@ -1098,7 +1137,8 @@ class MaskDirective {
1098
1137
  if (allowNegativeNumbers) {
1099
1138
  this._maskService.allowNegativeNumbers = allowNegativeNumbers.currentValue;
1100
1139
  if (this._maskService.allowNegativeNumbers) {
1101
- this._maskService.maskSpecialCharacters = this._maskService.maskSpecialCharacters.filter((c) => c !== '-');
1140
+ this._maskService.maskSpecialCharacters =
1141
+ this._maskService.maskSpecialCharacters.filter((c) => c !== '-');
1102
1142
  }
1103
1143
  }
1104
1144
  if (leadZeroDateTime) {
@@ -1135,7 +1175,7 @@ class MaskDirective {
1135
1175
  if (value && value.toString().length >= 1) {
1136
1176
  let counterOfOpt = 0;
1137
1177
  for (const key in this._maskService.maskAvailablePatterns) {
1138
- if (this._maskService.maskAvailablePatterns[key].optional) {
1178
+ if (this._maskService.maskAvailablePatterns[key]?.optional) {
1139
1179
  if (this._maskValue.indexOf(key) !== this._maskValue.lastIndexOf(key)) {
1140
1180
  const opt = this._maskValue
1141
1181
  .split('')
@@ -1157,7 +1197,9 @@ class MaskDirective {
1157
1197
  }
1158
1198
  if (this._maskValue.indexOf('{') === 1 &&
1159
1199
  value.toString().length ===
1160
- this._maskValue.length + Number(this._maskValue.split('{')[1].split('}')[0]) - 4) {
1200
+ this._maskValue.length +
1201
+ Number((this._maskValue.split('{')[1] ?? '').split('}')[0]) -
1202
+ 4) {
1161
1203
  return null;
1162
1204
  }
1163
1205
  if (this._maskValue.indexOf('*') === 1 || this._maskValue.indexOf('?') === 1) {
@@ -1192,7 +1234,8 @@ class MaskDirective {
1192
1234
  }
1193
1235
  onModelChange(value) {
1194
1236
  // on form reset we need to update the actualValue
1195
- if ((value === '' || value === null || value === undefined) && this._maskService.actualValue) {
1237
+ if ((value === '' || value === null || value === undefined) &&
1238
+ this._maskService.actualValue) {
1196
1239
  this._maskService.actualValue = this._maskService.getActualValue('');
1197
1240
  }
1198
1241
  }
@@ -1218,7 +1261,8 @@ class MaskDirective {
1218
1261
  if (this._getActiveElement() !== el) {
1219
1262
  return;
1220
1263
  }
1221
- this._position = this._position === 1 && this._inputValue.length === 1 ? null : this._position;
1264
+ this._position =
1265
+ this._position === 1 && this._inputValue.length === 1 ? null : this._position;
1222
1266
  let positionToApply = this._position
1223
1267
  ? this._inputValue.length + position + caretShift
1224
1268
  : position + (this._code === 'Backspace' && !backspaceShift ? 0 : caretShift);
@@ -1268,21 +1312,23 @@ class MaskDirective {
1268
1312
  }
1269
1313
  }
1270
1314
  }
1271
- const nextValue = !el.value || el.value === this._maskService.prefix
1272
- ? this._maskService.prefix + this._maskService.maskIsShown
1273
- : el.value;
1315
+ const nextValue = el &&
1316
+ (!el.value || el.value === this._maskService.prefix
1317
+ ? this._maskService.prefix + this._maskService.maskIsShown
1318
+ : el.value);
1274
1319
  /** Fix of cursor position jumping to end in most browsers no matter where cursor is inserted onFocus */
1275
- if (el.value !== nextValue) {
1320
+ if (el && el.value !== nextValue) {
1276
1321
  el.value = nextValue;
1277
1322
  }
1278
1323
  /** fix of cursor position with prefix when mouse click occur */
1279
- if ((el.selectionStart || el.selectionEnd) <=
1280
- this._maskService.prefix.length) {
1324
+ if (el &&
1325
+ (el.selectionStart || el.selectionEnd) <=
1326
+ this._maskService.prefix.length) {
1281
1327
  el.selectionStart = this._maskService.prefix.length;
1282
1328
  return;
1283
1329
  }
1284
1330
  /** select only inserted text */
1285
- if (el.selectionEnd > this._getActualInputLength()) {
1331
+ if (el && el.selectionEnd > this._getActualInputLength()) {
1286
1332
  el.selectionEnd = this._getActualInputLength();
1287
1333
  }
1288
1334
  }
@@ -1313,8 +1359,9 @@ class MaskDirective {
1313
1359
  else {
1314
1360
  if (this._inputValue.length !== el.selectionStart &&
1315
1361
  el.selectionStart !== 1) {
1316
- while (this.specialCharacters.includes(this._inputValue[el.selectionStart - 1].toString()) &&
1317
- ((this.prefix.length >= 1 && el.selectionStart > this.prefix.length) ||
1362
+ while (this.specialCharacters.includes((this._inputValue[el.selectionStart - 1] ?? '').toString()) &&
1363
+ ((this.prefix.length >= 1 &&
1364
+ el.selectionStart > this.prefix.length) ||
1318
1365
  this.prefix.length === 0)) {
1319
1366
  el.setSelectionRange(el.selectionStart - 1, el.selectionEnd);
1320
1367
  }
@@ -1366,7 +1413,9 @@ class MaskDirective {
1366
1413
  if (!Array.isArray(this.decimalMarker)) {
1367
1414
  // eslint-disable-next-line no-param-reassign
1368
1415
  inputValue =
1369
- this.decimalMarker !== '.' ? inputValue.replace('.', this.decimalMarker) : inputValue;
1416
+ this.decimalMarker !== '.'
1417
+ ? inputValue.replace('.', this.decimalMarker)
1418
+ : inputValue;
1370
1419
  }
1371
1420
  this._maskService.isNumberValue = true;
1372
1421
  }
@@ -1379,7 +1428,7 @@ class MaskDirective {
1379
1428
  if ((inputValue && this._maskService.maskExpression) ||
1380
1429
  (this._maskService.maskExpression &&
1381
1430
  (this._maskService.prefix || this._maskService.showMaskTyped))) {
1382
- // Let the service we know we are writing value so that triggering onChange function wont happen during applyMask
1431
+ // Let the service we know we are writing value so that triggering onChange function won't happen during applyMask
1383
1432
  this._maskService.writingValue = true;
1384
1433
  this._maskService.formElementProperty = [
1385
1434
  'value',
@@ -1394,8 +1443,7 @@ class MaskDirective {
1394
1443
  this._inputValue = inputValue;
1395
1444
  }
1396
1445
  registerOnChange(fn) {
1397
- this.onChange = fn;
1398
- this._maskService.onChange = this.onChange;
1446
+ this._maskService.onChange = this.onChange = fn;
1399
1447
  }
1400
1448
  registerOnTouched(fn) {
1401
1449
  this.onTouch = fn;
@@ -1419,10 +1467,14 @@ class MaskDirective {
1419
1467
  }
1420
1468
  _repeatPatternSymbols(maskExp) {
1421
1469
  return ((maskExp.match(/{[0-9]+}/) &&
1422
- maskExp.split('').reduce((accum, currval, index) => {
1423
- this._start = currval === '{' ? index : this._start;
1424
- if (currval !== '}') {
1425
- return this._maskService._findSpecialChar(currval) ? accum + currval : accum;
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;
1426
1478
  }
1427
1479
  this._end = index;
1428
1480
  const repeatNumber = Number(maskExp.slice(this._start + 1, this._end));
@@ -1440,11 +1492,13 @@ class MaskDirective {
1440
1492
  ];
1441
1493
  }
1442
1494
  _validateTime(value) {
1443
- const rowMaskLen = this._maskValue.split('').filter((s) => s !== ':').length;
1495
+ const rowMaskLen = this._maskValue
1496
+ .split('')
1497
+ .filter((s) => s !== ':').length;
1444
1498
  if (!value) {
1445
1499
  return null; // Don't validate empty values to allow for optional form control
1446
1500
  }
1447
- if ((+value[value.length - 1] === 0 && value.length < rowMaskLen) ||
1501
+ if ((+(value[value.length - 1] ?? -1) === 0 && value.length < rowMaskLen) ||
1448
1502
  value.length <= rowMaskLen - 2) {
1449
1503
  return this._createValidationError(value);
1450
1504
  }
@@ -1474,17 +1528,18 @@ class MaskDirective {
1474
1528
  return test;
1475
1529
  }
1476
1530
  else {
1477
- this._maskValue = this._maskExpressionArray[this._maskExpressionArray.length - 1];
1478
- this.maskExpression = this._maskExpressionArray[this._maskExpressionArray.length - 1];
1479
- this._maskService.maskExpression =
1480
- this._maskExpressionArray[this._maskExpressionArray.length - 1];
1531
+ const expression = this._maskExpressionArray[this._maskExpressionArray.length - 1] ?? '';
1532
+ this._maskValue =
1533
+ this.maskExpression =
1534
+ this._maskService.maskExpression =
1535
+ expression;
1481
1536
  }
1482
1537
  });
1483
1538
  }
1484
1539
  }
1485
1540
  }
1486
- 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 });
1487
- 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: [
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: [
1488
1543
  {
1489
1544
  provide: NG_VALUE_ACCESSOR,
1490
1545
  useExisting: forwardRef(() => MaskDirective),
@@ -1497,7 +1552,7 @@ MaskDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version:
1497
1552
  },
1498
1553
  MaskService,
1499
1554
  ], exportAs: ["mask", "ngxMask"], usesOnChanges: true, ngImport: i0 });
1500
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskDirective, decorators: [{
1555
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: MaskDirective, decorators: [{
1501
1556
  type: Directive,
1502
1557
  args: [{
1503
1558
  selector: 'input[mask], textarea[mask]',
@@ -1516,7 +1571,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.1", ngImpor
1516
1571
  ],
1517
1572
  exportAs: 'mask,ngxMask',
1518
1573
  }]
1519
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1574
+ }], ctorParameters: function () { return [{ type: Document, decorators: [{
1520
1575
  type: Inject,
1521
1576
  args: [DOCUMENT]
1522
1577
  }] }, { type: MaskService }, { type: undefined, decorators: [{
@@ -1600,9 +1655,9 @@ class MaskPipe {
1600
1655
  return this._maskService.applyMaskWithPattern(`${value}`, mask);
1601
1656
  }
1602
1657
  }
1603
- MaskPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskPipe, deps: [{ token: MaskApplierService }], target: i0.ɵɵFactoryTarget.Pipe });
1604
- MaskPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.2.1", ngImport: i0, type: MaskPipe, name: "mask" });
1605
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: MaskPipe, decorators: [{
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: [{
1606
1661
  type: Pipe,
1607
1662
  args: [{
1608
1663
  name: 'mask',
@@ -1646,10 +1701,10 @@ class NgxMaskModule {
1646
1701
  };
1647
1702
  }
1648
1703
  }
1649
- NgxMaskModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: NgxMaskModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1650
- NgxMaskModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.1", ngImport: i0, type: NgxMaskModule, declarations: [MaskDirective, MaskPipe], exports: [MaskDirective, MaskPipe] });
1651
- NgxMaskModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: NgxMaskModule });
1652
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.1", ngImport: i0, type: NgxMaskModule, decorators: [{
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: [{
1653
1708
  type: NgModule,
1654
1709
  args: [{
1655
1710
  exports: [MaskDirective, MaskPipe],
@@ -1668,6 +1723,7 @@ const commonjsGlobal = typeof globalThis !== 'undefined'
1668
1723
  : {};
1669
1724
  (function () {
1670
1725
  if (!commonjsGlobal.KeyboardEvent) {
1726
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
1671
1727
  commonjsGlobal.KeyboardEvent = function (_eventType, _init) { };
1672
1728
  }
1673
1729
  })();