ngx-mask 16.0.3 → 16.0.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.
@@ -388,7 +388,13 @@ class NgxMaskApplierService {
388
388
  }
389
389
  }
390
390
  if (maskExpression[cursor] === 'h') {
391
- if (result === '2' && Number(inputSymbol) > 3) {
391
+ if ((result === '2' && Number(inputSymbol) > 3) ||
392
+ ((result.slice(cursor - 2, cursor) === '2' ||
393
+ result.slice(cursor - 3, cursor) === '2' ||
394
+ result.slice(cursor - 4, cursor) === '2' ||
395
+ result.slice(cursor - 1, cursor) === '2') &&
396
+ Number(inputSymbol) > 3 &&
397
+ cursor > 10)) {
392
398
  // eslint-disable-next-line no-param-reassign
393
399
  position = position + 1;
394
400
  cursor += 1;
@@ -410,31 +416,32 @@ class NgxMaskApplierService {
410
416
  }
411
417
  }
412
418
  const daysCount = 31;
419
+ const inputValueCursor = inputValue[cursor];
420
+ const inputValueCursorPlusOne = inputValue[cursor + 1];
421
+ const inputValueCursorPlusTwo = inputValue[cursor + 2];
422
+ const inputValueCursorMinusOne = inputValue[cursor - 1];
423
+ const inputValueCursorMinusTwo = inputValue[cursor - 2];
424
+ const inputValueCursorMinusThree = inputValue[cursor - 3];
425
+ const inputValueSliceMinusThreeMinusOne = inputValue.slice(cursor - 3, cursor - 1);
426
+ const inputValueSliceMinusOnePlusOne = inputValue.slice(cursor - 1, cursor + 1);
427
+ const inputValueSliceCursorPlusTwo = inputValue.slice(cursor, cursor + 2);
428
+ const inputValueSliceMinusTwoCursor = inputValue.slice(cursor - 2, cursor);
413
429
  if (maskExpression[cursor] === 'd') {
414
430
  const maskStartWithMonth = maskExpression.slice(0, 2) === 'M0';
415
431
  const startWithMonthInput = maskExpression.slice(0, 2) === 'M0' &&
416
- (inputValue[cursor - 2] === '/' ||
417
- inputValue[cursor - 2] === '.' ||
418
- inputValue[cursor - 2] === '-');
432
+ this.specialCharacters.includes(inputValueCursorMinusTwo);
419
433
  if ((Number(inputSymbol) > 3 && this.leadZeroDateTime) ||
420
434
  (!maskStartWithMonth &&
421
- (Number(inputValue.slice(cursor, cursor + 2)) > daysCount ||
422
- Number(inputValue.slice(cursor - 1, cursor + 1)) > daysCount ||
423
- inputValue[cursor + 1] === '/' ||
424
- inputValue[cursor + 1] === '-')) ||
435
+ (Number(inputValueSliceCursorPlusTwo) > daysCount ||
436
+ Number(inputValueSliceMinusOnePlusOne) > daysCount ||
437
+ this.specialCharacters.includes(inputValueCursorPlusOne))) ||
425
438
  (startWithMonthInput
426
- ? Number(inputValue.slice(cursor - 1, cursor + 1)) > daysCount ||
427
- (inputValue[cursor] !== '/' &&
428
- (inputValue[cursor + 2] === '.' ||
429
- inputValue[cursor + 2] === '/' ||
430
- inputValue[cursor + 2] === '-')) ||
431
- inputValue[cursor] === '.' ||
432
- inputValue[cursor] === '/' ||
433
- inputValue[cursor] === '-'
434
- : Number(inputValue.slice(cursor, cursor + 2)) > daysCount ||
435
- inputValue[cursor + 1] === '/' ||
436
- inputValue[cursor + 1] === '-' ||
437
- inputValue[cursor + 1] === '.')) {
439
+ ? Number(inputValueSliceMinusOnePlusOne) > daysCount ||
440
+ (!this.specialCharacters.includes(inputValueCursor) &&
441
+ this.specialCharacters.includes(inputValueCursorPlusTwo)) ||
442
+ this.specialCharacters.includes(inputValueCursor)
443
+ : Number(inputValueSliceCursorPlusTwo) > daysCount ||
444
+ this.specialCharacters.includes(inputValueCursorPlusOne))) {
438
445
  // eslint-disable-next-line no-param-reassign
439
446
  position = position + 1;
440
447
  cursor += 1;
@@ -451,43 +458,39 @@ class NgxMaskApplierService {
451
458
  // mask without day
452
459
  const withoutDays = cursor === 0 &&
453
460
  (Number(inputSymbol) > 2 ||
454
- Number(inputValue.slice(cursor, cursor + 2)) > monthsCount ||
455
- inputValue[cursor + 1] === '/');
461
+ Number(inputValueSliceCursorPlusTwo) > monthsCount ||
462
+ this.specialCharacters.includes(inputValueCursorPlusOne));
456
463
  // day<10 && month<12 for input
457
- const day1monthInput = inputValue.slice(cursor - 3, cursor - 1).includes('/') &&
458
- ((inputValue[cursor - 2] === '/' &&
459
- Number(inputValue.slice(cursor - 1, cursor + 1)) > monthsCount &&
460
- inputValue[cursor] !== '/') ||
461
- inputValue[cursor] === '/' ||
462
- inputValue[cursor] === '-' ||
463
- (inputValue[cursor - 3] === '/' &&
464
- Number(inputValue.slice(cursor - 2, cursor)) > monthsCount &&
465
- inputValue[cursor - 1] !== '/') ||
466
- inputValue[cursor - 1] === '/' ||
467
- inputValue[cursor - 1] === '-');
464
+ const specialChart = maskExpression.slice(cursor + 2, cursor + 3);
465
+ const day1monthInput = inputValueSliceMinusThreeMinusOne.includes(specialChart) &&
466
+ ((this.specialCharacters.includes(inputValueCursorMinusTwo) &&
467
+ Number(inputValueSliceMinusOnePlusOne) > monthsCount &&
468
+ !this.specialCharacters.includes(inputValueCursor)) ||
469
+ this.specialCharacters.includes(inputValueCursor) ||
470
+ (this.specialCharacters.includes(inputValueCursorMinusThree) &&
471
+ Number(inputValueSliceMinusTwoCursor) > monthsCount &&
472
+ !this.specialCharacters.includes(inputValueCursorMinusOne)) ||
473
+ this.specialCharacters.includes(inputValueCursorMinusOne));
468
474
  // month<12 && day<10 for input
469
- const day2monthInput = Number(inputValue.slice(cursor - 3, cursor - 1)) <= daysCount &&
470
- !inputValue.slice(cursor - 3, cursor - 1).includes('/') &&
471
- (inputValue[cursor - 1] === '/' || inputValue[cursor - 1] === '-') &&
472
- (Number(inputValue.slice(cursor, cursor + 2)) > monthsCount ||
473
- inputValue[cursor + 1] === '/' ||
474
- inputValue[cursor + 1] === '-');
475
+ const day2monthInput = Number(inputValueSliceMinusThreeMinusOne) <= daysCount &&
476
+ !this.specialCharacters.includes(inputValueSliceMinusThreeMinusOne) &&
477
+ this.specialCharacters.includes(inputValueCursorMinusOne) &&
478
+ (Number(inputValueSliceCursorPlusTwo) > monthsCount ||
479
+ this.specialCharacters.includes(inputValueCursorPlusOne));
475
480
  // cursor === 5 && without days
476
- const day2monthInputDot = (Number(inputValue.slice(cursor, cursor + 2)) > monthsCount &&
477
- cursor === 5) ||
478
- inputValue[cursor + 1] === '.' ||
479
- inputValue[cursor + 1] === '-' ||
480
- inputValue[cursor + 1] === '/';
481
- // day<10 && month<12 for paste whole data
482
- const day1monthPaste = Number(inputValue.slice(cursor - 3, cursor - 1)) > daysCount &&
483
- !inputValue.slice(cursor - 3, cursor - 1).includes('/') &&
484
- !inputValue.slice(cursor - 2, cursor).includes('/') &&
485
- Number(inputValue.slice(cursor - 2, cursor)) > monthsCount;
481
+ const day2monthInputDot = (Number(inputValueSliceCursorPlusTwo) > monthsCount && cursor === 5) ||
482
+ (this.specialCharacters.includes(inputValueCursorPlusOne) &&
483
+ cursor === 5);
484
+ // // day<10 && month<12 for paste whole data
485
+ const day1monthPaste = Number(inputValueSliceMinusThreeMinusOne) > daysCount &&
486
+ !this.specialCharacters.includes(inputValueSliceMinusThreeMinusOne) &&
487
+ !this.specialCharacters.includes(inputValueSliceMinusTwoCursor) &&
488
+ Number(inputValueSliceMinusTwoCursor) > monthsCount;
486
489
  // 10<day<31 && month<12 for paste whole data
487
- const day2monthPaste = Number(inputValue.slice(cursor - 3, cursor - 1)) <= daysCount &&
488
- !inputValue.slice(cursor - 3, cursor - 1).includes('/') &&
489
- inputValue[cursor - 1] !== '/' &&
490
- Number(inputValue.slice(cursor - 1, cursor + 1)) > monthsCount;
490
+ const day2monthPaste = Number(inputValueSliceMinusThreeMinusOne) <= daysCount &&
491
+ !this.specialCharacters.includes(inputValueSliceMinusThreeMinusOne) &&
492
+ !this.specialCharacters.includes(inputValueCursorMinusOne) &&
493
+ Number(inputValueSliceMinusOnePlusOne) > monthsCount;
491
494
  if ((Number(inputSymbol) > 1 && this.leadZeroDateTime) ||
492
495
  withoutDays ||
493
496
  day1monthInput ||