Unverified Commit 3a9ded0a authored by Mario Lubenka's avatar Mario Lubenka Committed by GitHub
Browse files

feat(repocard): parse emojis in description (#67)



* feat: add remove_emojis option

Removes emojis in repo card description

* feat: parse emojis

* feat: rename remove_emojis to show_emojis option for consistency

* docs: update docs

Co-authored-by: default avataranuraghazra <hazru.anurag@gmail.com>
parent 7973805c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -19,7 +19,8 @@
    "jest": "^26.1.0"
  },
  "dependencies": {
    "dotenv": "^8.2.0"
    "dotenv": "^8.2.0",
    "emoji-name-map": "^1.2.8"
  },
  "husky": {
    "hooks": {
+8 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ const {
  FlexLayout,
} = require("../src/utils");
const icons = require("./icons");
const toEmoji = require("emoji-name-map");

const renderRepoCard = (repo, options = {}) => {
  const {
@@ -34,8 +35,14 @@ const renderRepoCard = (repo, options = {}) => {
  const shiftText = langName.length > 15 ? 0 : 30;

  let desc = description || "No description provided";

  // parse emojis to unicode
  desc = desc.replace(/:\w+:/gm, (emoji) => {
    return toEmoji.get(emoji) || "";
  });

  if (desc.length > 55) {
    desc = `${description.slice(0, 55)}..`;
    desc = `${desc.slice(0, 55)}..`;
  }

  // returns theme based colors with proper overrides and defaults
+12 −0
Original line number Diff line number Diff line
@@ -73,6 +73,18 @@ describe("Test renderRepoCard", () => {
    );
  });

  it("should render emojis", () => {
    document.body.innerHTML = renderRepoCard({
      ...data_repo.repository,
      description: "This is a text with a :poop: poo emoji",
    });

    // poop emoji may not show in all editors but it's there between "a" and "poo"
    expect(document.getElementsByClassName("description")[0]).toHaveTextContent(
      "This is a text with a 💩 poo emoji"
    );
  });

  it("should shift the text position depending on language length", () => {
    document.body.innerHTML = renderRepoCard({
      ...data_repo.repository,
+1 −1

File changed.

Contains only whitespace changes.