mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-21 15:36:50 -05:00
[AI] Normalize apostrophe-dot thousandsSeparator for consistency (#7179)
* Normalize apostrophe-dot thousandsSeparator for consistency * Also normalize keyboard apostrophes on the input path
This commit is contained in:
@@ -220,12 +220,15 @@ export function reapplyThousandSeparators(amountText: string) {
|
||||
return amountText;
|
||||
}
|
||||
|
||||
const { decimalSeparator, thousandsSeparator } = getNumberFormat();
|
||||
const { decimalSeparator, thousandsSeparator, value } = getNumberFormat();
|
||||
const [integerPartRaw, decimalPart = ''] = amountText.split(decimalSeparator);
|
||||
|
||||
const numericValue = Number(
|
||||
integerPartRaw.replaceAll(thousandsSeparator, ''),
|
||||
);
|
||||
// Apostrophe-dot: accept both U+2019 and keyboard U+0027 on input (see getNumberFormat formatter)
|
||||
const stripThousands =
|
||||
value === 'apostrophe-dot'
|
||||
? (s: string) => s.replaceAll(/[\u2019\u0027]/g, '')
|
||||
: (s: string) => s.replaceAll(thousandsSeparator, '');
|
||||
const numericValue = Number(stripThousands(integerPartRaw));
|
||||
if (isNaN(numericValue)) {
|
||||
return amountText; // Return original if parsing fails
|
||||
}
|
||||
@@ -342,7 +345,7 @@ export function getNumberFormat({
|
||||
break;
|
||||
case 'apostrophe-dot':
|
||||
locale = 'de-CH';
|
||||
thousandsSeparator = "'";
|
||||
thousandsSeparator = '\u2019'; // Intl may return U+0027 (Node <24.13.1/ICU 77)
|
||||
decimalSeparator = '.';
|
||||
break;
|
||||
case 'comma-dot-in':
|
||||
@@ -374,9 +377,14 @@ export function getNumberFormat({
|
||||
const intlFormatter = new Intl.NumberFormat(locale, fractionDigitsOptions);
|
||||
|
||||
// Wrapper to handle -0 edge case
|
||||
// Normalize apostrophe-dot to U+2019 for consistency across
|
||||
// Node/ICU versions (https://github.com/nodejs/node/issues/61861)
|
||||
const formatter = {
|
||||
format: (value: number) => {
|
||||
const formatted = intlFormatter.format(value);
|
||||
let formatted = intlFormatter.format(value);
|
||||
if (currentFormat === 'apostrophe-dot') {
|
||||
formatted = formatted.replace(/'/g, '\u2019');
|
||||
}
|
||||
return formatted === '-0' ? '0' : formatted;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user