@maskito/kit
Advanced tools
Comparing version 1.8.0 to 1.8.1
@@ -359,2 +359,37 @@ import { MASKITO_DEFAULT_OPTIONS, maskitoTransform } from '@maskito/core'; | ||
function normalizeDatePreprocessor({ | ||
dateModeTemplate, | ||
dateSegmentsSeparator, | ||
rangeSeparator = '' | ||
}) { | ||
return ({ | ||
elementState, | ||
data | ||
}) => { | ||
const separator = rangeSeparator ? new RegExp(`${rangeSeparator}|-`) : DATE_TIME_SEPARATOR; | ||
const possibleDates = data.split(separator); | ||
const dates = data.includes(DATE_TIME_SEPARATOR) ? [possibleDates[0]] : possibleDates; | ||
if (dates.every(date => date.trim().split(/\D/).length === dateModeTemplate.split(dateSegmentsSeparator).length)) { | ||
const newData = dates.map(date => normalizeDateString(date, dateModeTemplate, dateSegmentsSeparator)).join(rangeSeparator); | ||
return { | ||
elementState, | ||
data: `${newData}${data.includes(DATE_TIME_SEPARATOR) ? DATE_TIME_SEPARATOR + possibleDates[1] || '' : ''}` | ||
}; | ||
} | ||
return { | ||
elementState, | ||
data | ||
}; | ||
}; | ||
} | ||
function normalizeDateString(dateString, template, separator) { | ||
const dateSegments = dateString.split(/\D/); | ||
const templateSegments = template.split(separator); | ||
const normalizedSegments = dateSegments.map((segment, index) => index === templateSegments.length - 1 ? segment : segment.padStart(templateSegments[index].length, '0')); | ||
return normalizedSegments.join(separator); | ||
} | ||
function maskitoPostfixPostprocessorGenerator(postfix) { | ||
@@ -707,5 +742,8 @@ const postfixRE = new RegExp(`${escapeRegExp(postfix)}$`); | ||
overwriteMode: 'replace', | ||
preprocessors: [createZeroPlaceholdersPreprocessor(), createValidDatePreprocessor({ | ||
preprocessors: [createZeroPlaceholdersPreprocessor(), normalizeDatePreprocessor({ | ||
dateModeTemplate, | ||
dateSegmentsSeparator: separator | ||
}), createValidDatePreprocessor({ | ||
dateModeTemplate, | ||
dateSegmentsSeparator: separator | ||
})], | ||
@@ -807,6 +845,10 @@ postprocessors: [createMinMaxDatePostprocessor({ | ||
overwriteMode: 'replace', | ||
preprocessors: [createZeroPlaceholdersPreprocessor(), createValidDatePreprocessor({ | ||
preprocessors: [createZeroPlaceholdersPreprocessor(), normalizeDatePreprocessor({ | ||
dateModeTemplate, | ||
rangeSeparator, | ||
dateSegmentsSeparator: dateSeparator | ||
}), createValidDatePreprocessor({ | ||
dateModeTemplate, | ||
rangeSeparator, | ||
dateSegmentsSeparator: dateSeparator | ||
})], | ||
@@ -1063,5 +1105,8 @@ postprocessors: [createMinMaxDatePostprocessor({ | ||
overwriteMode: 'replace', | ||
preprocessors: [createZeroPlaceholdersPreprocessor(), createValidDateTimePreprocessor({ | ||
preprocessors: [createZeroPlaceholdersPreprocessor(), normalizeDatePreprocessor({ | ||
dateModeTemplate, | ||
dateSegmentsSeparator: dateSeparator | ||
}), createValidDateTimePreprocessor({ | ||
dateModeTemplate, | ||
dateSegmentsSeparator: dateSeparator | ||
})], | ||
@@ -1068,0 +1113,0 @@ postprocessors: [createMinMaxDateTimePostprocessor({ |
export { createMinMaxDatePostprocessor } from './min-max-date-postprocessor'; | ||
export { normalizeDatePreprocessor } from './normalize-date-preprocessor'; | ||
export { maskitoPostfixPostprocessorGenerator } from './postfix-postprocessor'; | ||
@@ -3,0 +4,0 @@ export { maskitoPrefixPostprocessorGenerator } from './prefix-postprocessor'; |
{ | ||
"name": "@maskito/kit", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"description": "The optional framework-agnostic Maskito's package with ready-to-use masks", | ||
@@ -33,3 +33,3 @@ "keywords": [ | ||
"peerDependencies": { | ||
"@maskito/core": "^1.8.0" | ||
"@maskito/core": "^1.8.1" | ||
}, | ||
@@ -36,0 +36,0 @@ "main": "./index.umd.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
197392
194
3927