diff options
| author | Max Nanis | 2026-09-13 19:03:55 +0000 |
|---|---|---|
| committer | Max Nanis | 2026-09-13 19:03:55 +0000 |
| commit | 8fbe8d439b418796932aaa88297e006c714e4d13 (patch) | |
| tree | 6c800476edc1e771fc570b559d483df8d59d4324 /jb-ui/src/lib | |
| parent | 12f6fee851b68e86af658dfa17e4a0daed457dd1 (diff) | |
| parent | 2c94f248d2438071a918fa9a30bf114ef9aa29b4 (diff) | |
| download | amt-jb-8fbe8d439b418796932aaa88297e006c714e4d13.tar.gz amt-jb-8fbe8d439b418796932aaa88297e006c714e4d13.zip | |
Merges pull request #3
Off of Amazon!!!
Diffstat (limited to 'jb-ui/src/lib')
| -rw-r--r-- | jb-ui/src/lib/utils.ts | 164 |
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(" "); +} |
