Skip to content

Commit

Permalink
update function names
Browse files Browse the repository at this point in the history
  • Loading branch information
omnidan committed Jul 21, 2017
1 parent 6eeaecd commit 22099e6
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions lib/emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var emojiNameRegex = /:([a-zA-Z0-9_\-\+]+):/g;
* @param {string} str
* @return {string}
*/
var stripColons = function(str) {
function stripColons (str) {
var colonIndex = str.indexOf(':');
if (colonIndex > -1) {
// :emoji: (http://www.emoji-cheat-sheet.com/)
Expand All @@ -37,7 +37,7 @@ var stripColons = function(str) {
* @param {string} str
* @return {string}
*/
var wrapColons = function(str) {
function wrapColons (str) {
return (typeof str === 'string' && str.length > 0) ? ':' + str + ':' : str;
}

Expand All @@ -47,25 +47,25 @@ var wrapColons = function(str) {
* @param {string} str
* @return {string}
*/
var ensureColons = function(str) {
function ensureColons (str) {
return (typeof str === 'string' && str[0] !== ':') ? wrapColons(str) : str;
}

// Non spacing mark, some emoticons have them. It's the 'Variant Form',
// which provides more information so that emoticons can be rendered as
// more colorful graphics. FE0E is a unicode text version, where as FE0F
// Non spacing mark, some emoticons have them. It's the 'Variant Form',
// which provides more information so that emoticons can be rendered as
// more colorful graphics. FE0E is a unicode text version, where as FE0F
// should be rendered as a graphical version. The code gracefully degrades.
var NON_SPACING_MARK = String.fromCharCode(65039); // 65039 - '️' - 0xFE0F;
var nonSpacingRegex = new RegExp(NON_SPACING_MARK, 'g')
var nonSpacingRegex = new RegExp(NON_SPACING_MARK, 'g')

// Remove the non-spacing-mark from the code, never send a stripped version
// to the client, as it kills graphical emoticons.
var stripNSB = function(code) {
function stripNSB (code) {
return code.replace(nonSpacingRegex, '');
};

// Reversed hash table, where as emojiByName contains a { heart: '❤' }
// dictionary emojiByCode contains { ❤: 'heart' }. The codes are normalized
// Reversed hash table, where as emojiByName contains a { heart: '❤' }
// dictionary emojiByCode contains { ❤: 'heart' }. The codes are normalized
// to the text version.
var emojiByCode = Object.keys(emojiByName).reduce(function(h,k) {
h[stripNSB(emojiByName[k])] = k;
Expand All @@ -84,7 +84,7 @@ var Emoji = {
* @param {string} emoji
* @return {string}
*/
Emoji._get = function _get(emoji) {
Emoji._get = function _get (emoji) {
if (emojiByName.hasOwnProperty(emoji)) {
return emojiByName[emoji];
}
Expand All @@ -97,7 +97,7 @@ Emoji._get = function _get(emoji) {
* @param {string} emoji
* @return {string}
*/
Emoji.get = function get(emoji) {
Emoji.get = function get (emoji) {
emoji = stripColons(emoji);

return Emoji._get(emoji);
Expand All @@ -108,7 +108,7 @@ Emoji.get = function get(emoji) {
* @param {string} nameOrCode The emoji to find, either `coffee`, `:coffee:` or `☕`;
* @return {object}
*/
Emoji.find = function get(nameOrCode) {
Emoji.find = function find (nameOrCode) {
return Emoji.findByName(nameOrCode) || Emoji.findByCode(nameOrCode);
};

Expand All @@ -117,7 +117,7 @@ Emoji.find = function get(nameOrCode) {
* @param {string} name The emoji to find either `coffee` or `:coffee:`;
* @return {object}
*/
Emoji.findByName = function get(name) {
Emoji.findByName = function findByName (name) {
var stripped = stripColons(name);
var emoji = emojiByName[stripped];

Expand All @@ -129,7 +129,7 @@ Emoji.findByName = function get(name) {
* @param {string} code The emoji to find; for example `☕` or `☔`
* @return {object}
*/
Emoji.findByCode = function get(code) {
Emoji.findByCode = function findByCode (code) {
var stripped = stripNSB(code);
var name = emojiByCode[stripped];

Expand All @@ -143,7 +143,7 @@ Emoji.findByCode = function get(code) {
* @param {string} nameOrCode The emoji to validate, either `coffee`, `:coffee:` or `☕`;
* @return {object}
*/
Emoji.hasEmoji = function get(nameOrCode) {
Emoji.hasEmoji = function hasEmoji (nameOrCode) {
return Emoji.hasEmojiByName(nameOrCode) || Emoji.hasEmojiByCode(nameOrCode);
};

Expand All @@ -152,7 +152,7 @@ Emoji.hasEmoji = function get(nameOrCode) {
* @param {string} name The emoji to validate either `coffee` or `:coffee:`;
* @return {object}
*/
Emoji.hasEmojiByName = function get(name) {
Emoji.hasEmojiByName = function hasEmojiByName (name) {
var result = Emoji.findByName(name);
return !!result && result.key === stripColons(name);
};
Expand All @@ -162,7 +162,7 @@ Emoji.hasEmojiByName = function get(name) {
* @param {string} code The emoji to validate; for example `☕` or `☔`
* @return {object}
*/
Emoji.hasEmojiByCode = function get(code) {
Emoji.hasEmojiByCode = function hasEmojiByCode (code) {
var result = Emoji.findByCode(code);
return !!result && stripNSB(result.emoji) === stripNSB(code);
};
Expand All @@ -173,9 +173,9 @@ Emoji.hasEmojiByCode = function get(code) {
* @param {boolean} includeColons should the result include the ::
* @return {string}
*/
Emoji.which = function which(emoji_code, includeColons) {
var code = stripNSB(emoji_code);
var word = emojiByCode[code];
Emoji.which = function which (emoji_code, includeColons) {
var code = stripNSB(emoji_code);
var word = emojiByCode[code];

return includeColons ? wrapColons(word) : word;
};
Expand All @@ -187,7 +187,7 @@ Emoji.which = function which(emoji_code, includeColons) {
* @param {function} format (wrap the returned emoji in a custom element)
* @return {string}
*/
Emoji.emojify = function emojify(str, on_missing, format) {
Emoji.emojify = function emojify (str, on_missing, format) {
if (!str) return '';

return str.split(emojiNameRegex) // parse emoji via regex
Expand Down Expand Up @@ -215,7 +215,7 @@ Emoji.emojify = function emojify(str, on_missing, format) {
* return a random emoji
* @return {string}
*/
Emoji.random = function random() {
Emoji.random = function random () {
var emojiKeys = Object.keys(emojiByName);
var randomIndex = Math.floor(Math.random() * emojiKeys.length);
var key = emojiKeys[randomIndex];
Expand All @@ -228,7 +228,7 @@ Emoji.random = function random() {
* @param {string} str
* @return {Array.<Object>}
*/
Emoji.search = function search(str) {
Emoji.search = function search (str) {
var emojiKeys = Object.keys(emojiByName);
var matcher = stripColons(str)
var matchingKeys = emojiKeys.filter(function(key) {
Expand All @@ -247,7 +247,7 @@ Emoji.search = function search(str) {
* @param {string} str
* @return {string}
*/
Emoji.unemojify = function unemojify(str) {
Emoji.unemojify = function unemojify (str) {
if (!str) return '';
var words = toArray(str);

Expand Down

0 comments on commit 22099e6

Please sign in to comment.