Skip to content

Commit

Permalink
fix(kit): fix normalize to enter arbitrary value
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Belokopytov committed Oct 31, 2024
1 parent caf2f7e commit e3b42ac
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export function normalizeDatePreprocessor({
}): MaskitoPreprocessor {
return ({elementState, data}) => {
const dateSegments = data.split(/\D/).filter(Boolean);
const templateSegments = dateModeTemplate.split(dateSegmentsSeparator);
const templateSegments = dateModeTemplate
.split(dateSegmentsSeparator)
.filter(Boolean);
const includesTime = data.includes(dateTimeSeparator);

let newData = '';
Expand All @@ -26,7 +28,8 @@ export function normalizeDatePreprocessor({
for (let index = 0; index < dateSegments.length; index++) {
const segment = dateSegments[index]!;
const template = templateSegments[index % templateSegments.length];
const isLastSegment =
const isLastSegment = index === dateSegments.length - 1;
const isLastFromTemplate =
index % templateSegments.length === templateSegments.length - 1;

if (index >= templateSegments.length && includesTime) {
Expand All @@ -35,7 +38,7 @@ export function normalizeDatePreprocessor({
}

if (template) {
if (isLastSegment) {
if (isLastFromTemplate || isLastSegment) {
dateParts.push(segment);
dates.push(dateParts.join(dateSegmentsSeparator));
dateParts = [];
Expand Down

0 comments on commit e3b42ac

Please sign in to comment.