How to use the node-emoji.which function in node-emoji

To help you get started, we’ve selected a few node-emoji examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rooseveltframework / roosevelt-logger / logger.js View on Github external
function argumentsToString (input, enablePrefix, prefix) {
  let str = ''
  const args = Object.values(input)

  // determine if first arg is a prefix
  if (typeof args[0] === 'string' && args[0].trim() === prefix) {
    // first arg is the prefix, add it when enabled
    if (enablePrefix) {
      str += args[0].trim() + '  '
    }
  } else if (typeof args[0] === 'string' && emoji.which(args[0].trim())) {
    // first arg is an emoji, add it as a prefix when enabled
    if (enablePrefix) {
      str += args[0].trim() + '  '
    }
  } else if (prefix && prefix.length > 0) {
    // first arg is not a prefix and prefix is set, add prefix when enabled
    const arg0 = (typeof args[0] === 'string') ? args[0] : util.inspect(args[0], false, null, false)
    if (enablePrefix) {
      str += prefix + '  ' + arg0
    } else {
      str += arg0 + ' '
    }
  } else {
    // no prefix configured or in use
    const arg0 = (typeof args[0] === 'string') ? args[0] : util.inspect(args[0], false, null, false)
    str += arg0 + ' '
github rooseveltframework / roosevelt / lib / tools / logger.js View on Github external
let args = Array.prototype.slice.call(input)
  // if the first arg is a string and the first arg isn't an emoji add the types emoji
  if (typeof args[0] === 'string' && !emoji.which(args[0])) {
    switch (type) {
      case 'warn':
        str += '⚠️   '
        break
      case 'error':
        str += '❌  '
        break
    }
  }
  // iterate through args and check for objects for proper string representation
  for (let k in args) {
    // proper spacing if the argument is an emoji
    if (typeof args[k] === 'string' && emoji.which(args[k])) {
      // add 2 spaces after an emoji
      str += args[k] + '  '
    } else if (typeof args[k] === 'object') {
      // if the argument is an object use the inspect utility on it
      args[k] = util.inspect(args[k], false, null, true)
      // after an object arguments add 1 space
      str += args[k] + ' '
    } else {
      // everything else will have 1 space
      str += args[k] + ' '
    }
  }
  // trim white space from the end of a string
  str = str.replace(/\s*$/, '')
  // return string
  return str
github rooseveltframework / roosevelt / lib / tools / logger.js View on Github external
function argumentsToString (input, type) {
  let str = ''
  // convert arguments object to array
  let args = Array.prototype.slice.call(input)
  // if the first arg is a string and the first arg isn't an emoji add the types emoji
  if (typeof args[0] === 'string' && !emoji.which(args[0])) {
    switch (type) {
      case 'warn':
        str += '⚠️   '
        break
      case 'error':
        str += '❌  '
        break
    }
  }
  // iterate through args and check for objects for proper string representation
  for (let k in args) {
    // proper spacing if the argument is an emoji
    if (typeof args[k] === 'string' && emoji.which(args[k])) {
      // add 2 spaces after an emoji
      str += args[k] + '  '
    } else if (typeof args[k] === 'object') {
github Snooful / Snooful / src / commands / emoji / feed.js View on Github external
handler: args => {
		const emoji = chance.pickone(tastyFood);
		const emojiName = emojiAPI.which(emoji).toString().replace(/_/g, " ");

		if (args.user && args.user !== "undefined") {
			args.send(args.localize("feed_other", emojiName, emoji, args.user));
		} else {
			// Feed the sender
			args.send(args.localize("feed", emojiName, emoji));
		}
	},
	name: "feed",
github Foundry376 / Mailspring / app / internal_packages / composer-emoji / lib / emoji-message-extension.jsx View on Github external
static renderedMessageBodyIntoDocument({ document }) {
    const emojiRegex = RegExpUtils.emojiRegex();

    // Look for emoji in the content of text nodes
    const treeWalker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);

    while (treeWalker.nextNode()) {
      emojiRegex.lastIndex = 0;

      const node = treeWalker.currentNode;
      let match = null;

      while ((match = emojiRegex.exec(node.textContent))) {
        const matchEmojiName = emoji.which(match[0]);
        if (matchEmojiName) {
          const matchNode = match.index === 0 ? node : node.splitText(match.index);
          matchNode.splitText(match[0].length);
          const imageNode = document.createElement('img');
          makeIntoEmojiTag(imageNode, matchEmojiName);
          matchNode.parentNode.replaceChild(imageNode, matchNode);
        }
      }
    }
  }
}
github Foundry376 / Mailspring / internal_packages / composer-emoji / lib / emoji-composer-extension.jsx View on Github external
static unapplyTransformsToBody = ({fragment}) => {
    const treeWalker = document.createTreeWalker(fragment, NodeFilter.SHOW_TEXT);
    while (treeWalker.nextNode()) {
      const textNode = treeWalker.currentNode;
      const match = RegExpUtils.emojiRegex().exec(textNode.textContent);
      if (match) {
        const emojiPlusTrailingEl = textNode.splitText(match.index);
        emojiPlusTrailingEl.splitText(match.length);
        const emojiEl = emojiPlusTrailingEl;
        const imgEl = document.createElement('img');
        const emojiName = emoji.which(match[0])
        imgEl.className = `emoji ${emojiName}`;
        imgEl.src = EmojiStore.getImagePath(emojiName);
        imgEl.width = '14';
        imgEl.height = '14';
        imgEl.style.marginTop = '-5px';
        emojiEl.parentNode.replaceChild(imgEl, emojiEl);
      }
    }
  }
github Foundry376 / Mailspring / app / internal_packages / composer-emoji / lib / emoji-composer-extension.jsx View on Github external
static unapplyTransformsForSending = ({ draftBodyRootNode }) => {
    const treeWalker = document.createTreeWalker(draftBodyRootNode, NodeFilter.SHOW_TEXT);
    while (treeWalker.nextNode()) {
      const textNode = treeWalker.currentNode;
      const match = RegExpUtils.emojiRegex().exec(textNode.textContent);
      if (match) {
        const emojiPlusTrailingEl = textNode.splitText(match.index);
        emojiPlusTrailingEl.splitText(match.length);
        const emojiEl = emojiPlusTrailingEl;
        const imgEl = document.createElement('img');
        const emojiName = emoji.which(match[0]);
        imgEl.className = `emoji ${emojiName}`;
        imgEl.src = EmojiStore.getImagePath(emojiName);
        imgEl.width = '14';
        imgEl.height = '14';
        imgEl.style.marginTop = '-5px';
        emojiEl.parentNode.replaceChild(imgEl, emojiEl);
      }
    }
  };