-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
52 lines (50 loc) · 1.54 KB
/
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
43
44
45
46
47
48
49
50
51
52
const ThaiNumbers_Dictionary = {
'0': '0',
'๐': '0',
'๑': '1',
'๒': '2',
'๓': '3',
'๔': '4',
'๕': '5',
'๖': '6',
'๗': '7',
'๘': '8',
'๙': '9',
};
function splitText(text: string, spliter: string) {
let value: string[] = text.split(spliter);
let data: string = value.reduce((a, b) => a + b);
return data;
}
export default class ThaiNumber_Converter {
static toInteger(thainumber: string) {
let value: any = splitText(thainumber, ',');
if (value.length === 1) value = value[0].split('');
let new_value: string[] = [];
for (let i = 0; i < value.length; i++) {
if (value[i] in ThaiNumbers_Dictionary) {
new_value[i] = ThaiNumbers_Dictionary[value[i]];
}
else {
return 'error check your data is it thai?';
}
}
let result: string = new_value.reduce((a, b) => a + b);
return parseInt(result);
}
static toStringData(thainumber) {
let value: any = splitText(thainumber, ',');
if (value.length === 1) value = value[0].split('');
let new_value: string[] = [];
for (let i = 0; i < value.length; i++) {
if (value[i] in ThaiNumbers_Dictionary) {
new_value[i] = ThaiNumbers_Dictionary[value[i]];
}
else {
return 'error check your data is it thai?';
}
}
let result: string = new_value.reduce((a, b) => a + b);
return result;
}
}