diff --git a/projects/kit/src/lib/masks/number/plugins/leading-zeroes-validation.plugin.ts b/projects/kit/src/lib/masks/number/plugins/leading-zeroes-validation.plugin.ts index 572072379..21dd2fcf9 100644 --- a/projects/kit/src/lib/masks/number/plugins/leading-zeroes-validation.plugin.ts +++ b/projects/kit/src/lib/masks/number/plugins/leading-zeroes-validation.plugin.ts @@ -2,7 +2,6 @@ import {MaskitoPlugin, maskitoUpdateElement} from '@maskito/core'; import {maskitoEventHandler} from '../../../plugins'; import {createLeadingZeroesValidationPostprocessor} from '../processors'; -import {extractAffixes} from '../utils/extract-affixes'; const DUMMY_SELECTION = [0, 0] as const; @@ -32,21 +31,13 @@ export function createLeadingZeroesValidationPlugin({ return maskitoEventHandler( 'blur', element => { - const {cleanValue, extractedPostfix, extractedPrefix} = extractAffixes( - element.value, - {prefix, postfix}, - ); - - const newValue = - extractedPrefix + - dropRepeatedLeadingZeroes( - { - value: cleanValue, - selection: DUMMY_SELECTION, - }, - {value: '', selection: DUMMY_SELECTION}, - ).value + - extractedPostfix; + const newValue = dropRepeatedLeadingZeroes( + { + value: element.value, + selection: DUMMY_SELECTION, + }, + {value: '', selection: DUMMY_SELECTION}, + ).value; if (element.value !== newValue) { maskitoUpdateElement(element, newValue); diff --git a/projects/kit/src/lib/masks/number/plugins/not-empty-integer.plugin.ts b/projects/kit/src/lib/masks/number/plugins/not-empty-integer.plugin.ts index 7f1222d59..a8a6870b0 100644 --- a/projects/kit/src/lib/masks/number/plugins/not-empty-integer.plugin.ts +++ b/projects/kit/src/lib/masks/number/plugins/not-empty-integer.plugin.ts @@ -1,8 +1,7 @@ import {MaskitoPlugin, maskitoUpdateElement} from '@maskito/core'; import {maskitoEventHandler} from '../../../plugins'; -import {escapeRegExp} from '../../../utils'; -import {extractAffixes} from '../utils/extract-affixes'; +import {escapeRegExp, extractAffixes} from '../../../utils'; /** * It pads EMPTY integer part with zero if decimal parts exists. diff --git a/projects/kit/src/lib/masks/number/processors/affixes-filter-preprocessor.ts b/projects/kit/src/lib/masks/number/processors/affixes-filter-preprocessor.ts index 9dba6d6e6..d1aec7aa7 100644 --- a/projects/kit/src/lib/masks/number/processors/affixes-filter-preprocessor.ts +++ b/projects/kit/src/lib/masks/number/processors/affixes-filter-preprocessor.ts @@ -1,6 +1,6 @@ import {MaskitoPreprocessor} from '@maskito/core'; -import {extractAffixes} from '../utils/extract-affixes'; +import {extractAffixes} from '../../../utils'; /** * It drops prefix and postfix from data diff --git a/projects/kit/src/lib/masks/number/processors/decimal-zero-padding-postprocessor.ts b/projects/kit/src/lib/masks/number/processors/decimal-zero-padding-postprocessor.ts index cafb0eb41..92e4053c5 100644 --- a/projects/kit/src/lib/masks/number/processors/decimal-zero-padding-postprocessor.ts +++ b/projects/kit/src/lib/masks/number/processors/decimal-zero-padding-postprocessor.ts @@ -1,8 +1,7 @@ import {MaskitoPostprocessor} from '@maskito/core'; -import {identity} from '../../../utils'; +import {extractAffixes, identity} from '../../../utils'; import {maskitoParseNumber} from '../utils'; -import {extractAffixes} from '../utils/extract-affixes'; /** * If `decimalZeroPadding` is `true`, it pads decimal part with zeroes diff --git a/projects/kit/src/lib/masks/number/processors/initialization-only-preprocessor.ts b/projects/kit/src/lib/masks/number/processors/initialization-only-preprocessor.ts index 58aafdd31..235bf3d58 100644 --- a/projects/kit/src/lib/masks/number/processors/initialization-only-preprocessor.ts +++ b/projects/kit/src/lib/masks/number/processors/initialization-only-preprocessor.ts @@ -1,7 +1,7 @@ import {MaskitoPreprocessor, maskitoTransform} from '@maskito/core'; +import {extractAffixes} from '../../../utils'; import {generateMaskExpression} from '../utils'; -import {extractAffixes} from '../utils/extract-affixes'; /** * This preprocessor works only once at initialization phase (when `new Maskito(...)` is executed). diff --git a/projects/kit/src/lib/masks/number/processors/leading-zeroes-validation-postprocessor.ts b/projects/kit/src/lib/masks/number/processors/leading-zeroes-validation-postprocessor.ts index 1d0082322..f0ded369c 100644 --- a/projects/kit/src/lib/masks/number/processors/leading-zeroes-validation-postprocessor.ts +++ b/projects/kit/src/lib/masks/number/processors/leading-zeroes-validation-postprocessor.ts @@ -1,7 +1,6 @@ import {MaskitoPostprocessor} from '@maskito/core'; -import {escapeRegExp} from '../../../utils'; -import {extractAffixes} from '../utils/extract-affixes'; +import {escapeRegExp, extractAffixes} from '../../../utils'; /** * It removes repeated leading zeroes for integer part. diff --git a/projects/kit/src/lib/masks/number/processors/pseudo-character-preprocessor.ts b/projects/kit/src/lib/masks/number/processors/pseudo-character-preprocessor.ts index 0ae37f1fa..52e25524c 100644 --- a/projects/kit/src/lib/masks/number/processors/pseudo-character-preprocessor.ts +++ b/projects/kit/src/lib/masks/number/processors/pseudo-character-preprocessor.ts @@ -1,6 +1,6 @@ import {MaskitoPreprocessor} from '@maskito/core'; -import {extractAffixes} from '../utils/extract-affixes'; +import {extractAffixes} from '../../../utils'; /** * It replaces pseudo characters with valid one. @@ -22,21 +22,18 @@ export function createPseudoCharactersPreprocessor({ return ({elementState, data}) => { const {value, selection} = elementState; - const {cleanValue, extractedPostfix, extractedPrefix} = extractAffixes(value, { prefix, postfix, }); - const newValue = - extractedPrefix + - cleanValue.replace(pseudoCharactersRegExp, validCharacter) + - extractedPostfix; - return { elementState: { selection, - value: newValue, + value: + extractedPrefix + + cleanValue.replace(pseudoCharactersRegExp, validCharacter) + + extractedPostfix, }, data: data.replace(pseudoCharactersRegExp, validCharacter), }; diff --git a/projects/kit/src/lib/masks/number/processors/repeated-decimal-separator-preprocessor.ts b/projects/kit/src/lib/masks/number/processors/repeated-decimal-separator-preprocessor.ts index 6cf4d08b5..e03d9b8f1 100644 --- a/projects/kit/src/lib/masks/number/processors/repeated-decimal-separator-preprocessor.ts +++ b/projects/kit/src/lib/masks/number/processors/repeated-decimal-separator-preprocessor.ts @@ -1,7 +1,6 @@ import {MaskitoPreprocessor} from '@maskito/core'; -import {escapeRegExp} from '../../../utils'; -import {extractAffixes} from '../utils/extract-affixes'; +import {escapeRegExp, extractAffixes} from '../../../utils'; /** * It rejects new typed decimal separator if it already exists in text field. @@ -19,7 +18,6 @@ export function createRepeatedDecimalSeparatorPreprocessor({ }): MaskitoPreprocessor { return ({elementState, data}) => { const {value, selection} = elementState; - const [from, to] = selection; const {cleanValue} = extractAffixes(value, {prefix, postfix}); diff --git a/projects/kit/src/lib/masks/number/processors/thousand-separator-postprocessor.ts b/projects/kit/src/lib/masks/number/processors/thousand-separator-postprocessor.ts index 4e217d7bd..64ba8c508 100644 --- a/projects/kit/src/lib/masks/number/processors/thousand-separator-postprocessor.ts +++ b/projects/kit/src/lib/masks/number/processors/thousand-separator-postprocessor.ts @@ -1,8 +1,7 @@ import {MaskitoPostprocessor} from '@maskito/core'; import {CHAR_MINUS} from '../../../constants'; -import {identity} from '../../../utils'; -import {extractAffixes} from '../utils/extract-affixes'; +import {extractAffixes, identity} from '../../../utils'; /** * It adds symbol for separating thousands. @@ -23,24 +22,17 @@ export function createThousandSeparatorPostprocessor({ return identity; } - const minusReg = new RegExp(`^${CHAR_MINUS}?`); const isAllSpaces = (...chars: string[]): boolean => chars.every(x => /\s/.test(x)); return ({value, selection}) => { - const { - cleanValue: cleanValueWithPossibleMinus, - extractedPostfix, - extractedPrefix, - } = extractAffixes(value, { + const {cleanValue, extractedPostfix, extractedPrefix} = extractAffixes(value, { prefix, postfix, }); - const [extractedMinus = ''] = cleanValueWithPossibleMinus.match(minusReg) || []; - - const cleanValue = cleanValueWithPossibleMinus.replace(minusReg, ''); - - const [integerPart, decimalPart = ''] = cleanValue.split(decimalSeparator); + const [integerPart, decimalPart = ''] = cleanValue + .replace(CHAR_MINUS, '') + .split(decimalSeparator); const [initialFrom, initialTo] = selection; let [from, to] = selection; @@ -91,7 +83,7 @@ export function createThousandSeparatorPostprocessor({ return { value: extractedPrefix + - extractedMinus + + (cleanValue.includes(CHAR_MINUS) ? CHAR_MINUS : '') + processedIntegerPart + (cleanValue.includes(decimalSeparator) ? decimalSeparator : '') + decimalPart + diff --git a/projects/kit/src/lib/masks/number/processors/zero-precision-preprocessor.ts b/projects/kit/src/lib/masks/number/processors/zero-precision-preprocessor.ts index 02ca110c0..cd767b8e9 100644 --- a/projects/kit/src/lib/masks/number/processors/zero-precision-preprocessor.ts +++ b/projects/kit/src/lib/masks/number/processors/zero-precision-preprocessor.ts @@ -1,7 +1,6 @@ import {MaskitoPreprocessor} from '@maskito/core'; -import {escapeRegExp, identity} from '../../../utils'; -import {extractAffixes} from '../utils/extract-affixes'; +import {escapeRegExp, extractAffixes, identity} from '../../../utils'; /** * It drops decimal part if precision is zero. diff --git a/projects/kit/src/lib/masks/number/utils/extract-affixes.ts b/projects/kit/src/lib/utils/extract-affixes.ts similarity index 93% rename from projects/kit/src/lib/masks/number/utils/extract-affixes.ts rename to projects/kit/src/lib/utils/extract-affixes.ts index ca22b11c4..f99b8295c 100644 --- a/projects/kit/src/lib/masks/number/utils/extract-affixes.ts +++ b/projects/kit/src/lib/utils/extract-affixes.ts @@ -1,4 +1,4 @@ -import {escapeRegExp} from '../../../utils'; +import {escapeRegExp} from '.'; export function extractAffixes( value: string, diff --git a/projects/kit/src/lib/utils/index.ts b/projects/kit/src/lib/utils/index.ts index 25994b95b..23a02ae52 100644 --- a/projects/kit/src/lib/utils/index.ts +++ b/projects/kit/src/lib/utils/index.ts @@ -9,6 +9,7 @@ export * from './date/segments-to-date'; export * from './date/to-date-string'; export * from './date/validate-date-string'; export * from './escape-reg-exp'; +export * from './extract-affixes'; export * from './find-common-beginning-substr'; export * from './get-focused'; export * from './identity';