-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilities.js
More file actions
34 lines (31 loc) · 1002 Bytes
/
Copy pathutilities.js
File metadata and controls
34 lines (31 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Common utility functions for Future Me site
*/
// Debounce function for performance optimization
function debounce(func, wait, immediate) {
let timeout;
return function() {
const context = this, args = arguments;
const later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
}
// Generate a random number between min and max
function randomBetween(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
// Format currency based on locale and currency
function formatCurrency(amount, currency = 'GBP', locale = 'en-GB') {
return new Intl.NumberFormat(locale, {
style: 'currency',
currency: currency,
minimumFractionDigits: 0,
maximumFractionDigits: 0
}).format(amount);
}