Converts between Prisma decimals and cents, normalizes blank strings and email addresses, and provides null‑safe helpers for monetary and string values.
// Source: https://github.com/mperkins0155/crm | License: MIT | Copyright 2026 Comp AI
// Provided via justclaw.it.com; keep this notice with the code.
import type { Prisma } from "@crm/db";
import { Prisma as PrismaNamespace } from "@crm/db";
export function toCents(amount: Prisma.Decimal | null): number | null {
return amount === null ? null : amount.times(100).toNumber();
}
export function fromCents(cents: number | null | undefined): number | null {
return cents === null || cents === undefined ? null : cents / 100;
}
export function decimalFromCents(
cents: number | null | undefined,
): Prisma.Decimal | null {
return cents === null || cents === undefined
? null
: new PrismaNamespace.Decimal(cents).dividedBy(100);
}
export function blankToNull(value: string): string | null {
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key