From c6f9f427e9f7f88cae4cb78669d38081a68c6106 Mon Sep 17 00:00:00 2001 From: Nikita Barsukov Date: Mon, 4 Mar 2024 12:10:30 +0300 Subject: [PATCH] fix(kit): `maskitoParseNumber` should interpret japanese prolonged sound mark as pseudo minus --- .../kit/src/lib/masks/number/utils/parse-number.ts | 12 ++++++++++-- .../masks/number/utils/tests/parse-number.spec.ts | 12 +++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/projects/kit/src/lib/masks/number/utils/parse-number.ts b/projects/kit/src/lib/masks/number/utils/parse-number.ts index aa8682be6..0b5f4eb90 100644 --- a/projects/kit/src/lib/masks/number/utils/parse-number.ts +++ b/projects/kit/src/lib/masks/number/utils/parse-number.ts @@ -1,9 +1,17 @@ -import {CHAR_EM_DASH, CHAR_EN_DASH, CHAR_HYPHEN, CHAR_MINUS} from '../../../constants'; +import { + CHAR_EM_DASH, + CHAR_EN_DASH, + CHAR_HYPHEN, + CHAR_JP_HYPHEN, + CHAR_MINUS, +} from '../../../constants'; import {escapeRegExp} from '../../../utils'; export function maskitoParseNumber(maskedNumber: string, decimalSeparator = '.'): number { const hasNegativeSign = !!maskedNumber.match( - new RegExp(`^\\D*[${CHAR_MINUS}\\${CHAR_HYPHEN}${CHAR_EN_DASH}${CHAR_EM_DASH}]`), + new RegExp( + `^\\D*[${CHAR_MINUS}\\${CHAR_HYPHEN}${CHAR_EN_DASH}${CHAR_EM_DASH}${CHAR_JP_HYPHEN}]`, + ), ); const escapedDecimalSeparator = escapeRegExp(decimalSeparator); diff --git a/projects/kit/src/lib/masks/number/utils/tests/parse-number.spec.ts b/projects/kit/src/lib/masks/number/utils/tests/parse-number.spec.ts index 9413efc50..aa1368243 100644 --- a/projects/kit/src/lib/masks/number/utils/tests/parse-number.spec.ts +++ b/projects/kit/src/lib/masks/number/utils/tests/parse-number.spec.ts @@ -1,4 +1,10 @@ -import {CHAR_EM_DASH, CHAR_EN_DASH, CHAR_HYPHEN, CHAR_MINUS} from '../../../../constants'; +import { + CHAR_EM_DASH, + CHAR_EN_DASH, + CHAR_HYPHEN, + CHAR_JP_HYPHEN, + CHAR_MINUS, +} from '../../../../constants'; import {maskitoParseNumber} from '../parse-number'; describe('maskitoParseNumber', () => { @@ -63,6 +69,10 @@ describe('maskitoParseNumber', () => { it('can be em-dash', () => { expect(maskitoParseNumber(`${CHAR_EM_DASH}42`)).toBe(-42); }); + + it('can be katakana-hiragana prolonged sound mark', () => { + expect(maskitoParseNumber(`${CHAR_JP_HYPHEN}42`)).toBe(-42); + }); }); it('parses negative integer number when thousand separator is hyphen & minus sign is hyphen', () => {