ngx-mask 14.3.2 → 14.3.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.
@@ -116,6 +116,7 @@ class NgxMaskApplierService {
116
116
  this.outputTransformFn = this._config.outputTransformFn;
117
117
  this.keepCharacterPositions = this._config.keepCharacterPositions;
118
118
  this._shift = new Set();
119
+ this.plusOnePosition = false;
119
120
  this.maskExpression = '';
120
121
  this.actualValue = '';
121
122
  this.showKeepCharacterExp = '';
@@ -222,7 +223,7 @@ class NgxMaskApplierService {
222
223
  let backspaceShift = false;
223
224
  let shift = 1;
224
225
  let stepBack = false;
225
- if (inputValue.slice(0, this.prefix.length) === this.prefix && !this.showMaskTyped) {
226
+ if (inputValue.slice(0, this.prefix.length) === this.prefix) {
226
227
  // eslint-disable-next-line no-param-reassign
227
228
  inputValue = inputValue.slice(this.prefix.length, inputValue.length);
228
229
  }
@@ -306,24 +307,91 @@ class NgxMaskApplierService {
306
307
  // eslint-disable-next-line no-param-reassign
307
308
  inputValue = this._stripToDecimal(inputValue);
308
309
  }
309
- // eslint-disable-next-line no-param-reassign
310
- inputValue =
311
- inputValue[0] === '-' && this.allowNegativeNumbers
310
+ const precision = this.getPrecision(maskExpression);
311
+ const decimalMarker = Array.isArray(this.decimalMarker)
312
+ ? "." /* MaskExpression.DOT */
313
+ : this.decimalMarker;
314
+ if (precision === 0) {
315
+ // eslint-disable-next-line no-param-reassign
316
+ inputValue = this.allowNegativeNumbers
312
317
  ? inputValue.length > 2 &&
313
- inputValue[1] === '0' &&
318
+ inputValue[0] === "-" /* MaskExpression.MINUS */ &&
319
+ inputValue[1] === "0" /* MaskExpression.NUMBER_ZERO */ &&
314
320
  inputValue[2] !== this.thousandSeparator &&
315
- !this._compareOrIncludes(inputValue[2], this.decimalMarker, this.thousandSeparator) &&
316
- !backspaced
317
- ? inputValue.slice(0, inputValue.length - 1)
318
- : inputValue
321
+ inputValue[2] !== "," /* MaskExpression.COMMA */ &&
322
+ inputValue[2] !== "." /* MaskExpression.DOT */
323
+ ? '-' + inputValue.slice(2, inputValue.length)
324
+ : inputValue[0] === "0" /* MaskExpression.NUMBER_ZERO */ &&
325
+ inputValue.length > 1 &&
326
+ inputValue[1] !== this.thousandSeparator &&
327
+ inputValue[1] !== "," /* MaskExpression.COMMA */ &&
328
+ inputValue[1] !== "." /* MaskExpression.DOT */
329
+ ? inputValue.slice(1, inputValue.length)
330
+ : inputValue
319
331
  : inputValue.length > 1 &&
320
- inputValue[0] === '0' &&
332
+ inputValue[0] === "0" /* MaskExpression.NUMBER_ZERO */ &&
321
333
  inputValue[1] !== this.thousandSeparator &&
322
- !this._compareOrIncludes(inputValue[1], this.decimalMarker, this.thousandSeparator) &&
323
- !backspaced
324
- ? inputValue.slice(0, inputValue.length - 1)
334
+ inputValue[1] !== "," /* MaskExpression.COMMA */ &&
335
+ inputValue[1] !== "." /* MaskExpression.DOT */
336
+ ? inputValue.slice(1, inputValue.length)
325
337
  : inputValue;
338
+ }
339
+ else {
340
+ // eslint-disable-next-line no-param-reassign
341
+ if (inputValue[0] === decimalMarker && inputValue.length > 1) {
342
+ // eslint-disable-next-line no-param-reassign
343
+ inputValue =
344
+ "0" /* MaskExpression.NUMBER_ZERO */ + inputValue.slice(0, inputValue.length + 1);
345
+ this.plusOnePosition = true;
346
+ }
347
+ if (inputValue[0] === "0" /* MaskExpression.NUMBER_ZERO */ &&
348
+ inputValue[1] !== decimalMarker &&
349
+ inputValue[1] !== this.thousandSeparator) {
350
+ // eslint-disable-next-line no-param-reassign
351
+ inputValue =
352
+ inputValue.length > 1
353
+ ? inputValue.slice(0, 1) +
354
+ decimalMarker +
355
+ inputValue.slice(1, inputValue.length + 1)
356
+ : inputValue;
357
+ this.plusOnePosition = true;
358
+ }
359
+ if (this.allowNegativeNumbers &&
360
+ inputValue[0] === "-" /* MaskExpression.MINUS */ &&
361
+ (inputValue[1] === decimalMarker ||
362
+ inputValue[1] === "0" /* MaskExpression.NUMBER_ZERO */)) {
363
+ // eslint-disable-next-line no-param-reassign
364
+ inputValue =
365
+ inputValue[1] === decimalMarker && inputValue.length > 2
366
+ ? inputValue.slice(0, 1) +
367
+ "0" /* MaskExpression.NUMBER_ZERO */ +
368
+ inputValue.slice(1, inputValue.length)
369
+ : inputValue[1] === "0" /* MaskExpression.NUMBER_ZERO */ &&
370
+ inputValue.length > 2 &&
371
+ inputValue[2] !== decimalMarker
372
+ ? inputValue.slice(0, 2) +
373
+ decimalMarker +
374
+ inputValue.slice(2, inputValue.length)
375
+ : inputValue;
376
+ this.plusOnePosition = true;
377
+ }
378
+ }
326
379
  if (backspaced) {
380
+ if (inputValue[0] === "0" /* MaskExpression.NUMBER_ZERO */ &&
381
+ inputValue[1] === this.decimalMarker &&
382
+ (inputValue[position] === "0" /* MaskExpression.NUMBER_ZERO */ ||
383
+ inputValue[position] === this.decimalMarker)) {
384
+ // eslint-disable-next-line no-param-reassign
385
+ inputValue = inputValue.slice(2, inputValue.length);
386
+ }
387
+ if (inputValue[0] === "-" /* MaskExpression.MINUS */ &&
388
+ inputValue[1] === "0" /* MaskExpression.NUMBER_ZERO */ &&
389
+ inputValue[2] === this.decimalMarker &&
390
+ (inputValue[position] === "0" /* MaskExpression.NUMBER_ZERO */ ||
391
+ inputValue[position] === this.decimalMarker)) {
392
+ // eslint-disable-next-line no-param-reassign
393
+ inputValue = "-" /* MaskExpression.MINUS */ + inputValue.slice(3, inputValue.length);
394
+ }
327
395
  // eslint-disable-next-line no-param-reassign
328
396
  inputValue = this._compareOrIncludes(inputValue[inputValue.length - 1], this.decimalMarker, this.thousandSeparator)
329
397
  ? inputValue.slice(0, inputValue.length - 1)
@@ -343,13 +411,10 @@ class NgxMaskApplierService {
343
411
  invalidChars = invalidChars.replace(this._charToRegExpExpression(this.decimalMarker), '');
344
412
  }
345
413
  const invalidCharRegexp = new RegExp('[' + invalidChars + ']');
346
- if (inputValue.match(invalidCharRegexp) ||
347
- (inputValue.length === 1 &&
348
- this._compareOrIncludes(inputValue, this.decimalMarker, this.thousandSeparator))) {
414
+ if (inputValue.match(invalidCharRegexp)) {
349
415
  // eslint-disable-next-line no-param-reassign
350
416
  inputValue = inputValue.substring(0, inputValue.length - 1);
351
417
  }
352
- const precision = this.getPrecision(maskExpression);
353
418
  // eslint-disable-next-line no-param-reassign
354
419
  inputValue = this.checkInputPrecision(inputValue, precision, this.decimalMarker);
355
420
  const strForSep = inputValue.replace(new RegExp(thousandSeparatorCharEscaped, 'g'), '');
@@ -422,7 +487,7 @@ class NgxMaskApplierService {
422
487
  if (maskExpression[cursor] === "H" /* MaskExpression.HOURS */) {
423
488
  if (this.apm ? Number(inputSymbol) > 9 : Number(inputSymbol) > 2) {
424
489
  // eslint-disable-next-line no-param-reassign
425
- position = position + 1;
490
+ position = !this.leadZeroDateTime ? position + 1 : position;
426
491
  cursor += 1;
427
492
  this._shiftStep(maskExpression, cursor, inputArray.length);
428
493
  i--;
@@ -458,7 +523,7 @@ class NgxMaskApplierService {
458
523
  maskExpression[cursor] === "s" /* MaskExpression.SECOND */) {
459
524
  if (Number(inputSymbol) > 5) {
460
525
  // eslint-disable-next-line no-param-reassign
461
- position = position + 1;
526
+ position = !this.leadZeroDateTime ? position + 1 : position;
462
527
  cursor += 1;
463
528
  this._shiftStep(maskExpression, cursor, inputArray.length);
464
529
  i--;
@@ -496,7 +561,7 @@ class NgxMaskApplierService {
496
561
  : Number(inputValueSliceCursorPlusTwo) > daysCount ||
497
562
  this.specialCharacters.includes(inputValueCursorPlusOne))) {
498
563
  // eslint-disable-next-line no-param-reassign
499
- position = position + 1;
564
+ position = !this.leadZeroDateTime ? position + 1 : position;
500
565
  cursor += 1;
501
566
  this._shiftStep(maskExpression, cursor, inputArray.length);
502
567
  i--;
@@ -552,7 +617,7 @@ class NgxMaskApplierService {
552
617
  day2monthInput ||
553
618
  (day2monthInputDot && !this.leadZeroDateTime)) {
554
619
  // eslint-disable-next-line no-param-reassign
555
- position = position + 1;
620
+ position = !this.leadZeroDateTime ? position + 1 : position;
556
621
  cursor += 1;
557
622
  this._shiftStep(maskExpression, cursor, inputArray.length);
558
623
  i--;
@@ -647,7 +712,7 @@ class NgxMaskApplierService {
647
712
  if (backspaced) {
648
713
  onlySpecial = inputArray.every((char) => this.specialCharacters.includes(char));
649
714
  }
650
- let res = `${this.prefix}${onlySpecial ? "" /* MaskExpression.EMPTY_STRING */ : result}${this.suffix}`;
715
+ let res = `${this.prefix}${onlySpecial ? "" /* MaskExpression.EMPTY_STRING */ : result}${this.showMaskTyped ? '' : this.suffix}`;
651
716
  if (result.length === 0) {
652
717
  res = !this.dropSpecialCharacters ? `${this.prefix}${result}` : `${result}`;
653
718
  }
@@ -761,14 +826,14 @@ class NgxMaskService extends NgxMaskApplierService {
761
826
  this.maskChanged = false;
762
827
  this._maskExpressionArray = [];
763
828
  this.triggerOnMaskChange = false;
764
- this._emitValue = false;
765
829
  this._previousValue = '';
766
830
  this._currentValue = '';
831
+ this._emitValue = false;
767
832
  // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
768
833
  this.onChange = (_) => { };
834
+ this._elementRef = inject(ElementRef, { optional: true });
769
835
  this.document = inject(DOCUMENT);
770
836
  this._config = inject(NGX_MASK_CONFIG);
771
- this._elementRef = inject(ElementRef, { optional: true });
772
837
  this._renderer = inject(Renderer2, { optional: true });
773
838
  }
774
839
  // eslint-disable-next-line complexity
@@ -789,7 +854,7 @@ class NgxMaskService extends NgxMaskApplierService {
789
854
  }
790
855
  if (!inputValue && this.showMaskTyped) {
791
856
  this.formControlResult(this.prefix);
792
- return this.prefix + this.maskIsShown;
857
+ return this.prefix + this.maskIsShown + this.suffix;
793
858
  }
794
859
  const getSymbol = !!inputValue && typeof this.selStart === 'number'
795
860
  ? inputValue[this.selStart] ?? "" /* MaskExpression.EMPTY_STRING */
@@ -835,6 +900,11 @@ class NgxMaskService extends NgxMaskApplierService {
835
900
  if (justPasted && (this.hiddenInput || !this.hiddenInput)) {
836
901
  newInputValue = inputValue;
837
902
  }
903
+ if (backspaced &&
904
+ this.specialCharacters.indexOf(this.maskExpression[position] ?? "" /* MaskExpression.EMPTY_STRING */) !== -1 &&
905
+ this.showMaskTyped) {
906
+ newInputValue = this._currentValue;
907
+ }
838
908
  if (this.deletedSpecialCharacter && position) {
839
909
  if (this.specialCharacters.includes(this.actualValue.slice(position, position + 1))) {
840
910
  // eslint-disable-next-line no-param-reassign
@@ -903,7 +973,7 @@ class NgxMaskService extends NgxMaskApplierService {
903
973
  return result;
904
974
  }
905
975
  const resLen = result.length;
906
- const prefNmask = this.prefix + this.maskIsShown;
976
+ const prefNmask = this.prefix + this.maskIsShown + this.suffix;
907
977
  if (this.maskExpression.includes("H" /* MaskExpression.HOURS */)) {
908
978
  const countSkipedSymbol = this._numberSkipedSymbols(result);
909
979
  return result + prefNmask.slice(resLen + countSkipedSymbol);
@@ -1216,11 +1286,17 @@ class NgxMaskService extends NgxMaskApplierService {
1216
1286
  return value ? value.replace(this.suffix, "" /* MaskExpression.EMPTY_STRING */) : value;
1217
1287
  }
1218
1288
  _retrieveSeparatorValue(result) {
1219
- const specialCharacters = Array.isArray(this.dropSpecialCharacters)
1289
+ let specialCharacters = Array.isArray(this.dropSpecialCharacters)
1220
1290
  ? this.specialCharacters.filter((v) => {
1221
1291
  return this.dropSpecialCharacters.includes(v);
1222
1292
  })
1223
1293
  : this.specialCharacters;
1294
+ if (!this.deletedSpecialCharacter &&
1295
+ this._checkPatternForSpace() &&
1296
+ result.includes(" " /* MaskExpression.WHITE_SPACE */) &&
1297
+ this.maskExpression.includes("*" /* MaskExpression.SYMBOL_STAR */)) {
1298
+ specialCharacters = specialCharacters.filter((char) => char !== " " /* MaskExpression.WHITE_SPACE */);
1299
+ }
1224
1300
  return this._removeMask(result, specialCharacters);
1225
1301
  }
1226
1302
  _regExpForRemove(specialCharactersForRemove) {
@@ -1259,6 +1335,20 @@ class NgxMaskService extends NgxMaskApplierService {
1259
1335
  return separatorValue;
1260
1336
  }
1261
1337
  }
1338
+ _checkPatternForSpace() {
1339
+ for (const key in this.patterns) {
1340
+ // eslint-disable-next-line no-prototype-builtins
1341
+ if (this.patterns[key] && this.patterns[key]?.hasOwnProperty('pattern')) {
1342
+ const patternString = this.patterns[key]?.pattern.toString();
1343
+ const pattern = this.patterns[key]?.pattern;
1344
+ if (patternString?.includes(" " /* MaskExpression.WHITE_SPACE */) &&
1345
+ pattern?.test(this.maskExpression)) {
1346
+ return true;
1347
+ }
1348
+ }
1349
+ }
1350
+ return false;
1351
+ }
1262
1352
  // TODO should think about helpers or separting decimal precision to own property
1263
1353
  _retrieveSeparatorPrecision(maskExpretion) {
1264
1354
  const matcher = maskExpretion.match(new RegExp(`^separator\\.([^d]*)`));
@@ -1348,6 +1438,7 @@ class NgxMaskDirective {
1348
1438
  this._position = null;
1349
1439
  this._maskExpressionArray = [];
1350
1440
  this._justPasted = false;
1441
+ this._isFocused = false;
1351
1442
  /**For IME composition event */
1352
1443
  this._isComposing = false;
1353
1444
  this.document = inject(DOCUMENT);
@@ -1365,13 +1456,6 @@ class NgxMaskDirective {
1365
1456
  !maskExpression.firstChange) {
1366
1457
  this._maskService.maskChanged = true;
1367
1458
  }
1368
- if (allowNegativeNumbers) {
1369
- this._maskService.allowNegativeNumbers = allowNegativeNumbers.currentValue;
1370
- if (this._maskService.allowNegativeNumbers) {
1371
- this._maskService.specialCharacters =
1372
- this._maskService.specialCharacters.filter((c) => c !== "-" /* MaskExpression.MINUS */);
1373
- }
1374
- }
1375
1459
  if (maskExpression.currentValue &&
1376
1460
  maskExpression.currentValue.split("||" /* MaskExpression.OR */).length > 1) {
1377
1461
  this._maskExpressionArray = maskExpression.currentValue
@@ -1395,6 +1479,12 @@ class NgxMaskDirective {
1395
1479
  this._maskService.specialCharacters = specialCharacters.currentValue || [];
1396
1480
  }
1397
1481
  }
1482
+ if (allowNegativeNumbers) {
1483
+ this._maskService.allowNegativeNumbers = allowNegativeNumbers.currentValue;
1484
+ if (this._maskService.allowNegativeNumbers) {
1485
+ this._maskService.specialCharacters = this._maskService.specialCharacters.filter((c) => c !== "-" /* MaskExpression.MINUS */);
1486
+ }
1487
+ }
1398
1488
  // Only overwrite the mask available patterns if a pattern has actually been passed in
1399
1489
  if (patterns && patterns.currentValue) {
1400
1490
  this._maskService.patterns = patterns.currentValue;
@@ -1422,6 +1512,13 @@ class NgxMaskDirective {
1422
1512
  }
1423
1513
  if (showMaskTyped) {
1424
1514
  this._maskService.showMaskTyped = showMaskTyped.currentValue;
1515
+ if (showMaskTyped.previousValue === false &&
1516
+ showMaskTyped.currentValue === true &&
1517
+ this._isFocused) {
1518
+ requestAnimationFrame(() => {
1519
+ this._maskService._elementRef?.nativeElement.click();
1520
+ });
1521
+ }
1425
1522
  }
1426
1523
  if (placeHolderCharacter) {
1427
1524
  this._maskService.placeHolderCharacter = placeHolderCharacter.currentValue;
@@ -1581,6 +1678,9 @@ class NgxMaskDirective {
1581
1678
  onPaste() {
1582
1679
  this._justPasted = true;
1583
1680
  }
1681
+ onFocus() {
1682
+ this._isFocused = true;
1683
+ }
1584
1684
  onModelChange(value) {
1585
1685
  // on form reset we need to update the actualValue
1586
1686
  if ((value === "" /* MaskExpression.EMPTY_STRING */ || value === null || value === undefined) &&
@@ -1681,13 +1781,33 @@ class NgxMaskDirective {
1681
1781
  position = position + 1;
1682
1782
  }
1683
1783
  else if (checkSymbols) {
1784
+ if (el.value.length === 1 && position === 1) {
1785
+ this._maskService.actualValue =
1786
+ this.prefix +
1787
+ inputSymbol +
1788
+ this._maskService.maskIsShown.slice(1, this._maskService.maskIsShown.length) +
1789
+ this.suffix;
1790
+ }
1791
+ else {
1792
+ this._maskService.actualValue =
1793
+ el.value.slice(0, position - 1) +
1794
+ inputSymbol +
1795
+ el.value
1796
+ .slice(position + 1)
1797
+ .split(this.suffix)
1798
+ .join('') +
1799
+ this.suffix;
1800
+ }
1801
+ }
1802
+ else if (this.prefix &&
1803
+ el.value.length === 1 &&
1804
+ position - prefixLength === 1 &&
1805
+ this._maskService._checkSymbolMask(el.value, this._maskService.maskExpression[position - 1 - prefixLength] ??
1806
+ "" /* MaskExpression.EMPTY_STRING */)) {
1684
1807
  this._maskService.actualValue =
1685
- el.value.slice(0, position - 1) +
1686
- inputSymbol +
1687
- el.value
1688
- .slice(position + 1)
1689
- .split(this.suffix)
1690
- .join('') +
1808
+ this.prefix +
1809
+ el.value +
1810
+ this._maskService.maskIsShown.slice(1, this._maskService.maskIsShown.length) +
1691
1811
  this.suffix;
1692
1812
  }
1693
1813
  }
@@ -1707,6 +1827,13 @@ class NgxMaskDirective {
1707
1827
  inputSymbol +
1708
1828
  this._inputValue.slice(position + 1);
1709
1829
  }
1830
+ if (this._maskService.maskExpression === "d0/M0/0000" /* MaskExpression.DAYS_MONTHS_YEARS */ &&
1831
+ this.leadZeroDateTime) {
1832
+ if ((position < 3 && Number(el.value) > 31 && Number(el.value) < 40) ||
1833
+ (position === 5 && Number(el.value.slice(3, 5)) > 12)) {
1834
+ position = position + 2;
1835
+ }
1836
+ }
1710
1837
  if (this._maskService.maskExpression === "Hh:m0:s0" /* MaskExpression.HOURS_MINUTES_SECONDS */ &&
1711
1838
  this.apm) {
1712
1839
  if (this._justPasted && el.value.slice(0, 2) === "00" /* MaskExpression.DOUBLE_ZERO */) {
@@ -1726,6 +1853,10 @@ class NgxMaskDirective {
1726
1853
  if (this._getActiveElement() !== el) {
1727
1854
  return;
1728
1855
  }
1856
+ if (this._maskService.plusOnePosition) {
1857
+ position = position + 1;
1858
+ this._maskService.plusOnePosition = false;
1859
+ }
1729
1860
  // update position after applyValueChanges to prevent cursor on wrong position when it has an array of maskExpression
1730
1861
  if (this._maskExpressionArray.length) {
1731
1862
  if (this._code === "Backspace" /* MaskExpression.BACKSPACE */) {
@@ -1747,7 +1878,10 @@ class NgxMaskDirective {
1747
1878
  : position +
1748
1879
  (this._code === "Backspace" /* MaskExpression.BACKSPACE */ && !backspaceShift ? 0 : caretShift);
1749
1880
  if (positionToApply > this._getActualInputLength()) {
1750
- positionToApply = this._getActualInputLength();
1881
+ positionToApply =
1882
+ el.value === this._maskService.decimalMarker && el.value.length === 1
1883
+ ? this._getActualInputLength() + 1
1884
+ : this._getActualInputLength();
1751
1885
  }
1752
1886
  if (positionToApply < 0) {
1753
1887
  positionToApply = 0;
@@ -1760,6 +1894,10 @@ class NgxMaskDirective {
1760
1894
  }
1761
1895
  }
1762
1896
  else {
1897
+ if (!this._maskValue) {
1898
+ this.onChange(el.value);
1899
+ return;
1900
+ }
1763
1901
  this._maskService.applyValueChanges(el.value.length, this._justPasted, this._code === "Backspace" /* MaskExpression.BACKSPACE */ || this._code === "Delete" /* MaskExpression.DELETE */);
1764
1902
  }
1765
1903
  }
@@ -1795,6 +1933,7 @@ class NgxMaskDirective {
1795
1933
  }
1796
1934
  this._maskService.clearIfNotMatchFn();
1797
1935
  }
1936
+ this._isFocused = false;
1798
1937
  this.onTouch();
1799
1938
  }
1800
1939
  onClick(e) {
@@ -1928,13 +2067,12 @@ class NgxMaskDirective {
1928
2067
  }
1929
2068
  }
1930
2069
  /** It writes the value in the input */
1931
- // public async writeValue(controlValue: unknown): Promise<void> {
1932
2070
  async writeValue(controlValue) {
1933
2071
  if (typeof controlValue === 'object' && controlValue !== null && 'value' in controlValue) {
1934
2072
  if ('disable' in controlValue) {
1935
2073
  this.setDisabledState(Boolean(controlValue.disable));
1936
2074
  }
1937
- // // eslint-disable-next-line no-param-reassign
2075
+ // eslint-disable-next-line no-param-reassign
1938
2076
  controlValue = controlValue.value;
1939
2077
  }
1940
2078
  if (controlValue !== null) {
@@ -1945,7 +2083,12 @@ class NgxMaskDirective {
1945
2083
  }
1946
2084
  if (typeof controlValue === 'string' ||
1947
2085
  typeof controlValue === 'number' ||
1948
- controlValue === null) {
2086
+ controlValue === null ||
2087
+ controlValue === undefined) {
2088
+ if (controlValue === null || controlValue === undefined || controlValue === '') {
2089
+ this._maskService._currentValue = '';
2090
+ this._maskService._previousValue = '';
2091
+ }
1949
2092
  // eslint-disable-next-line no-param-reassign
1950
2093
  let inputValue = controlValue;
1951
2094
  if (typeof inputValue === 'number' ||
@@ -2097,7 +2240,8 @@ class NgxMaskDirective {
2097
2240
  }
2098
2241
  }
2099
2242
  else {
2100
- const check = this._inputValue
2243
+ const check = this._maskService
2244
+ .removeMask(this._inputValue)
2101
2245
  ?.split("" /* MaskExpression.EMPTY_STRING */)
2102
2246
  .every((character, index) => {
2103
2247
  const indexMask = mask.charAt(index);
@@ -2112,7 +2256,7 @@ class NgxMaskDirective {
2112
2256
  }
2113
2257
  }
2114
2258
  NgxMaskDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: NgxMaskDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
2115
- NgxMaskDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.8", type: NgxMaskDirective, 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", leadZero: "leadZero", triggerOnMaskChange: "triggerOnMaskChange", apm: "apm", inputTransformFn: "inputTransformFn", outputTransformFn: "outputTransformFn", keepCharacterPositions: "keepCharacterPositions" }, outputs: { maskFilled: "maskFilled" }, host: { listeners: { "paste": "onPaste()", "ngModelChange": "onModelChange($event)", "input": "onInput($event)", "compositionstart": "onCompositionStart($event)", "compositionend": "onCompositionEnd($event)", "blur": "onBlur($event)", "click": "onClick($event)", "keydown": "onKeyDown($event)" } }, providers: [
2259
+ NgxMaskDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.8", type: NgxMaskDirective, 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", leadZero: "leadZero", triggerOnMaskChange: "triggerOnMaskChange", apm: "apm", inputTransformFn: "inputTransformFn", outputTransformFn: "outputTransformFn", keepCharacterPositions: "keepCharacterPositions" }, outputs: { maskFilled: "maskFilled" }, host: { listeners: { "paste": "onPaste()", "focus": "onFocus($event)", "ngModelChange": "onModelChange($event)", "input": "onInput($event)", "compositionstart": "onCompositionStart($event)", "compositionend": "onCompositionEnd($event)", "blur": "onBlur($event)", "click": "onClick($event)", "keydown": "onKeyDown($event)" } }, providers: [
2116
2260
  {
2117
2261
  provide: NG_VALUE_ACCESSOR,
2118
2262
  useExisting: forwardRef(() => NgxMaskDirective),
@@ -2124,7 +2268,7 @@ NgxMaskDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", versi
2124
2268
  multi: true,
2125
2269
  },
2126
2270
  NgxMaskService,
2127
- ], usesOnChanges: true, ngImport: i0 });
2271
+ ], exportAs: ["mask", "ngxMask"], usesOnChanges: true, ngImport: i0 });
2128
2272
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: NgxMaskDirective, decorators: [{
2129
2273
  type: Directive,
2130
2274
  args: [{
@@ -2142,6 +2286,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImpor
2142
2286
  },
2143
2287
  NgxMaskService,
2144
2288
  ],
2289
+ exportAs: 'mask,ngxMask',
2145
2290
  }]
2146
2291
  }], propDecorators: { maskExpression: [{
2147
2292
  type: Input,
@@ -2197,6 +2342,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImpor
2197
2342
  }], onPaste: [{
2198
2343
  type: HostListener,
2199
2344
  args: ['paste']
2345
+ }], onFocus: [{
2346
+ type: HostListener,
2347
+ args: ['focus', ['$event']]
2200
2348
  }], onModelChange: [{
2201
2349
  type: HostListener,
2202
2350
  args: ['ngModelChange', ['$event']]
@@ -2290,6 +2438,9 @@ class NgxMaskPipe {
2290
2438
  }
2291
2439
  this._maskService.isNumberValue = true;
2292
2440
  }
2441
+ if (value === null || value === undefined) {
2442
+ return this._maskService.applyMask('', mask);
2443
+ }
2293
2444
  return this._maskService.applyMask(`${value}`, mask);
2294
2445
  }
2295
2446
  _setMask(value) {