Skip to content

Commit

Permalink
fix: move hyphen replacement to correct place, fix e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
rikusen0335 committed Jan 7, 2024
1 parent 0cbb6ce commit de45c32
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
6 changes: 6 additions & 0 deletions projects/kit/src/lib/constants/unicode-characters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
3 changes: 2 additions & 1 deletion projects/kit/src/lib/masks/number/number-mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
CHAR_EM_DASH,
CHAR_EN_DASH,
CHAR_HYPHEN,
CHAR_JP_HYPEN,
CHAR_MINUS,
CHAR_NO_BREAK_SPACE,
} from '../../constants';
Expand Down Expand Up @@ -51,7 +52,7 @@ export function maskitoNumberOptionsGenerator({
prefix?: string;
postfix?: string;
} = {}): Required<MaskitoOptions> {
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({
Expand Down
Original file line number Diff line number Diff line change
@@ -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
*
Expand All @@ -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),
),
};
};
}

0 comments on commit de45c32

Please sign in to comment.