public
imalexnord
read
Slot
Calendar-first scheduling powered by Cloudflare Workers and Google Calendar.
Languages
Repository composition by tracked source files.
TypeScript
79%
CSS
19%
SQL
2%
HTML
0%
Create file
Wiki Documentation
Clone
https://nobgit.com/user/imalexnord/slot.git
ssh://[email protected]:2222/user/imalexnord/slot.git
Trace
worker/money.ts
Trace helps you understand code history line by line. See who changed each line, when it changed, and which commit introduced it.
Author
Date
Commit
Line
Code
1
const ZERO_DECIMAL_CURRENCIES = new Set([
2
'bif', 'clp', 'djf', 'gnf', 'jpy', 'kmf', 'krw', 'mga', 'pyg', 'rwf', 'ugx', 'vnd', 'vuv', 'xaf', 'xof', 'xpf',
3
]);
5
const THREE_DECIMAL_CURRENCIES = new Set(['bhd', 'jod', 'kwd', 'omr', 'tnd']);
7
export function currencyMinorUnitDigits(currency: string): number {
8
const normalized = currency.trim().toLowerCase();
9
if (ZERO_DECIMAL_CURRENCIES.has(normalized)) return 0;
10
if (THREE_DECIMAL_CURRENCIES.has(normalized)) return 3;
11
return 2;
12
}
14
export function majorToMinor(amountMajor: number, currency: string): number {
15
if (!Number.isFinite(amountMajor) || amountMajor < 0) return 0;
16
return Math.round(amountMajor * (10 ** currencyMinorUnitDigits(currency)));
17
}
19
export function minorToMajor(amountMinor: number, currency: string): number {
20
if (!Number.isFinite(amountMinor)) return 0;
21
return amountMinor / (10 ** currencyMinorUnitDigits(currency));
22
}
24
export function bookingAmountMinor(ratePerMinute: number, durationMinutes: number, currency: string): number {
25
return majorToMinor(ratePerMinute * durationMinutes, currency);
26
}