-
Notifications
You must be signed in to change notification settings - Fork 113
/
index.ts
42 lines (40 loc) · 1007 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* toPersianChars
*
* Description: Replace all instances of ي and ك with ی and ک,
* respectively. It should not make any changes to an Arabic text
* surrounded by appropriate templates.
*
* @method toPersianChars
* @param {string} str
* @return cleaned characters of arabic characters
*/
function toPersianChars(str: string): string | undefined {
if (!str) return;
return str
.replace(/ي/g, "ی")
.replace(/ك/g, "ک")
.replace(/٫/g, "٫")
.replace(/٬/g, "٬")
.replace(/٭/g, "٭")
.replace(/٪/g, "٪")
.replace(/ـ/g, "ـ")
.replace(/ً/g, "ً")
.replace(/ٌ/g, "ٌ")
.replace(/ٍ/g, "ٍ")
.replace(/َ/g, "َ")
.replace(/ُ/g, "ُ")
.replace(/ِ/g, "ِ")
.replace(/ّ/g, "ّ")
.replace(/ْ/g, "ْ")
.replace(/ٰ/g, "ٰ")
.replace(/ٔ/g, "ٔ")
.replace(/ٕ/g, "ٕ")
.replace(/ٖ/g, "ٖ")
.replace(/ٗ/g, "ٗ")
.replace(/٘/g, "٘")
.replace(/ٙ/g, "ٙ")
.replace(/ٚ/g, "ٚ")
.replace(/ٛ/g, "ٛ");
}
export default toPersianChars;