-
Notifications
You must be signed in to change notification settings - Fork 0
/
getTranslite.js
57 lines (48 loc) · 1.1 KB
/
getTranslite.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
const { esTranslite } = require('./data/es/data-es-translite')
const { ruTranslite } = require('./data/ru/data-ru-translite')
const { ukTranslite } = require('./data/uk/data-uk-translite')
const defaultTransliteOptions = {
input: 'ru',
output: 'en'
}
/**
* option = {
* str ()
* input ()
* output ()
* }
*/
const getTranslite = (str, transliteOptions = defaultTransliteOptions) => {
const inputLanguage = transliteOptions.input
let activeTranslite
switch(inputLanguage) {
case 'es':
activeTranslite = esTranslite
break;
case 'ru':
activeTranslite = ruTranslite
break;
case 'uk':
activeTranslite = ukTranslite
break;
/*
case 'es':
// code block
break;
default:
// code block
*/
}
const newStr = [...str].map(element => {
const isTransliteAvailable = activeTranslite.toEn.hasOwnProperty(`${element}`)
if(isTransliteAvailable) {
return activeTranslite.toEn[element]
} else if(element === '.'){
return '.'
} else {
return ''
}
})
return newStr.join('')
}
module.exports = { getTranslite }