-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
67 lines (63 loc) · 1.01 KB
/
main.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const rules = [
[',','،'],
['aa','ا'],
['oo','و'],
['h2','ح'],
['h1','ه'],
['sh','ش'],
['kh','خ'],
['zh','ژ'],
['ch','چ'],
['gh','ق'],
["g'h",'غ'],
['s2','ث'],
['s3','ص'],
['z2','ذ'],
['z3','ض'],
['z4','ظ'],
['t2','ط'],
["'",'ع'],
['a',''],
['b','ب'],
['c',''],
['d','د'],
['e',''],
['f','ف'],
['g','گ'],
['h','ه'],
['i','ی'],
['j','ج'],
['k','ک'],
['l','ل'],
['m','م'],
['n','ن'],
['o',''],
['p','پ'],
['q',''],
['r','ر'],
['s','س'],
['t','ت'],
['u',''],
['v','و'],
['w',''],
['x','خ'],
['y','ی'],
['z','ز'],
];
const words = require('./words');
const f = function (word){
if (word[0]=='$'){
word = word.substr(1);
rules.forEach(rule=>{
word = word.replace(new RegExp(rule[0],'g'),rule[1]);
});
return word;
}
if (words[word]) return words[word];
rules.forEach(rule=>{
word = word.replace(new RegExp(rule[0],'g'),rule[1]);
});
return word;
}
f.jomle = x=> x.split(' ').map(f).join(' ');
module.exports = f;