aboutsummaryrefslogtreecommitdiff
path: root/jb-ui/src/lib/utils.ts
diff options
context:
space:
mode:
authorMax Nanis2026-09-10 17:46:41 -0700
committerMax Nanis2026-09-10 17:46:41 -0700
commited201936813d9a720b51e6cb40a05267b94e7314 (patch)
treef675f6a0d91ed1d17f654e40936e8c1ca9ccf141 /jb-ui/src/lib/utils.ts
parent0ac38066402762dc5fa24f2ffa2170681a6eddb1 (diff)
downloadamt-jb-ed201936813d9a720b51e6cb40a05267b94e7314.tar.gz
amt-jb-ed201936813d9a720b51e6cb40a05267b94e7314.zip
Typescript prettier
Committing seperate so it's easier to see actual changes.
Diffstat (limited to 'jb-ui/src/lib/utils.ts')
-rw-r--r--jb-ui/src/lib/utils.ts164
1 files changed, 85 insertions, 79 deletions
diff --git a/jb-ui/src/lib/utils.ts b/jb-ui/src/lib/utils.ts
index 0c84192..1aa59c6 100644
--- a/jb-ui/src/lib/utils.ts
+++ b/jb-ui/src/lib/utils.ts
@@ -1,113 +1,119 @@
-import { type ClassValue, clsx } from "clsx"
-import { twMerge } from "tailwind-merge"
-import { Source } from "../api_fsb"
+import { type ClassValue, clsx } from "clsx";
+import { twMerge } from "tailwind-merge";
+import { Source } from "../api_fsb";
export const routeBasename = import.meta.env.VITE_BASENAME;
-export const tagManager = import.meta.env.VITE_TAG_MANAGER
+export const tagManager = import.meta.env.VITE_TAG_MANAGER;
export const bpid = import.meta.env.VITE_BPID;
export function cn(...inputs: ClassValue[]) {
- return twMerge(clsx(inputs))
+ return twMerge(clsx(inputs));
}
export function assert(condition: any, msg?: string): asserts condition {
- if (!condition) {
- throw new Error(msg);
- }
+ if (!condition) {
+ throw new Error(msg);
+ }
}
export function toCapitalized(word: string): string {
- return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
+ return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
}
-export function truncate(originalText: string, maxLength: number = 10, replaceStr = "…"): string {
- if (originalText && originalText.length > maxLength) {
- return originalText.substring(0, maxLength) + replaceStr;
- }
- return originalText;
+export function truncate(
+ originalText: string,
+ maxLength: number = 10,
+ replaceStr = "…",
+): string {
+ if (originalText && originalText.length > maxLength) {
+ return originalText.substring(0, maxLength) + replaceStr;
+ }
+ return originalText;
}
export function usdCentFmt(value: number): string {
- return (value / 100).toLocaleString('en-US', {
- style: 'currency',
- currency: 'USD',
- minimumFractionDigits: 2,
- maximumFractionDigits: 2
- })
+ return (value / 100).toLocaleString("en-US", {
+ style: "currency",
+ currency: "USD",
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ });
}
export function formatStatus(status: string): string {
- const table = {
- 'c': 'Completed',
- 't': 'Terminated',
- 'f': 'Failed',
- 'e': 'Entered',
- }
-
- return table[status as keyof typeof table] ?? "Unknown";
+ const table = {
+ c: "Completed",
+ t: "Terminated",
+ f: "Failed",
+ e: "Entered",
+ };
+
+ return table[status as keyof typeof table] ?? "Unknown";
}
export function formatSource(source: Source): string {
- const table = {
- 'g': 'GRS',
- 'c': 'Cint',
- 'a': 'Dalia',
- 'd': 'Dynata',
- 'et': 'Etx',
- 'f': 'Full Circle',
- 'i': 'InnovateMR',
- 'l': 'Lucid',
- 'm': 'Morning Consult',
- 'n': 'Open Labs',
- 'o': 'Pollfish',
- 'e': 'Precision Sample',
- 'r': 'Prodege User',
- 'pr': 'Prodege',
- 'p': 'Pulley',
- 'rd': 'Rep Data',
- 'h': 'Sago',
- 's': 'Pure Spectrum',
- 't': 'Testing',
- 'u': 'Testing 2',
- 'w': 'WXET'
- }
-
- return table[source]
+ const table = {
+ g: "GRS",
+ c: "Cint",
+ a: "Dalia",
+ d: "Dynata",
+ et: "Etx",
+ f: "Full Circle",
+ i: "InnovateMR",
+ l: "Lucid",
+ m: "Morning Consult",
+ n: "Open Labs",
+ o: "Pollfish",
+ e: "Precision Sample",
+ r: "Prodege User",
+ pr: "Prodege",
+ p: "Pulley",
+ rd: "Rep Data",
+ h: "Sago",
+ s: "Pure Spectrum",
+ t: "Testing",
+ u: "Testing 2",
+ w: "WXET",
+ };
+
+ return table[source];
}
export function formatSecondsVerbose(seconds: number): string {
- const mins = Math.floor(seconds / 60)
- const secs = seconds % 60
-
- const parts = []
- if (mins > 0) parts.push(`${mins} min`)
- if (secs > 0 || mins === 0) {
- parts.push(`${secs.toLocaleString('en-US', {
- minimumFractionDigits: 0,
- maximumFractionDigits: 1
- })} sec`)
- }
-
- return parts.join(" ")
+ const mins = Math.floor(seconds / 60);
+ const secs = seconds % 60;
+
+ const parts = [];
+ if (mins > 0) parts.push(`${mins} min`);
+ if (secs > 0 || mins === 0) {
+ parts.push(
+ `${secs.toLocaleString("en-US", {
+ minimumFractionDigits: 0,
+ maximumFractionDigits: 1,
+ })} sec`,
+ );
+ }
+
+ return parts.join(" ");
}
export function formatSeconds(seconds: number): string {
- const mins = Math.floor(seconds / 60)
- const secs = seconds % 60
- const paddedSecs = secs.toString().padStart(2, '0')
- return `${mins}:${paddedSecs}`
+ const mins = Math.floor(seconds / 60);
+ const secs = seconds % 60;
+ const paddedSecs = secs.toString().padStart(2, "0");
+ return `${mins}:${paddedSecs}`;
}
export function formatCentsToUSD(cents: number): string {
- return new Intl.NumberFormat('en-US', {
- style: 'currency',
- currency: 'USD',
- }).format(cents / 100)
+ return new Intl.NumberFormat("en-US", {
+ style: "currency",
+ currency: "USD",
+ }).format(cents / 100);
}
export function titleCase(str: string): string {
- return str
- .split(" ")
- .map(word => word.charAt(0).toUpperCase() + word.slice(1))
- .join(" ");
-} \ No newline at end of file
+ return str
+ .split(" ")
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
+ .join(" ");
+}