Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
63 lines
3.0 KiB
TypeScript
63 lines
3.0 KiB
TypeScript
const DISPLAY_SYMBOLS: Record<string, string> = { MYR: 'RM', SGD: 'S$' }
|
|
|
|
/** Display symbol for an ISO code; non-strings (e.g. a chart tickFormatter index) fall back to RM. */
|
|
export function displaySymbol(code?: unknown): string {
|
|
if (typeof code !== 'string' || !code.trim()) return 'RM'
|
|
const c = code.trim()
|
|
return DISPLAY_SYMBOLS[c] ?? c
|
|
}
|
|
|
|
export function formatRM(n: number, currency?: string): string {
|
|
return displaySymbol(currency) + ' ' + n.toLocaleString('en-MY', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
|
}
|
|
|
|
/** "RM 750", "RM 1.5k", "RM 12k", "RM 2.5m": short ringgit for chart axes and bar labels. One decimal below RM 10k keeps axis ticks distinct. */
|
|
export function compactRM(value: number, currency?: unknown): string {
|
|
const s = displaySymbol(currency)
|
|
if (value >= 1_000_000) return `${s} ${(value / 1_000_000).toFixed(1)}m`
|
|
if (value >= 10_000) return `${s} ${Math.round(value / 1000)}k`
|
|
if (value >= 1000) return `${s} ${Number((value / 1000).toFixed(1))}k`
|
|
return `${s} ${value}`
|
|
}
|
|
|
|
/** "+60 01928312323" from a stored prefix ("60", or "+60" in older rows) and number; "" if no number. */
|
|
export function formatPhone(prefix: string | null | undefined, number: string | null | undefined): string {
|
|
const n = (number ?? '').trim()
|
|
if (!n) return ''
|
|
const p = (prefix ?? '').trim().replace(/^\+/, '')
|
|
return p ? `+${p} ${n}` : n
|
|
}
|
|
|
|
/** Acorn/Apple reward amounts: wallet units, not currency — two decimals, no "RM". */
|
|
export function formatPoints(n: number): string {
|
|
return n.toLocaleString('en-MY', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
|
}
|
|
|
|
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
|
const DATE_RE = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::\d{2}(?:\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/
|
|
const MYT_OFFSET_MIN = 8 * 60 // Malaysia has no DST
|
|
|
|
function formatWhen(v: string | null | undefined, withTime: boolean): string {
|
|
if (!v) return '—'
|
|
const m = DATE_RE.exec(v)
|
|
if (!m) return v
|
|
if (Number(m[2]) < 1 || Number(m[2]) > 12 || Number(m[3]) < 1 || Number(m[3]) > 31) return v
|
|
let [y, mo, d, h, mi] = [m[1], m[2], m[3], m[4], m[5]].map(Number)
|
|
const zone = m[6]
|
|
if (zone) {
|
|
// Zoned instant -> Malaysia wall time; unzoned values are shown as written.
|
|
const off = zone === 'Z' ? 0 : (zone[0] === '-' ? -1 : 1) * (Number(zone.slice(1, 3)) * 60 + Number(zone.slice(-2)))
|
|
const t = new Date(Date.UTC(y, mo - 1, d, h, mi) + (MYT_OFFSET_MIN - off) * 60000)
|
|
;[y, mo, d, h, mi] = [t.getUTCFullYear(), t.getUTCMonth() + 1, t.getUTCDate(), t.getUTCHours(), t.getUTCMinutes()]
|
|
}
|
|
const date = `${d} ${MONTHS[mo - 1]} ${y}`
|
|
if (!withTime || m[4] === undefined) return date
|
|
return `${date}, ${String(h).padStart(2, '0')}:${String(mi).padStart(2, '0')}`
|
|
}
|
|
|
|
/** "28 Sep 2026, 23:41" — zoned values in Malaysia time, unzoned shown as written. */
|
|
export const formatDateTime = (v?: string | null) => formatWhen(v, true)
|
|
|
|
/** "28 Sep 2026" */
|
|
export const formatDate = (v?: string | null) => formatWhen(v, false)
|