Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit ede925d

Browse files
committed
add: utils for date and price format
1 parent 1e690b6 commit ede925d

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/utils/dateUtils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const formatDate = (dateString: string): string => {
2+
if (!dateString) return 'Invalid Date';
3+
4+
const date = new Date(dateString);
5+
if (isNaN(date.getTime())) return 'Invalid Date';
6+
7+
return date.toLocaleDateString('en-US', {
8+
year: 'numeric',
9+
month: 'long',
10+
day: 'numeric',
11+
});
12+
};

src/utils/priceUtils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Formats a number into a price string with commas as thousand separators.
3+
* @param value - The number to format.
4+
* @returns The formatted price string.
5+
*/
6+
export const formatPrice = (value: number): string => {
7+
return value.toLocaleString('en-US', {
8+
minimumFractionDigits: 2,
9+
maximumFractionDigits: 2,
10+
});
11+
};

0 commit comments

Comments
 (0)