ngx-mask 19.0.2 → 19.0.3

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/README.md CHANGED
@@ -189,6 +189,14 @@ const maskConfigFunction: () => Partial<NgxMaskConfig> = () => {
189
189
 
190
190
  Then, just define masks in inputs.
191
191
 
192
+ ## Actively supported versions
193
+
194
+ ngx-mask follows the official Angular support policy, supporting the Active and LTS (Long-Term Support) versions of Angular. As of the latest release, Angular v17 and newer are supported.
195
+
196
+ Projects using Angular versions outside the supported range (e.g., older than v17) should use the last compatible version of ngx-mask. However, these versions will no longer receive updates, bug fixes, or new features.
197
+
198
+ For detailed information about Angular's versioning and support schedule, visit the official [Angular releases page](https://angular.dev/reference/releases#actively-supported-versions).
199
+
192
200
  ## Usage
193
201
 
194
202
  Text [documentation](https://github.com/JsDaddy/ngx-mask/blob/develop/USAGE.md)
@@ -60,7 +60,7 @@ const initialConfig = {
60
60
  showMaskTyped: false,
61
61
  placeHolderCharacter: '_',
62
62
  dropSpecialCharacters: true,
63
- hiddenInput: null,
63
+ hiddenInput: false,
64
64
  shownMaskExpression: '',
65
65
  separatorLimit: '',
66
66
  allowNegativeNumbers: false,
@@ -455,7 +455,7 @@ class NgxMaskApplierService {
455
455
  ? processedPosition + 1
456
456
  : processedPosition;
457
457
  cursor += 1;
458
- this._shiftStep(maskExpression, cursor, inputArray.length);
458
+ this._shiftStep(cursor);
459
459
  i--;
460
460
  if (this.leadZeroDateTime) {
461
461
  result += '0';
@@ -491,7 +491,7 @@ class NgxMaskApplierService {
491
491
  ? processedPosition + 1
492
492
  : processedPosition;
493
493
  cursor += 1;
494
- this._shiftStep(maskExpression, cursor, inputArray.length);
494
+ this._shiftStep(cursor);
495
495
  i--;
496
496
  if (this.leadZeroDateTime) {
497
497
  result += '0';
@@ -530,7 +530,7 @@ class NgxMaskApplierService {
530
530
  ? processedPosition + 1
531
531
  : processedPosition;
532
532
  cursor += 1;
533
- this._shiftStep(maskExpression, cursor, inputArray.length);
533
+ this._shiftStep(cursor);
534
534
  i--;
535
535
  if (this.leadZeroDateTime) {
536
536
  result += '0';
@@ -580,7 +580,7 @@ class NgxMaskApplierService {
580
580
  ? processedPosition + 1
581
581
  : processedPosition;
582
582
  cursor += 1;
583
- this._shiftStep(maskExpression, cursor, inputArray.length);
583
+ this._shiftStep(cursor);
584
584
  i--;
585
585
  if (this.leadZeroDateTime) {
586
586
  result += '0';
@@ -599,12 +599,12 @@ class NgxMaskApplierService {
599
599
  else if (this.specialCharacters.indexOf(maskExpression[cursor] ?? MaskExpression.EMPTY_STRING) !== -1) {
600
600
  result += maskExpression[cursor];
601
601
  cursor++;
602
- this._shiftStep(maskExpression, cursor, inputArray.length);
602
+ this._shiftStep(cursor);
603
603
  i--;
604
604
  }
605
605
  else if (maskExpression[cursor] === MaskExpression.NUMBER_NINE &&
606
606
  this.showMaskTyped) {
607
- this._shiftStep(maskExpression, cursor, inputArray.length);
607
+ this._shiftStep(cursor);
608
608
  }
609
609
  else if (this.patterns[maskExpression[cursor] ?? MaskExpression.EMPTY_STRING] &&
610
610
  this.patterns[maskExpression[cursor] ?? MaskExpression.EMPTY_STRING]?.optional) {
@@ -646,7 +646,8 @@ class NgxMaskApplierService {
646
646
  }
647
647
  }
648
648
  }
649
- if (result.length + 1 === maskExpression.length &&
649
+ if (result[processedPosition - 1] &&
650
+ result.length + 1 === maskExpression.length &&
650
651
  this.specialCharacters.indexOf(maskExpression[maskExpression.length - 1] ?? MaskExpression.EMPTY_STRING) !== -1) {
651
652
  result += maskExpression[maskExpression.length - 1];
652
653
  }
@@ -812,11 +813,8 @@ class NgxMaskApplierService {
812
813
  }
813
814
  return char;
814
815
  }
815
- _shiftStep(maskExpression, cursor, inputLength) {
816
- const shiftStep = /[*?]/g.test(maskExpression.slice(0, cursor))
817
- ? inputLength
818
- : cursor;
819
- this._shift.add(shiftStep + this.prefix.length || 0);
816
+ _shiftStep(cursor) {
817
+ this._shift.add(cursor + this.prefix.length || 0);
820
818
  }
821
819
  _compareOrIncludes(value, comparedValue, excludedValue) {
822
820
  return Array.isArray(comparedValue)
@@ -913,36 +911,67 @@ class NgxMaskService extends NgxMaskApplierService {
913
911
  : MaskExpression.EMPTY_STRING;
914
912
  let newInputValue = '';
915
913
  let newPosition = position;
916
- if (this.hiddenInput !== null && !this.writingValue) {
914
+ if ((this.hiddenInput ||
915
+ (inputValue && inputValue.indexOf(MaskExpression.SYMBOL_STAR) >= 0)) &&
916
+ !this.writingValue) {
917
917
  let actualResult = inputValue && inputValue.length === 1
918
918
  ? inputValue.split(MaskExpression.EMPTY_STRING)
919
919
  : this.actualValue.split(MaskExpression.EMPTY_STRING);
920
+ if (backspaced) {
921
+ actualResult = actualResult
922
+ .slice(0, position)
923
+ .concat(actualResult.slice(position + 1));
924
+ }
925
+ if (this.showMaskTyped) {
926
+ inputValue = this.removeMask(inputValue);
927
+ actualResult = this.removeMask(actualResult.join('')).split(MaskExpression.EMPTY_STRING);
928
+ }
920
929
  if (typeof this.selStart === 'object' && typeof this.selEnd === 'object') {
921
930
  this.selStart = Number(this.selStart);
922
931
  this.selEnd = Number(this.selEnd);
923
932
  }
924
933
  else {
925
- inputValue !== MaskExpression.EMPTY_STRING && actualResult.length
926
- ? typeof this.selStart === 'number' && typeof this.selEnd === 'number'
927
- ? inputValue.length > actualResult.length
928
- ? actualResult.splice(this.selStart, 0, getSymbol)
929
- : inputValue.length < actualResult.length
930
- ? actualResult.length - inputValue.length === 1
931
- ? backspaced
932
- ? actualResult.splice(this.selStart - 1, 1)
933
- : actualResult.splice(inputValue.length - 1, 1)
934
- : actualResult.splice(this.selStart, this.selEnd - this.selStart)
935
- : null
936
- : null
937
- : (actualResult = []);
934
+ if (inputValue !== MaskExpression.EMPTY_STRING && actualResult.length) {
935
+ if (typeof this.selStart === 'number' && typeof this.selEnd === 'number') {
936
+ if (inputValue.length > actualResult.length) {
937
+ actualResult.splice(this.selStart, 0, getSymbol);
938
+ }
939
+ else if (inputValue.length < actualResult.length) {
940
+ if (actualResult.length - inputValue.length === 1) {
941
+ if (backspaced) {
942
+ actualResult.splice(this.selStart - 1, 1);
943
+ }
944
+ else {
945
+ actualResult.splice(inputValue.length - 1, 1);
946
+ }
947
+ }
948
+ else {
949
+ actualResult.splice(this.selStart, this.selEnd - this.selStart);
950
+ }
951
+ }
952
+ }
953
+ }
954
+ else {
955
+ actualResult = [];
956
+ }
938
957
  }
939
958
  if (this.showMaskTyped && !this.hiddenInput) {
940
959
  newInputValue = this.removeMask(inputValue);
941
960
  }
942
- newInputValue =
943
- this.actualValue.length && actualResult.length <= inputValue.length
944
- ? this.shiftTypedSymbols(actualResult.join(MaskExpression.EMPTY_STRING))
945
- : inputValue;
961
+ if (this.actualValue.length) {
962
+ if (actualResult.length < inputValue.length) {
963
+ newInputValue = this.shiftTypedSymbols(actualResult.join(MaskExpression.EMPTY_STRING));
964
+ }
965
+ else if (actualResult.length === inputValue.length) {
966
+ newInputValue = actualResult.join(MaskExpression.EMPTY_STRING);
967
+ }
968
+ else {
969
+ newInputValue = inputValue;
970
+ }
971
+ }
972
+ else {
973
+ newInputValue = inputValue;
974
+ }
946
975
  }
947
976
  if (justPasted && (this.hiddenInput || !this.hiddenInput)) {
948
977
  newInputValue = inputValue;
@@ -965,7 +994,7 @@ class NgxMaskService extends NgxMaskApplierService {
965
994
  if (this.showMaskTyped &&
966
995
  this.placeHolderCharacter.length === 1 &&
967
996
  !this.leadZeroDateTime) {
968
- newInputValue = this.removeMask(inputValue);
997
+ newInputValue = this.removeMask(newInputValue);
969
998
  }
970
999
  if (this.maskChanged) {
971
1000
  newInputValue = inputValue;
@@ -1013,9 +1042,6 @@ class NgxMaskService extends NgxMaskApplierService {
1013
1042
  : '';
1014
1043
  if (!this.showMaskTyped || (this.showMaskTyped && this.hiddenInput)) {
1015
1044
  if (this.hiddenInput) {
1016
- if (backspaced) {
1017
- return this.hideInput(result, this.maskExpression);
1018
- }
1019
1045
  return `${this.hideInput(result, this.maskExpression)}${this.maskIsShown.slice(result.length)}`;
1020
1046
  }
1021
1047
  return result;
@@ -1258,7 +1284,7 @@ class NgxMaskService extends NgxMaskApplierService {
1258
1284
  }
1259
1285
  formControlResult(inputValue) {
1260
1286
  if (this.writingValue && !inputValue) {
1261
- this.onChange(this.outputTransformFn(''));
1287
+ this.onChange(this.outputTransformFn(null));
1262
1288
  return;
1263
1289
  }
1264
1290
  if (this.writingValue || (!this.triggerOnMaskChange && this.maskChanged)) {
@@ -1558,6 +1584,9 @@ class NgxMaskDirective {
1558
1584
  }
1559
1585
  if (hiddenInput) {
1560
1586
  this._maskService.hiddenInput = hiddenInput.currentValue;
1587
+ if (hiddenInput.previousValue === true && hiddenInput.currentValue === false) {
1588
+ this._inputValue.set(this._maskService.actualValue);
1589
+ }
1561
1590
  }
1562
1591
  if (showMaskTyped) {
1563
1592
  this._maskService.showMaskTyped = showMaskTyped.currentValue;
@@ -2258,11 +2287,12 @@ class NgxMaskDirective {
2258
2287
  }
2259
2288
  }
2260
2289
  else {
2290
+ const cleanMask = this._maskService.removeMask(mask);
2261
2291
  const check = this._maskService
2262
2292
  .removeMask(this._inputValue())
2263
2293
  ?.split(MaskExpression.EMPTY_STRING)
2264
2294
  .every((character, index) => {
2265
- const indexMask = mask.charAt(index);
2295
+ const indexMask = cleanMask.charAt(index);
2266
2296
  return this._maskService._checkSymbolMask(character, indexMask);
2267
2297
  });
2268
2298
  if (check || this._justPasted()) {