Skip to content

Commit

Permalink
refactor: made the corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Belokopytov committed Nov 28, 2024
1 parent b8ec49e commit 5c861bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
};
}
23 changes: 11 additions & 12 deletions projects/kit/src/lib/utils/extract-affixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

0 comments on commit 5c861bd

Please sign in to comment.