node-emoji
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -62,8 +62,15 @@ /*jslint node: true*/ | ||
* @param {string} str | ||
* @param {function} on_missing (gets emoji name without :: and returns a proper emoji if no emoji was found) | ||
* @return {string} | ||
*/ | ||
Emoji.emojify = function emojify(str) { | ||
Emoji.emojify = function emojify(str, on_missing) { | ||
return str.split(parser) // parse emoji via regex | ||
.map(function parseEmoji(s, i) { | ||
return (i % 2 === 0) ? s : Emoji._get(s); // every second element is an emoji, e.g. "test :fast_forward:" -> [ "test ", "fast_forward" ] | ||
// every second element is an emoji, e.g. "test :fast_forward:" -> [ "test ", "fast_forward" ] | ||
if (i % 2 === 0) return s; | ||
var emoji = Emoji._get(s); | ||
if (emoji.indexOf(':') > -1 && typeof on_missing === 'function') { | ||
return on_missing(emoji.substr(1, emoji.length-2)); | ||
} | ||
return emoji; | ||
}) | ||
@@ -70,0 +77,0 @@ .join('') // convert back to string |
{ | ||
"name": "node-emoji", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "simple emoji support for node.js projects", | ||
@@ -5,0 +5,0 @@ "author": "Daniel Bugl <daniel.bugl@touchlay.com>", |
@@ -55,2 +55,10 @@ /*jslint node: true*/ | ||
}); | ||
it("should replace unknown emoji using provided cb function", function () { | ||
var coffee = emoji.emojify('I :unknown_emoji: :star: :another_one:', function(name) { | ||
return name; | ||
}); | ||
should.exist(coffee); | ||
coffee.should.be.exactly('I unknown_emoji ⭐️ another_one'); | ||
}); | ||
}); | ||
@@ -57,0 +65,0 @@ |
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
144570
1460