Skip to content

Commit 65c0a5a

Browse files
jfdomingmatt-fiddgithub-actions[bot]
authored
🔖 (25.3.1) (#4497)
* fix negative amount parsing (#4489) * fix negative amount parsing * note * Remove used release notes * Empty commit to bump ci * Fix number input on mobile with hidden decimals (#4503) * Fix number input on mobile with hidden decimals * Add release notes * Remove used release notes * Empty commit to bump ci * Bump non-server versions * Bump sync-server --------- Co-authored-by: Matt Fiddaman <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent b0deedb commit 65c0a5a

File tree

7 files changed

+78
-14
lines changed

7 files changed

+78
-14
lines changed

‎packages/api/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@actual-app/api",
3-
"version": "25.3.0",
3+
"version": "25.3.1",
44
"license": "MIT",
55
"description": "An API for Actual",
66
"engines": {

‎packages/desktop-client/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@actual-app/web",
3-
"version": "25.3.0",
3+
"version": "25.3.1",
44
"license": "MIT",
55
"files": [
66
"build"

‎packages/desktop-electron/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"author": "Actual",
44
"productName": "Actual",
55
"description": "A simple and powerful personal finance system",
6-
"version": "25.3.0",
6+
"version": "25.3.1",
77
"scripts": {
88
"clean": "rm -rf dist",
99
"update-client": "bin/update-client",

‎packages/loot-core/src/shared/util.test.ts

+65-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { looselyParseAmount, getNumberFormat, setNumberFormat } from './util';
1+
import {
2+
looselyParseAmount,
3+
getNumberFormat,
4+
setNumberFormat,
5+
currencyToAmount,
6+
} from './util';
27

38
describe('utility functions', () => {
49
test('looseParseAmount works with basic numbers', () => {
@@ -108,4 +113,63 @@ describe('utility functions', () => {
108113
formatter = getNumberFormat().formatter;
109114
expect(formatter.format(Number('1234.56'))).toBe('1’235');
110115
});
116+
117+
test('currencyToAmount works with basic numbers', () => {
118+
expect(currencyToAmount('3')).toBe(3);
119+
expect(currencyToAmount('3.4')).toBe(3.4);
120+
expect(currencyToAmount('3.45')).toBe(3.45);
121+
expect(currencyToAmount('3.45060')).toBe(3.4506);
122+
});
123+
124+
test('currencyToAmount works with varied formats', () => {
125+
setNumberFormat({ format: 'comma-dot', hideFraction: true });
126+
expect(currencyToAmount('3,45')).toBe(3.45);
127+
expect(currencyToAmount('3,456')).toBe(3456);
128+
expect(currencyToAmount('3,45000')).toBe(345000);
129+
expect(currencyToAmount("3'456.78")).toBe(3456.78);
130+
expect(currencyToAmount("3'456.78000")).toBe(3456.78);
131+
expect(currencyToAmount('1,00,000.99')).toBe(100000.99);
132+
expect(currencyToAmount('1,00,000.99000')).toBe(100000.99);
133+
});
134+
135+
test('currencyToAmount works with leading decimal characters', () => {
136+
expect(currencyToAmount('.45')).toBe(0.45);
137+
expect(currencyToAmount(',45')).toBe(0.45);
138+
});
139+
140+
test('currencyToAmount works with negative numbers', () => {
141+
expect(currencyToAmount('-3')).toBe(-3);
142+
expect(currencyToAmount('-3.45')).toBe(-3.45);
143+
expect(currencyToAmount('-3,45')).toBe(-3.45);
144+
});
145+
146+
test('currencyToAmount works with non-fractional numbers', () => {
147+
setNumberFormat({ format: 'comma-dot', hideFraction: false });
148+
expect(currencyToAmount('3.')).toBe(3);
149+
expect(currencyToAmount('3,')).toBe(3);
150+
expect(currencyToAmount('3,000')).toBe(3000);
151+
expect(currencyToAmount('3,000.')).toBe(3000);
152+
});
153+
154+
test('currencyToAmount works with hidden fractions', () => {
155+
setNumberFormat({ format: 'comma-dot', hideFraction: true });
156+
expect(currencyToAmount('3.45')).toBe(3.45);
157+
expect(currencyToAmount('3.456')).toBe(3.456);
158+
expect(currencyToAmount('3.4500')).toBe(3.45);
159+
expect(currencyToAmount('3.')).toBe(3);
160+
expect(currencyToAmount('3,')).toBe(3);
161+
expect(currencyToAmount('3,000')).toBe(3000);
162+
expect(currencyToAmount('3,000.')).toBe(3000);
163+
});
164+
165+
test('currencyToAmount works with dot-comma', () => {
166+
setNumberFormat({ format: 'dot-comma', hideFraction: false });
167+
expect(currencyToAmount('3,45')).toBe(3.45);
168+
expect(currencyToAmount('3,456')).toBe(3.456);
169+
expect(currencyToAmount('3,4500')).toBe(3.45);
170+
expect(currencyToAmount('3,')).toBe(3);
171+
expect(currencyToAmount('3.')).toBe(3);
172+
expect(currencyToAmount('3.000')).toBe(3000);
173+
expect(currencyToAmount('3.000,')).toBe(3000);
174+
});
111175
});

‎packages/loot-core/src/shared/util.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,12 @@ export function currencyToAmount(currencyAmount: string): Amount | null {
396396
if (
397397
!match ||
398398
(match[0] === getNumberFormat().thousandsSeparator &&
399-
match.index + 4 === currencyAmount.length)
399+
match.index + 4 <= currencyAmount.length)
400400
) {
401401
fraction = null;
402-
integer = currencyAmount.replace(/\D/g, '');
402+
integer = currencyAmount.replace(/[^\d-]/g, '');
403403
} else {
404-
integer = currencyAmount.slice(0, match.index).replace(/\D/g, '');
404+
integer = currencyAmount.slice(0, match.index).replace(/[^\d-]/g, '');
405405
fraction = currencyAmount.slice(match.index + 1);
406406
}
407407

‎packages/sync-server/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@actual-app/sync-server",
3-
"version": "25.3.0",
3+
"version": "25.3.1",
44
"license": "MIT",
55
"description": "actual syncing server",
66
"type": "module",
@@ -24,7 +24,7 @@
2424
},
2525
"dependencies": {
2626
"@actual-app/crdt": "2.1.0",
27-
"@actual-app/web": "25.3.0",
27+
"@actual-app/web": "25.3.1",
2828
"bcrypt": "^5.1.1",
2929
"better-sqlite3": "^11.7.0",
3030
"body-parser": "^1.20.3",

‎yarn.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ __metadata:
8484
resolution: "@actual-app/sync-server@workspace:packages/sync-server"
8585
dependencies:
8686
"@actual-app/crdt": "npm:2.1.0"
87-
"@actual-app/web": "npm:25.3.0"
87+
"@actual-app/web": "npm:25.3.1"
8888
"@babel/preset-typescript": "npm:^7.20.2"
8989
"@types/bcrypt": "npm:^5.0.2"
9090
"@types/better-sqlite3": "npm:^7.6.12"
@@ -125,10 +125,10 @@ __metadata:
125125
languageName: unknown
126126
linkType: soft
127127

128-
"@actual-app/web@npm:25.3.0":
129-
version: 25.3.0
130-
resolution: "@actual-app/web@npm:25.3.0"
131-
checksum: 10/cd63ec1b8ffe1a8e6b8339ee475633bf9c0f04223338f64ca2594c3dee66918b79a0c4ce24c8388abc5b9b9141654cc694a372f0b42126fada3504041c98ccb0
128+
"@actual-app/web@npm:25.3.1":
129+
version: 25.3.1
130+
resolution: "@actual-app/web@npm:25.3.1"
131+
checksum: 10/a582c288b6ee5414dc0b8bf6bc10c585bd5ddb3612a564142a4f44cf6a38bfd0cecc5cbcdc3781d8be6891fef12d588d4179e7e0582f53b751184d8aaba9e43b
132132
languageName: node
133133
linkType: hard
134134

0 commit comments

Comments
 (0)