mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-09 11:42:54 -05:00
Compare commits
1 Commits
feat/plugi
...
stable
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65c0a5a316 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@actual-app/api",
|
||||
"version": "25.3.0",
|
||||
"version": "25.3.1",
|
||||
"license": "MIT",
|
||||
"description": "An API for Actual",
|
||||
"engines": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@actual-app/web",
|
||||
"version": "25.3.0",
|
||||
"version": "25.3.1",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"build"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"author": "Actual",
|
||||
"productName": "Actual",
|
||||
"description": "A simple and powerful personal finance system",
|
||||
"version": "25.3.0",
|
||||
"version": "25.3.1",
|
||||
"scripts": {
|
||||
"clean": "rm -rf dist",
|
||||
"update-client": "bin/update-client",
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { looselyParseAmount, getNumberFormat, setNumberFormat } from './util';
|
||||
import {
|
||||
looselyParseAmount,
|
||||
getNumberFormat,
|
||||
setNumberFormat,
|
||||
currencyToAmount,
|
||||
} from './util';
|
||||
|
||||
describe('utility functions', () => {
|
||||
test('looseParseAmount works with basic numbers', () => {
|
||||
@@ -108,4 +113,63 @@ describe('utility functions', () => {
|
||||
formatter = getNumberFormat().formatter;
|
||||
expect(formatter.format(Number('1234.56'))).toBe('1’235');
|
||||
});
|
||||
|
||||
test('currencyToAmount works with basic numbers', () => {
|
||||
expect(currencyToAmount('3')).toBe(3);
|
||||
expect(currencyToAmount('3.4')).toBe(3.4);
|
||||
expect(currencyToAmount('3.45')).toBe(3.45);
|
||||
expect(currencyToAmount('3.45060')).toBe(3.4506);
|
||||
});
|
||||
|
||||
test('currencyToAmount works with varied formats', () => {
|
||||
setNumberFormat({ format: 'comma-dot', hideFraction: true });
|
||||
expect(currencyToAmount('3,45')).toBe(3.45);
|
||||
expect(currencyToAmount('3,456')).toBe(3456);
|
||||
expect(currencyToAmount('3,45000')).toBe(345000);
|
||||
expect(currencyToAmount("3'456.78")).toBe(3456.78);
|
||||
expect(currencyToAmount("3'456.78000")).toBe(3456.78);
|
||||
expect(currencyToAmount('1,00,000.99')).toBe(100000.99);
|
||||
expect(currencyToAmount('1,00,000.99000')).toBe(100000.99);
|
||||
});
|
||||
|
||||
test('currencyToAmount works with leading decimal characters', () => {
|
||||
expect(currencyToAmount('.45')).toBe(0.45);
|
||||
expect(currencyToAmount(',45')).toBe(0.45);
|
||||
});
|
||||
|
||||
test('currencyToAmount works with negative numbers', () => {
|
||||
expect(currencyToAmount('-3')).toBe(-3);
|
||||
expect(currencyToAmount('-3.45')).toBe(-3.45);
|
||||
expect(currencyToAmount('-3,45')).toBe(-3.45);
|
||||
});
|
||||
|
||||
test('currencyToAmount works with non-fractional numbers', () => {
|
||||
setNumberFormat({ format: 'comma-dot', hideFraction: false });
|
||||
expect(currencyToAmount('3.')).toBe(3);
|
||||
expect(currencyToAmount('3,')).toBe(3);
|
||||
expect(currencyToAmount('3,000')).toBe(3000);
|
||||
expect(currencyToAmount('3,000.')).toBe(3000);
|
||||
});
|
||||
|
||||
test('currencyToAmount works with hidden fractions', () => {
|
||||
setNumberFormat({ format: 'comma-dot', hideFraction: true });
|
||||
expect(currencyToAmount('3.45')).toBe(3.45);
|
||||
expect(currencyToAmount('3.456')).toBe(3.456);
|
||||
expect(currencyToAmount('3.4500')).toBe(3.45);
|
||||
expect(currencyToAmount('3.')).toBe(3);
|
||||
expect(currencyToAmount('3,')).toBe(3);
|
||||
expect(currencyToAmount('3,000')).toBe(3000);
|
||||
expect(currencyToAmount('3,000.')).toBe(3000);
|
||||
});
|
||||
|
||||
test('currencyToAmount works with dot-comma', () => {
|
||||
setNumberFormat({ format: 'dot-comma', hideFraction: false });
|
||||
expect(currencyToAmount('3,45')).toBe(3.45);
|
||||
expect(currencyToAmount('3,456')).toBe(3.456);
|
||||
expect(currencyToAmount('3,4500')).toBe(3.45);
|
||||
expect(currencyToAmount('3,')).toBe(3);
|
||||
expect(currencyToAmount('3.')).toBe(3);
|
||||
expect(currencyToAmount('3.000')).toBe(3000);
|
||||
expect(currencyToAmount('3.000,')).toBe(3000);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -396,12 +396,12 @@ export function currencyToAmount(currencyAmount: string): Amount | null {
|
||||
if (
|
||||
!match ||
|
||||
(match[0] === getNumberFormat().thousandsSeparator &&
|
||||
match.index + 4 === currencyAmount.length)
|
||||
match.index + 4 <= currencyAmount.length)
|
||||
) {
|
||||
fraction = null;
|
||||
integer = currencyAmount.replace(/\D/g, '');
|
||||
integer = currencyAmount.replace(/[^\d-]/g, '');
|
||||
} else {
|
||||
integer = currencyAmount.slice(0, match.index).replace(/\D/g, '');
|
||||
integer = currencyAmount.slice(0, match.index).replace(/[^\d-]/g, '');
|
||||
fraction = currencyAmount.slice(match.index + 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@actual-app/sync-server",
|
||||
"version": "25.3.0",
|
||||
"version": "25.3.1",
|
||||
"license": "MIT",
|
||||
"description": "actual syncing server",
|
||||
"type": "module",
|
||||
@@ -24,7 +24,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@actual-app/crdt": "2.1.0",
|
||||
"@actual-app/web": "25.3.0",
|
||||
"@actual-app/web": "25.3.1",
|
||||
"bcrypt": "^5.1.1",
|
||||
"better-sqlite3": "^11.7.0",
|
||||
"body-parser": "^1.20.3",
|
||||
|
||||
10
yarn.lock
10
yarn.lock
@@ -84,7 +84,7 @@ __metadata:
|
||||
resolution: "@actual-app/sync-server@workspace:packages/sync-server"
|
||||
dependencies:
|
||||
"@actual-app/crdt": "npm:2.1.0"
|
||||
"@actual-app/web": "npm:25.3.0"
|
||||
"@actual-app/web": "npm:25.3.1"
|
||||
"@babel/preset-typescript": "npm:^7.20.2"
|
||||
"@types/bcrypt": "npm:^5.0.2"
|
||||
"@types/better-sqlite3": "npm:^7.6.12"
|
||||
@@ -125,10 +125,10 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@actual-app/web@npm:25.3.0":
|
||||
version: 25.3.0
|
||||
resolution: "@actual-app/web@npm:25.3.0"
|
||||
checksum: 10/cd63ec1b8ffe1a8e6b8339ee475633bf9c0f04223338f64ca2594c3dee66918b79a0c4ce24c8388abc5b9b9141654cc694a372f0b42126fada3504041c98ccb0
|
||||
"@actual-app/web@npm:25.3.1":
|
||||
version: 25.3.1
|
||||
resolution: "@actual-app/web@npm:25.3.1"
|
||||
checksum: 10/a582c288b6ee5414dc0b8bf6bc10c585bd5ddb3612a564142a4f44cf6a38bfd0cecc5cbcdc3781d8be6891fef12d588d4179e7e0582f53b751184d8aaba9e43b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Reference in New Issue
Block a user