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

@greenweb/grid-aware-websites

v0.1.1

Published

A library to enable developers to implement grid awareness in their websites

Downloads

143

Readme

Grid-aware Websites

[!CAUTION] This repository is currently under active development. It is not advised that this code be used in any critical production systems.

Installing this library

You can install this library using NPM.

npm install @greenweb/grid-aware-websites

You can now import this library into a JavaScript project like this:

import { fetchGridIntensity } from "grid-aware-websites";

Working with this library

This library currently uses the Electricity Maps API to fetch current grid data for regions around the World.

We hope to add other data sources at a later time.

You will need to have an Electricity Maps API key in order to use this library. You will probably want to set this as a private environment variable in your project. You can obtain an API key here: https://api-portal.electricitymaps.com/

Using grid intensity data

You can choose to use grid intensity data to determine if grid-aware changes should be made. In this approach, the current grid intensity (fetched from Electricity Maps) is compared with the annual average grid intensity data (available in CO2.js). If the grid intensity is higher than the annual average, gridAware: true will be returned indicating that grid-aware changes should be applied. Otherwise gridAware: false will be returned.

import { gridAwareCO2e } from "grid-aware-websites";

const zone = "DE"; // The zone ID of the region you'd like to get grid intensity data for
const apiKey = "you_api_key";
const gridData = await gridAwareCO2e(zone, apiKey);

The gridAwareCO2e() function will return either:

Success

{
    "status": "success",
    "gridAware": boolean, // A flag indicating if grid aware changes should be applied
    "region": "DE" // The zone ID of the region you'd like to get grid intensity data for
    "data" {
        "carbonIntensity": number, // The current grid intensity fetched from Electricity Maps
        "averageIntensity": number // The annual average grid intensity for the zone being checked taken from CO2.js
    }
}

Error

{
    "status": "error",
    "message": "some error message",
    "details": {
        // ... an object with additional information about the error, if available.
    }
}

Using grid power breakdown

Alternately, you may choose to use the current power consumption breakdown of a regional grid to determine if grid-aware changes should be applied. With this approach, developers can specify if they wish to use data for all low-carbon energy (renewables + nuclear), or only renewable energy. The default mode is using only renewable energy.

A minimum threshold can also be specified. This is the minimum percentage of renewable/low-carbon energy being used by the grid. By default this value is set to 50 percent - meaning that at least 50% of the energy on the grid must come from renewables/low-carbon sources otherwise the gridAware: true flag will be returned.

import { gridAwarePower } from "grid-aware-websites";

const zone = "DE"; // The zone ID of the region you'd like to get grid intensity data for
const apiKey = "you_api_key";

const options = {
  mode: "renewables", // The energy data we want to use - either renewables or low-carbon.
  minimumPercentage: 95, // The minimum percentage of the choosen energy type before grid-awareness should be triggered.
};

const gridData = await gridAwarePower(zone, apiKey, options);

The gridAwarePower() function will return either:

Success

{
    "status": "success",
    "gridAware": boolean, // A flag indicating if grid aware changes should be applied
    "region": "DE" // The zone ID of the region you'd like to get grid intensity data for
    "data": {
          "mode": "renewables", // The energy source being used
          "minimumPercentage": 95, // The minimum percentage for that energy source before grid-awareness is set to true,
          "low-carbon percentage": number, // Data from Electricity Maps for the current low-carbon (renewables + nuclear) percentage,
          "renewable percentage": number, // Data from Electricity Maps for the current renewables percentage
        },
}

Error

{
    "status": "error",
    "message": "some error message",
    "details": {
        // ... an object with additional information about the error, if available.
    }
}

Using this projects

This library can be used anywhere that runs server-side JavaScript and can make outbound fetch requests. Currently, we have limited documentation on how to use this project with:

You can also see the Grid-aware Websites Demo repository which has some more detailed implementation code that can be referenced.

To do:

  • [ ] Add some text explaining the project (or linking to an explainer).
  • [ ] Add proper steps to install this project using NPM and/or Yarn.