Skip to content

Commit

Permalink
punctuation logic was still broken
Browse files Browse the repository at this point in the history
  • Loading branch information
notwaldorf committed Jun 11, 2017
1 parent 011c69e commit 96f3d02
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
21 changes: 12 additions & 9 deletions emoji-translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,18 @@ function translate(sentence, onlyEmoji) {
let firstSymbol = '';
let lastSymbol = '';
var word = words[i];
if (!onlyEmoji) {
while (SYMBOLS.indexOf(word[0]) != -1) {
firstSymbol += word[0];
word = word.slice(1, word.length);
}
while (SYMBOLS.indexOf(word[word.length - 1]) != -1) {
lastSymbol += word[word.length - 1];
word = word.slice(0, word.length - 1);
}

while (SYMBOLS.indexOf(word[0]) != -1) {
firstSymbol += word[0];
word = word.slice(1, word.length);
}
while (SYMBOLS.indexOf(word[word.length - 1]) != -1) {
lastSymbol += word[word.length - 1];
word = word.slice(0, word.length - 1);
}

if (onlyEmoji) {
firstSymbol = lastSymbol = ''
}

let translated = getEmojiForWord(word);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moji-translate",
"version": "1.0.5",
"version": "1.0.6",
"description": "A library that translates english words to emoji",
"main": "emoji-translate.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ test('annoying translations', function(t) {
// Exclamation marks should be preserved
t.equal(2, translate.translate('YES! victory!').match(/!/g).length);
t.equal(null, translate.translate('YES! victory!', true).match(/!/g));

t.notEqual('', translate.translate('welcome back, emoji robot! ready to take over the world?', true));
t.end();
});

0 comments on commit 96f3d02

Please sign in to comment.