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 🙏

© 2026 – Pkg Stats / Ryan Hefner

github-code

v0.2.1

Published

Custom element for embedding GitHub source files with syntax highlighting

Readme

github-code

npm version bundle size License highlight.js

A web component for displaying GitHub files with syntax highlighting.

Demo

See the live demo: github-code Demo

Demo page SS

Installation

Include the script in your HTML:

<script type="module" src="https://cdn.jsdelivr.net/npm/github-code/dist/github-code.min.js"></script>

Or install via npm:

npm install github-code

Usage

Single File

<github-code
  file="https://github.com/owner/repo/blob/main/src/example.ts">
</github-code>

Multiple Files (Tabbed)

Comma-separate URLs to display files as tabs:

<github-code
  file="https://github.com/owner/repo/blob/main/src/app.ts,
        https://github.com/owner/repo/blob/main/src/utils.ts">
</github-code>

Attributes

| Attribute | Default | Description | |-----------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | file | (required) | GitHub blob URL(s). Comma-separated for multiple files. | | theme | auto | light, dark, or auto (follows system preference) | | highlightjs-url | <empty> | If omitted, uses global window.hljs if available, otherwise uses jsDelivr CDNCustom highlight.js URL. Omit to use global window.hljs if available. |

URL Format

URLs must be GitHub blob URLs:

https://github.com/{owner}/{repo}/blob/{branch|commit}/{path}

Use the permalink of a file:

permalink in Github

Features

  • Syntax highlighting via highlight.js (auto-detected language)
  • Lazy loading (content fetched on demand)
  • Keyboard-accessible tabs (Arrow keys, Home, End)
  • CSP-compliant (no inline styles)
  • Shadow DOM encapsulation

Advanced Usage

Custom highlight.js

By default, highlight.js is loaded from jsDelivr CDN. You can provide your own:

<github-code
  file="https://github.com/owner/repo/blob/main/file.ts"
  highlightjs-url="https://your-cdn.com/highlight.min.js">
</github-code>

If highlight.js is already loaded globally (window.hljs), the component will use it automatically.

Debugging

Access component info via the static property:

console.log(GitHubCode.info);
// { version: "0.2.0", highlightjsUrl: "...", highlightjsSource: "cdn-default" }

Troubleshooting

Content Security Policy (CSP)

If using the default CDN and you have a strict CSP, add:

script-src https://cdn.jsdelivr.net;

Or use highlightjs-url to load from an allowed source.

Development

npm install
npm run dev            # Watch mode
npm run test:ci        # Full CI check (lint + typecheck + build + tests)
npm run build          # Build dist files

License

MIT