aboutsummaryrefslogtreecommitdiff
path: root/jb-ui/src
diff options
context:
space:
mode:
Diffstat (limited to 'jb-ui/src')
-rw-r--r--jb-ui/src/lib/utils.ts95
1 files changed, 95 insertions, 0 deletions
diff --git a/jb-ui/src/lib/utils.ts b/jb-ui/src/lib/utils.ts
new file mode 100644
index 0000000..04b5dc9
--- /dev/null
+++ b/jb-ui/src/lib/utils.ts
@@ -0,0 +1,95 @@
+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 bpid = import.meta.env.VITE_BPID;
+
+export function cn(...inputs: ClassValue[]) {
+ return twMerge(clsx(inputs))
+}
+
+export function assert(condition: any, msg?: string): asserts condition {
+ if (!condition) {
+ throw new Error(msg);
+ }
+}
+
+export function toCapitalized(word: string): string {
+ 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 usdCentFmt(value: number): string {
+ return (value / 100).toLocaleString('en-US', {
+ style: 'currency',
+ currency: 'USD',
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2
+ })
+}
+
+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]
+}
+
+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} 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}`
+}
+
+export function formatCentsToUSD(cents: number): string {
+ 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