Skip to content

Commit 298ecfe

Browse files
committed
Have a violent reaction when out of emoji
Failing explicitly is better than silently starting to return empty strings.
1 parent fface50 commit 298ecfe

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/interpolateName.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ function encodeStringToEmoji(content, length) {
1212
if(emojiCache[content]) return emojiCache[content];
1313
length = length || 1;
1414
const emojis = [];
15-
do {
16-
const index = Math.floor(Math.random() * emojiList.length);
15+
do {
16+
if (!emojiList.length) {
17+
throw new Error("Ran out of emoji");
18+
}
19+
20+
const index = Math.floor(Math.random() * emojiList.length);
1721
emojis.push(emojiList[index]);
1822
emojiList.splice(index, 1);
1923
} while(--length > 0);

0 commit comments

Comments
 (0)