Files
CRM_Montzar/apps/api/src/common/sms-text.ts
T

36 lines
977 B
TypeScript

import { jalaliMonthName, toJalali } from './jalali';
import { applyMessageTemplate } from '../message-automations/message-automation.util';
const FA_DIGITS = '۰۱۲۳۴۵۶۷۸۹';
function toFaDigits(value: string | number) {
return String(value).replace(/\d/g, (d) => FA_DIGITS[Number(d)] ?? d);
}
function tehranJalaliLong(d: Date) {
const [gy, gm, gd] = new Intl.DateTimeFormat('en-CA', {
timeZone: 'Asia/Tehran',
year: 'numeric',
month: '2-digit',
day: '2-digit',
})
.format(d)
.split('-')
.map(Number);
const j = toJalali(gy, gm, gd);
return `${toFaDigits(j.jd)} ${jalaliMonthName(j.jm)} ${toFaDigits(j.jy)}`;
}
export function renderSmsText(
text: string,
vars: { name?: string; phone?: string; title?: string; company?: string },
) {
return applyMessageTemplate(text, {
name: vars.name,
phone: vars.phone,
title: vars.title,
company: vars.company,
date: tehranJalaliLong(new Date()),
}).trim();
}