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

@vnphanquang/green-check

v1.0.3

Published

Custom element to render green check badge from the Green Web Foundation

Downloads

9

Readme

Green Web Badge as Custom Element

green badge example

Introduction

This library defines an HTML Custom Element to check and display a badge if your site passes the Green Web Check from The Green Web Foundation.

See https://github.com/thegreenwebfoundation/admin-portal/issues/234 for the original discussion that led to this library.

1. Installation

Install @vnphanquang/green-check with your package manager of choice (recommended):

pnpm add @vnphanquang/green-check
npm install @vnphanquang/green-check
yarn add @vnphanquang/green-check

[!NOTE] This method is recommended as it allows the green-check module to be part of your dependency tree and build process, making it easier to integrate into framework contexts, track version, and deploy with high availability (you are effectively self-hosting the module).

Alternatively, you may load the module via a CDN by adding to importmap in your html:

<script type="importmap">
  {
    "imports": {
      "@vnphanquang/green-check": "https://cdn.jsdelivr.net/npm/@vnphanquang/green-check/dist/index.js"
    }
  }
</script>

2. Register the Custom Element

Import GreenCheck and register <green-check> using the global customElements, where applicable:

import { GreenCheck } from '@vnphanquang/green-check';

// later where applicable
customElements.define('green-check', GreenCheck);

Optionally, you may find dynamically importing the module to be more efficient depending on your use case:

async function loadGreenCheck() {
  const { GreenCheck } = await import('@vnphanquang/green-check');
  customElements.define('green-check', GreenCheck);
}

// later
loadGreenCheck();

3. Using the Custom Element

Use <green-check> where applicable with the hostname attribute as the host name of your site. If not provided hostname will default to window.location.hostname, i.e current site.

<green-check hostname="www.yourdomain.xyz">
  <img
    src="https://cdn.jsdelivr.net/npm/@vnphanquang/green-check/dist/fallback.svg"
    width="200"
    height="95"
    alt="Fallback blank greencheck badge from The Green Web Foundation, in case JS is not (yet) available"
  />
</green-check>

Customizing Colors

Colors of the badge can be customized by providing the following CSS custom properties (default values are shown):

<green-check hostname="www.yourdomain.xyz">
  <!-- [...truncated fallback image...] -->
</green-check>

<style>
  green-check {
    --green-check-fg: #000;
    --green-check-bg: linear-gradient(45deg, #06ff06 4%, #dffcdd 24%, #fff 32%);
  }
</style>

This is helpful to ensure consistency with your site's color scheme or to support dark mode.

Development

Prerequisites

| Dependency | Installation | Description | | ---------- | --------------------------------------- | ------------------------------- | | node | recommended via volta | | | pnpm | follow guide on website | alternative to npm and yarn |

See [package.json] for preferred versions of node and pnpm. At project root, run:

Getting Started

This project is built with Vite. Start by installing dependencies

pnpm install

And run development server

pnpm dev

Todos

  • [ ] Add tests