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-calendar-parser

v1.2.2

Published

Parses the GitHub contributions calendar SVG code into JSON.

Downloads

498

Readme

github-calendar-parser

Support me on Patreon Buy me a book PayPal Ask me anything Version Downloads Get help on Codementor

Parses the GitHub contributions calendar SVG code into JSON.

:cloud: Installation

# Using npm
npm install --save github-calendar-parser

# Using yarn
yarn add github-calendar-parser

:clipboard: Example

const parse = require("github-calendar-parser");

var svg = `
        <svg width="722" height="112" class="js-calendar-graph-svg">
            <g transform="translate(10, 20)" data-hydro-click="{&quot;event_type&quot;:&quot;user_profile.click&quot;,&quot;payload&quot;:{&quot;profile_user_id&quot;:2864371,&quot;target&quot;:&quot;CONTRIBUTION_CALENDAR_SQUARE&quot;,&quot;user_id&quot;:null,&quot;originating_url&quot;:&quot;https://github.com/users/IonicaBizau/contributions&quot;}}" data-hydro-click-hmac="c29bb84527b62dafc7ab4208ed2db21ea4195839d541da829d109a8d172bee42">
                <g transform="translate(0, 0)">
                    <rect width="10" height="10" x="14" y="0" class="ContributionCalendar-day" data-date="2022-01-09" data-level="0" rx="2" ry="2">2 contributions on January 9, 2022</rect>
                    <rect width="10" height="10" x="14" y="13" class="ContributionCalendar-day" data-date="2022-01-10" data-level="0" rx="2" ry="2">15 contributions on January 10, 2022</rect>
                    <rect width="10" height="10" x="14" y="26" class="ContributionCalendar-day" data-date="2022-01-11" data-level="0" rx="2" ry="2">No contributions on January 11, 2022</rect>
                    <rect width="10" height="10" x="14" y="39" class="ContributionCalendar-day" data-date="2022-01-12" data-level="3" rx="2" ry="2">45 contributions on January 12, 2022</rect>
                    <rect width="10" height="10" x="14" y="52" class="ContributionCalendar-day" data-date="2022-01-13" data-level="1" rx="2" ry="2">2 contributions on January 13, 2022</rect>
                    <rect width="10" height="10" x="14" y="65" class="ContributionCalendar-day" data-date="2022-01-14" data-level="0" rx="2" ry="2">No contributions on January 14, 2022</rect>
                    <rect width="10" height="10" x="14" y="78" class="ContributionCalendar-day" data-date="2022-01-15" data-level="0" rx="2" ry="2">1 contribution on January 15, 2022</rect>
                </g>
                <g transform="translate(14, 0)">
                    <rect width="10" height="10" x="13" y="0" class="ContributionCalendar-day" data-date="2022-01-16" data-level="1" rx="2" ry="2">6 contributions on January 16, 2022</rect>
                    <rect width="10" height="10" x="13" y="13" class="ContributionCalendar-day" data-date="2022-01-17" data-level="0" rx="2" ry="2">No contributions on January 17, 2022</rect>
                    <rect width="10" height="10" x="13" y="26" class="ContributionCalendar-day" data-date="2022-01-18" data-level="1" rx="2" ry="2">2 contributions on January 18, 2022</rect>
                    <rect width="10" height="10" x="13" y="39" class="ContributionCalendar-day" data-date="2022-01-19" data-level="0" rx="2" ry="2">No contributions on January 19, 2022</rect>
                    <rect width="10" height="10" x="13" y="52" class="ContributionCalendar-day" data-date="2022-01-20" data-level="1" rx="2" ry="2">4 contributions on January 20, 2022</rect>
                    <rect width="10" height="10" x="13" y="65" class="ContributionCalendar-day" data-date="2022-01-21" data-level="1" rx="2" ry="2">1 contribution on January 21, 2022</rect>
                    <rect width="10" height="10" x="13" y="78" class="ContributionCalendar-day" data-date="2022-01-22" data-level="0" rx="2" ry="2">No contributions on January 22, 2022</rect>
                </g>
            </g>
        </svg>
`;

console.log(parse(svg))

// {
  // last_year: 78,
  // longest_streak: 2,
  // longest_streak_range: [ 2022-01-09T00:00:00.000Z, 2022-01-10T00:00:00.000Z ],
  // current_streak: 0,
  // current_streak_range: [ 2022-01-20T00:00:00.000Z, 2022-01-21T00:00:00.000Z ],
  // longest_break: 1,
  // longest_break_range: [ 2022-01-11T00:00:00.000Z, 2022-01-11T00:00:00.000Z ],
  // current_break: 1,
  // current_break_range: [ 2022-01-22T00:00:00.000Z, 2022-01-22T00:00:00.000Z ],
  // weeks: [
    // [
      // [Object], [Object],
      // [Object], [Object],
      // [Object], [Object],
      // [Object]
    // ]
  // ],
  // days: [
    // {
      // fill: '#eee',
      // date: 2022-01-09T00:00:00.000Z,
      // count: 2,
      // level: '0'
    // },
    // {
      // fill: '#eee',
      // date: 2022-01-10T00:00:00.000Z,
      // count: 15,
      // level: '0'
    // },
    // ...
    // {
      // fill: '#d6e685',
      // date: 2022-01-21T00:00:00.000Z,
      // count: 1,
      // level: '1'
    // },
    // {
      // fill: '#eee',
      // date: 2022-01-22T00:00:00.000Z,
      // count: 0,
      // level: '0'
    // }
  // ],
  // last_contributed: 2022-01-21T00:00:00.000Z
// }

:question: Get Help

There are few ways to get help:

  1. Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
  2. For bug reports and feature requests, open issues. :bug:
  3. For direct and quick help, you can use Codementor. :rocket:

:memo: Documentation

parseGitHubCalendarSvg(input)

Parses the SVG input (as string).

Params

  • String input: The SVG code of the contributions calendar.

Return

  • Object An object containing:
  • last_year (Number): The total contributions in the last year.
  • longest_streak (Number): The longest streak.
  • longest_streak_range (Array): An array of two date objects representing the date range.
  • current_streak (Number): The current streak.
  • current_streak_range (Array): An array of two date objects representing the date range.
  • days (Array): An array of day objects:
    • fill (String): The hex color.
    • date (Date): The day date.
    • count (Number): The number of commits.
    • level (Number): A number between 0 and 4 (inclusive) representing the contribution level (more commits, higher value).
  • weeks (Array): The day objects grouped by weeks (arrays).
  • last_contributed (Date): The last contribution date.

:yum: How to contribute

Have an idea? Found a bug? See how to contribute.

:sparkling_heart: Support my projects

I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).

However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:

  • Starring and sharing the projects you like :rocket:

  • Buy me a book—I love books! I will remember you after years if you buy me one. :grin: :book:

  • PayPal—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea:

  • Support me on Patreon—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).

  • Bitcoin—You can send me bitcoins at this address (or scanning the code below): 1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6

Thanks! :heart:

:dizzy: Where is this library used?

If you are using this library in one of your projects, add it in this list. :sparkles:

  • github-calendar
  • @xwl7001/react-github-calendar
  • react-github-calendar-x

:scroll: License

MIT © Ionică Bizău