emoji-similar
Advanced tools
Comparing version 1.1.2 to 1.2.0
23
index.js
@@ -20,10 +20,23 @@ 'use strict'; | ||
var getSimilar = function(emoji, count) { | ||
var getSimilar = function(emoji, count, random) { | ||
var emojiName = _getEmojiname(emoji); | ||
for (var i = 0; i < similarEmoji.length; i++) | ||
if(similarEmoji[i].indexOf(emojiName) > -1) | ||
return count ? similarEmoji.filter(e => e !== emojiName).slice(0, count) : similarEmoji.filter(e => e !== emojiName); | ||
var index = null; | ||
for (var i = 0; i < similarEmoji.length; i++) { | ||
if(similarEmoji[i].indexOf(emojiName) > -1) { | ||
index = i; | ||
break; | ||
} | ||
} | ||
return []; | ||
if (index === null) | ||
return []; | ||
var emojis = similarEmoji[index].filter(e => e !== emojiName); | ||
if (random) { | ||
emojis.sort(function() { return 0.5 - Math.random() }); | ||
} | ||
return count ? emojis.slice(0, count) : emojis; | ||
}; | ||
@@ -30,0 +43,0 @@ |
{ | ||
"name": "emoji-similar", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "Simple library to get similar emoji", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,5 +11,5 @@ # emoji-similar | ||
``` | ||
getSimilar(emoji [, count]); | ||
getSimilar(emoji [, count, random]); | ||
``` | ||
Example | ||
@@ -28,2 +28,8 @@ ``` | ||
getSimilar('boom', 4, true); | ||
// return list of 4 similar emoji in random order | ||
getSimilar('boom', null, true); | ||
// return list of all similar emoji in random order | ||
``` | ||
@@ -36,2 +42,1 @@ | ||
``` | ||
34
test.js
@@ -8,3 +8,5 @@ 'use strict'; | ||
it('should return 3 similar emoji', function() { | ||
assert.equal(3, getSimilar('boom', 3).length); | ||
var emojis = getSimilar('boom', 3); | ||
console.log(emojis); | ||
assert.equal(3, emojis.length); | ||
}); | ||
@@ -15,3 +17,5 @@ }); | ||
it('should return 3 similar emoji', function() { | ||
assert.equal(3, getSimilar(':heartbeat:', 3).length); | ||
var emojis = getSimilar(':heartbeat:', 3); | ||
console.log(emojis); | ||
assert.equal(3, emojis.length); | ||
}); | ||
@@ -22,3 +26,5 @@ }); | ||
it('should return 4 similar emoji', function() { | ||
assert.equal(4, getSimilar('😄', 4).length); | ||
var emojis = getSimilar('😬', 4); | ||
console.log(emojis); | ||
assert.equal(4, emojis.length); | ||
}); | ||
@@ -29,5 +35,23 @@ }); | ||
describe('getSimilar', function() { | ||
it('should return all (4) similar emoji', function() { | ||
assert.equal(4, getSimilar('facepunch').length); | ||
it('should return all (5) similar emoji', function() { | ||
var emojis = getSimilar('facepunch'); | ||
console.log(emojis); | ||
assert.equal(5, emojis.length); | ||
}); | ||
}); | ||
describe('getSimilar', function() { | ||
it('should return 4 random similar emoji', function() { | ||
var emojis = getSimilar('smile', 4, true); | ||
console.log(emojis); | ||
assert.equal(4, emojis.length); | ||
}); | ||
}); | ||
describe('getSimilar', function() { | ||
it('should return all (5) similar emoji in random order', function() { | ||
var emojis = getSimilar('facepunch', null, true); | ||
console.log(emojis); | ||
assert.equal(5, emojis.length); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3653
77
40