Skip to content

Commit

Permalink
emoji only shouldn't use punctuation
Browse files Browse the repository at this point in the history
  • Loading branch information
notwaldorf committed Jun 11, 2017
1 parent cd1ec93 commit 011c69e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions emoji-translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,15 @@ function translate(sentence, onlyEmoji) {
let firstSymbol = '';
let lastSymbol = '';
var word = words[i];
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) {
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);
}
}

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.4",
"version": "1.0.5",
"description": "A library that translates english words to emoji",
"main": "emoji-translate.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ test('annoying translations', function(t) {

// Exclamation marks should be preserved
t.equal(2, translate.translate('YES! victory!').match(/!/g).length);
t.equal(2, translate.translate('YES! victory!', true).match(/!/g).length);
t.equal(null, translate.translate('YES! victory!', true).match(/!/g));
t.end();
});

0 comments on commit 011c69e

Please sign in to comment.