Utility Functions
Utility Functions
The lib/utils.ts file contains core helper functions used throughout the application to handle styling, data validation, and currency formatting.
cn
A utility for conditionally joining Tailwind CSS classes. It combines clsx for conditional logic and tw-merge to ensure the last class defined takes precedence in case of conflicts.
Parameters:
...inputs: A list of class names, objects, or arrays (usingClassValuetype).
Returns:
string: A merged string of CSS classes.
Usage:
import { cn } from "@/lib/utils"
function MyComponent({ className, isActive }) {
return (
<div className={cn(
"base-styles border-2",
isActive ? "bg-green-700 text-white" : "bg-white text-black",
className
)}>
Content
</div>
)
}
formatFundingAmount
Converts raw funding numbers into human-readable strings using Indian currency notation (Lakhs, Crores) and Billions for very large amounts.
Note: The system expects the input amount to be in Lakhs (e.g., 100 represents 1 Crore).
Parameters:
amount:number— The funding amount in lakhs.
Returns:
string: A formatted string with the ₹ symbol or "Not Disclosed" if the amount is zero or null.
| Input (Lakhs) | Output Example | Range Logic |
| :--- | :--- | :--- |
| 0 | "Not Disclosed" | Amount is 0, null, or undefined |
| 50 | "₹50L" | Amounts < 100 Lakhs |
| 120 | "₹1.2Cr" | Amounts between 1 Cr and 1000 Cr |
| 100000 | "₹1.00B" | Amounts >= 1000 Cr |
Usage:
import { formatFundingAmount } from "@/lib/utils"
// Displays: "₹50Cr"
const label = formatFundingAmount(5000);
// Displays: "Not Disclosed"
const emptyLabel = formatFundingAmount(0);
isFundingDisclosed
A helper function used to filter datasets or determine if specific UI elements (like "Largest Deal" stats) should include a particular record.
Parameters:
amount:number— The funding amount.
Returns:
boolean: Returnstrueif the amount is greater than0.
Usage:
import { isFundingDisclosed } from "@/lib/utils"
const disclosedDeals = fundingData.filter(deal => isFundingDisclosed(deal.amount));
const totalAmount = disclosedDeals.reduce((sum, deal) => sum + deal.amount, 0);