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

@tgwf/gridintensity-polyfill

v0.0.7

Published

A polyfill to for carbon-aware design. Adds a gridintensity API to user agents.

Downloads

11

Readme

Grid intensity polyfill

A polyfill, to build awareness of carbon intensity into javascript programs - move your code through time and space for greener digital products.

The dream is for this to be built into the browser, so we learn as web makers to do the right thing by default, and incorporate carbon-aware practices into how we work. Partly inspired by the work by Michelle Thorne and Yulia Startsev on Firefox Eco Mode concepts and sustainablity engineering, and by Lucia Ye's recent work on Onlign OS, and David Sykes work on the energy onion model, and Auke Hoekste's work on energy systems as ecosystems

Usage

import GridIntensity from '@tgwf/grid-intensity-polyfill'

// initialise
grid = GridIntensity()

const carbonIndex = await grid.getCarbonIndex()

if (carbonIndex == 'low')  {
  // Huzzah! Energy is cheap! The wind is blowing and the sun is out,
  // the cost of energy is low, and the grid is also greener
  // than normal. Do network and CPU intensive stuff

  loadrichImages()

  await Promise.all([
    doExpensiveOperation(), preLoadVideo()
  ])

} else {
  // Eep - our grid is relying on more fossil fuels than usual, so
  // let's defer work til later, and serve a lighter weight experience
  // by default
  loadLiteImages()

  // if we have web workers available, let give them a job to do when
  // grid intensity is lower, so when the user comes back they have the
  // richer experience
  queueJobforWorker([
    doExpensiveOperation
    fetchVideo
  ])
}

Quick demo

There's a public demo in the github repo, to try this out. Run these commands after checking the code to see it

npm run build
cp ./lib/gridintensity.browser.js ./lib/gridintensity.browser.min.js ./public
npx run serve public

Background

We know that the internet runs on electricity. That electricity comes from a mix of energy sources, including wind and solar, nuclear power, biomass, fossil gas, oil and coal and so on,

We call this the fuel mix, and this fuel mix can impact on the carbon intensity of your code.

Move your code through time and space

Because the fuel mix will be different depending when and where you run your code, you can influence the carbon intensity of the code you write by moving it through time and space - either by making it run when the grid is greener, or making it run where it's greener, like a CDN running on green power.

This API is designed to make that easier. It pulls data from open data sources, about the predicted carbon intensity of energy on the grid where code is run, and presents an object you can query, so you can make an application or website serve a different experience to end users based on the carbon intensity.

TODO

This is very incomplete. Sorry about that. I hope this gives an idea of where you can help if you're interested.

  • [ ] Add support for API providers beyond the UK national grid (Electricity Map would be WONDERFUL)
  • [x] Add a 24 hour forward looking check, so there's less need to hit a single API endpoint. This is how forward markets for energy work for reals anyway.
  • [ ] Add geo support to either use geolocation features in a browser, or some kind of educated guesses serverside so we use the correct country for grid intensity
  • [ ] Write post to explain the idea in more detail
  • [ ] Flesh out issues, and guidelines for contribution.
  • [ ] Figure out how to get this into the the green web browser extension, to demonstrate how carbon awareness should be part of browsers by default. user-agents of change!
  • [x] Publish to NPM, and generate the compiled regular js into lib
  • [ ] For browsers, include check for the kind of connection on a webpage, using the polyfill currently listed in the package.json