Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kit): maskitoParseNumber should interpret japanese prolonged sound mark as pseudo minus #1115

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions projects/kit/src/lib/masks/number/utils/parse-number.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down
Loading