From de45c3295d0f23cfe31af11864998fbafaec092e Mon Sep 17 00:00:00 2001 From: Soshi Homma Date: Sun, 7 Jan 2024 12:24:31 +0900 Subject: [PATCH] fix: move hyphen replacement to correct place, fix e2e test --- .../kit/src/lib/constants/unicode-characters.ts | 6 ++++++ projects/kit/src/lib/masks/number/number-mask.ts | 3 ++- ...create-fullwidth-to-halfwidth-preprocessor.ts | 16 ++++++---------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/projects/kit/src/lib/constants/unicode-characters.ts b/projects/kit/src/lib/constants/unicode-characters.ts index 2ecc724e2..d18f6eb3d 100644 --- a/projects/kit/src/lib/constants/unicode-characters.ts +++ b/projects/kit/src/lib/constants/unicode-characters.ts @@ -35,3 +35,9 @@ export const CHAR_HYPHEN = '\u002D'; * Can be used as `−`. Don't confuse with {@link CHAR_HYPHEN} */ export const CHAR_MINUS = '\u2212'; + +/** + * {@link https://symbl.cc/en/30FC/ Katakana-Hiragana Prolonged Sound Mark} + * is used as prolonged sounds in Japanese. + */ +export const CHAR_JP_HYPEN = '\u30FC'; diff --git a/projects/kit/src/lib/masks/number/number-mask.ts b/projects/kit/src/lib/masks/number/number-mask.ts index c9016759b..9c62b273a 100644 --- a/projects/kit/src/lib/masks/number/number-mask.ts +++ b/projects/kit/src/lib/masks/number/number-mask.ts @@ -4,6 +4,7 @@ import { CHAR_EM_DASH, CHAR_EN_DASH, CHAR_HYPHEN, + CHAR_JP_HYPEN, CHAR_MINUS, CHAR_NO_BREAK_SPACE, } from '../../constants'; @@ -51,7 +52,7 @@ export function maskitoNumberOptionsGenerator({ prefix?: string; postfix?: string; } = {}): Required { - const pseudoMinuses = [CHAR_HYPHEN, CHAR_EN_DASH, CHAR_EM_DASH].filter( + const pseudoMinuses = [CHAR_HYPHEN, CHAR_EN_DASH, CHAR_EM_DASH, CHAR_JP_HYPEN].filter( char => char !== thousandSeparator && char !== decimalSeparator, ); const validatedDecimalPseudoSeparators = validateDecimalPseudoSeparators({ diff --git a/projects/kit/src/lib/masks/number/processors/create-fullwidth-to-halfwidth-preprocessor.ts b/projects/kit/src/lib/masks/number/processors/create-fullwidth-to-halfwidth-preprocessor.ts index 554d115df..f2036bdac 100644 --- a/projects/kit/src/lib/masks/number/processors/create-fullwidth-to-halfwidth-preprocessor.ts +++ b/projects/kit/src/lib/masks/number/processors/create-fullwidth-to-halfwidth-preprocessor.ts @@ -1,7 +1,5 @@ import {MaskitoPreprocessor} from '@maskito/core'; -import {CHAR_MINUS} from '../../../constants'; - /** * Convert full width numbers like 1, 2 to half width numbers 1, 2 * @@ -14,15 +12,13 @@ export function createFullWidthToHalfWidthPreprocessor(): MaskitoPreprocessor { return { elementState: { selection, - value: value - .replace(/[0-9]/g, s => - String.fromCharCode(s.charCodeAt(0) - 0xfee0), - ) - .replace(/[--﹣−‐⁃‑‒–—﹘―⎯⏤ーー─━]/g, CHAR_MINUS), + value: value.replace(/[0-9]/g, s => + String.fromCharCode(s.charCodeAt(0) - 0xfee0), + ), }, - data: data - .replace(/[0-9]/g, s => String.fromCharCode(s.charCodeAt(0) - 0xfee0)) - .replace(/[--﹣−‐⁃‑‒–—﹘―⎯⏤ーー─━]/g, CHAR_MINUS), + data: data.replace(/[0-9]/g, s => + String.fromCharCode(s.charCodeAt(0) - 0xfee0), + ), }; }; }