-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert.js
152 lines (97 loc) · 3.2 KB
/
convert.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
module.exports = {
persian_number: [ "\u06F0", "\u06F1", "\u06F2", "\u06F3", "\u06F4", "\u06F5", "\u06F6", "\u06F7", "\u06F8", "\u06F9"],
result: '',
temp: '',
/*********************************************************************
* Convert english number to persian number
**********************************************************************
* @since 25 Jun 2015
* @var input string
* @return object
*/
number: function( input ) {
if ( input == null ) {
input = this.result;
}
for (var i = 0; i < input.length; i++) {
this.result += this.persian_number[ parseInt( input.charAt( i ) ) ];
}
return this;
},
/*********************************************************************
* Convert english number to persian number in persin text
**********************************************************************
* @since 08 July 2015
* @var input string
* @return object
*/
alphaNum: function( input ) {
if ( input == null ) {
input = this.result;
}
for (var i = 0; i < input.length; i++) {
if ( isNaN( parseInt( input.charAt( i ) ) ) ) continue;
else {
this.temp = this.persian_number[ parseInt( input.charAt( i ) ) ];
this.result = this.result.replace( input.charAt( i ), this.temp );
}
}
return this;
},
/**********************************************************************
* Detect persian verbs and replace space with half-space
***********************************************************************
* @since 30 Jun 2015
* @var input string
* @return Object
*/
halfSpace: function( input ) {
if ( input == null ) {
input = this.result;
}
this.result = input.replace(/(\s[\u0645]+[\u06CC])+\s/g, "$1\u200C");
this.result = this.result.replace(/([\u0647])+\s+([\u0627]+[\u0645]||[\u0627]+[\u0649]||[\u0627]+[\u0649]+[\u0649]||[\u0627]+[\u0649]+[\u0645]||[\u0649]+[\u0646]+[\u062f]||[\u0627]+[\u0649]+[\u062f])/g, "$1\u200C$2");
return this;
},
/**********************************************************************
* Convert arabic charachters to persian
***********************************************************************
* @since 30 Jun 2015
* @var input string
* @return Object
*/
removeArabicChar: function( input ) {
if ( input == null ) {
input = this.result;
}
this.result = input.replace(/[\u064A]/g,"\u06CC");
this.result = this.result.replace(/[\u0643]/g, "\u06A9");
return this;
},
/**********************************************************************
* Convert inputs to valid persian format with all options
***********************************************************************
* @since 08 July 2015
* @var input string
* @return string
*/
all: function( input ) {
if ( input == null ) {
input = this.result;
}
this.result = input;
this.alphaNum(this.result);
this.halfSpace( this.result );
this.removeArabicChar( this.result );
return this;
},
/**********************************************************************
* Return result of all operations on value
***********************************************************************
* @since 25 Jun 2015
* @return string
*/
get: function() {
return this.result;
}
}