diff --git a/projects/core/src/lib/classes/mask-model/utils/guess-valid-value-by-reg-exp.ts b/projects/core/src/lib/classes/mask-model/utils/guess-valid-value-by-reg-exp.ts index 356374458..845bd7432 100644 --- a/projects/core/src/lib/classes/mask-model/utils/guess-valid-value-by-reg-exp.ts +++ b/projects/core/src/lib/classes/mask-model/utils/guess-valid-value-by-reg-exp.ts @@ -22,13 +22,11 @@ export function guessValidValueByRegExp( return newPossibleValue.match(maskRegExp) ? newPossibleValue : validatedValuePart; }, ''); - if (newFrom > validatedValue.length) { - newFrom = validatedValue.length; - } - - if (newTo > validatedValue.length) { - newTo = validatedValue.length; - } - - return {value: validatedValue, selection: [newFrom, newTo]}; + return { + value: validatedValue, + selection: [ + Math.min(newFrom, validatedValue.length), + Math.min(newTo, validatedValue.length), + ], + }; } diff --git a/projects/kit/src/lib/utils/extract-affixes.ts b/projects/kit/src/lib/utils/extract-affixes.ts index af3569ec1..86f03c919 100644 --- a/projects/kit/src/lib/utils/extract-affixes.ts +++ b/projects/kit/src/lib/utils/extract-affixes.ts @@ -14,16 +14,15 @@ export function extractAffixes( const [extractedPrefix = ''] = value.match(prefixRegExp) ?? []; const [extractedPostfix = ''] = value.match(postfixRegExp) ?? []; - if (extractedPrefix || extractedPostfix) { - return { - extractedPrefix, - extractedPostfix, - cleanValue: value.slice( - extractedPrefix.length, - extractedPostfix.length ? -extractedPostfix.length : Infinity, - ), - }; - } - - return {extractedPrefix, extractedPostfix, cleanValue: value}; + return { + extractedPrefix, + extractedPostfix, + cleanValue: + extractedPrefix || extractedPostfix + ? value.slice( + extractedPrefix.length, + extractedPostfix.length ? -extractedPostfix.length : Infinity, + ) + : value, + }; }