mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-10 19:04:42 +02:00
Remove Tons of Dependencies
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
module.exports.wordTrans = (text, words) => {
|
||||
text = text.split(' ');
|
||||
let translation = [];
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
const word = text[i];
|
||||
const wordPuncStrip = word.replace(/[.,?!-]/g, '');
|
||||
if (words[wordPuncStrip]) {
|
||||
const reg = new RegExp(wordPuncStrip, 'gi');
|
||||
translation.push(word.replace(reg, words[wordPuncStrip]));
|
||||
}
|
||||
else {
|
||||
translation.push(word);
|
||||
}
|
||||
}
|
||||
return translation.join(' ');
|
||||
};
|
||||
|
||||
module.exports.letterTrans = (text, letters) => {
|
||||
text = text.split('');
|
||||
let translation = [];
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
const letter = text[i];
|
||||
if (letters[letter]) {
|
||||
const reg = new RegExp(letter, 'gi');
|
||||
translation.push(letter.replace(reg, letters[letter]));
|
||||
}
|
||||
else {
|
||||
translation.push(letter);
|
||||
}
|
||||
}
|
||||
return translation.join('');
|
||||
};
|
||||
Reference in New Issue
Block a user