Spaces:
Sleeping
Sleeping
Download src/utils/formatters.py from hashir-qt/keyvault-api: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/hashir-qt/keyvault-api/resolve/main/src/utils/formatters.py
- Command line
-
hf download hf://spaces/hashir-qt/keyvault-api/src/utils/formatters.py
-
curl -L -o formatters.py https://huggingface.co/spaces/hashir-qt/keyvault-api/resolve/main/src/utils/formatters.py
1.11 kB
| from datetime import datetime | |
| def format_pkr(amount: int) -> str: | |
| """Format an integer amount as Pakistani Rupees.""" | |
| return f"Rs. {amount:,}" | |
| def format_usd(amount: float) -> str: | |
| """Format a float amount as US Dollars.""" | |
| return f"${amount:,.2f}" | |
| def format_price_display(amount: float, currency: str = "USD") -> str: | |
| """Format price for display with the given currency code.""" | |
| if currency == "PKR": | |
| return format_pkr(int(amount)) | |
| if currency == "USD": | |
| return format_usd(amount) | |
| return f"{currency} {amount:,.2f}" | |
| def format_date(dt: datetime) -> str: | |
| """Format a datetime to a human-readable string.""" | |
| return dt.strftime("%B %d, %Y at %I:%M %p") | |
| def format_date_short(dt: datetime) -> str: | |
| """Format a datetime to a short date string.""" | |
| return dt.strftime("%b %d, %Y") | |
| def truncate_text(text: str, max_length: int = 100) -> str: | |
| """Truncate text to max_length and append ellipsis if needed.""" | |
| if len(text) <= max_length: | |
| return text | |
| return text[: max_length - 3] + "..." | |