From 96f3d0275c3298950dab5df1b32abc01ffbfc179 Mon Sep 17 00:00:00 2001 From: Monica Dinculescu Date: Sun, 11 Jun 2017 13:14:57 -0700 Subject: [PATCH] punctuation logic was still broken --- emoji-translate.js | 21 ++++++++++++--------- package.json | 2 +- test.js | 2 ++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/emoji-translate.js b/emoji-translate.js index 3346e954..d61c3786 100644 --- a/emoji-translate.js +++ b/emoji-translate.js @@ -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); diff --git a/package.json b/package.json index 45f0f17a..07f3ef81 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test.js b/test.js index fc5cd616..5a6d7608 100644 --- a/test.js +++ b/test.js @@ -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(); });