forked from Yara724/api
28 lines
763 B
TypeScript
28 lines
763 B
TypeScript
/** Strip invisible bidi / ZWNJ chars that render as tofu in embedded Arabic fonts. */
|
|
export function normalizePersianPdfText(text: string): string {
|
|
return text
|
|
.replace(/\u200c/g, " ")
|
|
.replace(/[\u200e\u200f\u202a-\u202e\u2066-\u2069\ufeff]/g, "")
|
|
.replace(/\u2014/g, "-")
|
|
.replace(/\s+/g, " ")
|
|
.trim();
|
|
}
|
|
|
|
export function pdfKitRtlKeyValue(
|
|
label: string,
|
|
value: string,
|
|
): { label: string; value: string } {
|
|
return {
|
|
label: normalizePersianPdfText(label),
|
|
value: normalizePersianPdfText(value),
|
|
};
|
|
}
|
|
|
|
export function pdfKitRtlParagraph(text: string): string {
|
|
return normalizePersianPdfText(text);
|
|
}
|
|
|
|
export function isMostlyAscii(text: string): boolean {
|
|
return text.length > 0 && !/[\u0600-\u06FF]/.test(text);
|
|
}
|