npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

github-leetcode-component

v1.0.5

Published

Component to generates GitHub and LeetCode calendar. Plus, the combination calendar for both.

Downloads

3

Readme

github-leetcode-component

Blog Example

github-leetcode-component is a react library to:

  1. Generate the calendar that combined GitHub and LeetCode Calendar (Combination Calendar)
  2. Generate the GitHub Contribution Calendar
  3. Generate the LeetCode Submission Calendar
  4. Get User Data from GitHub
  5. Get User Data from LeetCode

Here how GitHub Calendar, Leetcode Calendar, Combination Calendar look in order: Overall_example

Different Sizes of Calendar: Combination Calender (Large - default / wrong input) GitHub Calendar (Medium) LeetCode Calendar (Small) Overall_example

Example of applying to :

Installation

npm install github-leetcode-component

Requirements

You will have to set up a server proxy. Here are guide and examples for vite and next.js.

Vite:

test vite app repo

  1. install the github-leetcode-component
npm install github-leetcode-component
  1. Add server proxy field in the vite.config.ts:

Here is an example:

// vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  server: {
    proxy: {
      "/github": {
        target: "https://github.com",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/github/, ""),
      },
      "/leetcode": {
        target: "https://leetcode.com/graphql/",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/leetcode/, ""),
      },
    },
  },
});
  1. Use it!
import "./App.css";
import { CombinationCalendar, LeetCodeCalendar } from "github-leetcode-component";

function App() {
  return (
    <>
      <CombinationCalendar
        github_username="ggamsang812"
        leetcode_username="ggamsang812"
        size="small"
      />
      <LeetCodeCalendar username="ggamsang812"/>
    </>
  );
}

export default App;

Next.js:

Project page of my personal blog test next.js app repo

  1. install the github-leetcode-component
npm install github-leetcode-component
  1. Add rewrites to the next.config.mjs (or next.config.js - whichever you have on your next.js project)
  • my blog uses next.config.js and the demo app uses next.config.mjs

Here is an example:

// next.config.mjs
/** @type {import('next').NextConfig} */
const nextConfig = {
  async rewrites() {
    return [
      {
        source: "/github/:path*",
        destination: "https://github.com/:path*", // Proxy to Backend
      },
      {
        source: "/leetcode/:path*",
        destination: "https://leetcode.com/graphql/:path*", // Proxy to Backend
      },
    ];
  },
};

export default nextConfig;
// next.config.js
module.exports = {
  async rewrites() {
    return [
      {
        source: "/github/:path*",
        destination: "https://github.com/:path*", // Proxy to Backend
      },
      {
        source: "/leetcode/:path*",
        destination: "https://leetcode.com/graphql/:path*", // Proxy to Backend
      },
    ];
  },
};
  1. Create a client side rendering component:

Here is an example:

// app/pages/Calendar.tsx
"use client";

import { GitHubCalendar, CombinationCalendar } from "github-leetcode-component";

export default function Calendar() {
  return (
    <div>
      <GitHubCalendar username="ggamsang812" size="medium" />
      <CombinationCalendar
        github_username="ggamsang812"
        leetcode_username="ggamsang812"
      />
    </div>
  );
}
  1. Use it!
// app/page.tsx
import Calendar from "./pages/Calendar";

export default function Home() {
  return (
    <div>
      <Calendar />
    </div>
  );
}

Usage

CombinationCalendar

Offers two modes of operation:

  1. Current Year Calendar: When no year is specified, the component will generate the github contribution calendar starting from one year ago up until the current date.
  2. Specific Year Calendar: When a year is provided as an input, the component will generate the github calendar for that entire year.
/**
 * Generates GitHub Contribution Calendar
 * @param {string} github_username - GitHub username
 * @param {string} leetcode_username - LeetCode username
 * @param {string} year - Optional param for year of the calendar
 * @param {string} size - Optional param for size of the calendar
 * @returns {jsx} -
 */
import { CombinationCalendar } from "github-leetcode-component";
<CombinationCalendar github_username="ggamsang812" leetcode_username="ggamsang812" />
<CombinationCalendar github_username="ggamsang812" leetcode_username="ggamsang812" size="small"/>

example: CombinationCalendar_example

GitHubCalendar

Offers two modes of operation:

  1. Current Year Calendar: When no year is specified, the component will generate the github contribution calendar starting from one year ago up until the current date.
  2. Specific Year Calendar: When a year is provided as an input, the component will generate the github calendar for that entire year.
/**
 * Generates GitHub Contribution Calendar
 * @param {string} username - GitHub username
 * @param {string} year - Optional param for year of the calendar
 * @param {string} size - Optional param for size of the calendar
 * @returns {jsx} -
 */
import { GitHubCalendar } from "github-leetcode-component";
<GitHubCalendar username="ggamsang812" />
<GitHubCalendar username="ggamsang812" year="2024" />
<GitHubCalendar username="ggamsang812" size="medium" />

example: GitHubCalendar_example

LeetCodeCalendar

Offers two modes of operation:

  1. Current Year Calendar: When no year is specified, the component will generate the leetcode submission calendar starting from one year ago up until the current date.
  2. Specific Year Calendar: When a year is provided as an input, the component will generate the leetcode calendar for that entire year.
/**
 * Generates LeetCode Submissions Calendar
 * @param {string} username - LeetCode username
 * @param {string} year - Optional param for year of the calendar
 * @param {string} size - Optional param for size of the calendar
 * @returns {jsx} -
 */
import { LeetCodeCalendar } from "github-leetcode-component";
<LeetCodeCalendar username="ggamsang812" />
<LeetCodeCalendar username="ggamsang812" year="2024" />
<LeetCodeCalendar username="ggamsang812" size="MeDiUm" />

example: LeetCodeCalendar_example

GetGitHubData

Performs an HTTP request to fetch user data, then converts the fetched data into a stringified HTML format and returns it. Offers two modes of operation:

  1. Current Year Data: When no year is specified, the component will generate the stringified HTML of user data starting from one year ago up until the current date.
  2. Specific Year Data: When a year is provided as an input, the component will generate the leetcode calendar for that entire year.
/**
 * Fetch GitHub user data
 * @param {string} username - LeetCode username
 * @param {string} year - Optional param for specific year data
 * @returns {string} - stringified fetched GitHub data
 */
import { GetGitHubData } from "github-leetcode-component";
<GetGitHubData username="ggamsang812" />
<GetGitHubData username="ggamsang812" year="2024" />

example: GetGitHubData_example

GetLeetCodeData

Performs an HTTP request with GraphQL query to fetch user data, then converts the fetched data into a stringified HTML format and returns it. Offers two modes of operation:

  1. Current Year Data: When no year is specified, the component will generate the stringified HTML of user data starting from one year ago up until the current date.
  2. Specific Year Data: When a year is provided as an input, the component will generate the leetcode calendar for that entire year.
/**
 * Fetch LeetCode user data
 * @param {string} username - LeetCode username
 * @param {string} year - Optional param for specific year data
 * @returns {string} - stringified fetched Leetcode data
 */
import { GetLeetCodeData } from "github-leetcode-component";
<GetLeetCodeData username="ggamsang812" />
<GetLeetCodeData username="ggamsang812" year="2024" />

example: GetLeetCodeData_example

License

MIT