Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork64
An npm module for accessing the green web API, and estimating the carbon emissions from using digital services
License
thegreenwebfoundation/co2.js
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
One day, the internet will be powered by renewable energy. Until that day comes, there’ll be a CO2 cost that comes with every byte of data that’s uploaded or downloaded. By being able to calculate these emissions, developers can be empowered to create more efficient, lower carbon apps, websites, and software.
CO2.js is a JavaScript library that enables developers a way to estimate the emissions related to use of their apps, websites, and software.
Being able to estimate the CO2 emissions associated with digital activities can be of benefit to both developers and users.
Internally, you may want to use this library to create acarbon budget for your site or app. It is also useful for inclusion in dashboards and monitoring tools.
For user facing applications, CO2.js could be used to check & block the uploading of carbon intensive files. Or, to present users with information about the carbon impact of their online activities (such as browsing a website).
The above are just a few examples of the many and varied ways CO2.js can be applied to provide carbon estimates for data transfer. If you’re using CO2.js in production we’d love to hear how!Contact us via our website.
You can install CO2.js as a dependency for your projects using NPM.
npm install @tgwf/co2
You can import the CO2.js library into projects using esm.sh.
importtgwffrom"https://esm.sh/@tgwf/co2@latest";
You can get the latest version of CO2.js using one of the content delivery networks below.
You can find the package athttps://www.jsdelivr.com/package/npm/@tgwf/co2.
- CommonJS compatible build
https://cdn.jsdelivr.net/npm/@tgwf/co2@latest/dist/cjs/index-node.min.js - ES Modules compatible build
https://cdn.jsdelivr.net/npm/@tgwf/co2@latest/dist/esm/index.js - IIFE compatible build
https://cdn.jsdelivr.net/npm/@tgwf/co2@latest/dist/iife/index.js
You can find the package athttps://unpkg.com/browse/@tgwf/co2@latest/.
- CommonJS compatible build
https://unpkg.com/@tgwf/co2@latest/dist/cjs/index-node.min.js - ES Modules compatible build
https://unpkg.com/@tgwf/co2@latest/dist/esm/index.js - IIFE compatible build
https://unpkg.com/@tgwf/co2@latest/dist/iife/index.js
You can also build the CO2.js library from the source code. To do this:
Go to theCO2.js repository on GitHub.
Clone or fork the repository.
Navigate to the folder on your machine and run
npm run buildin your terminal.Once the build has finished running, you will find a
/distfolder has been created. Inside you can find:dist/cjs- A CommonJS compatible build.dist/esm- An ES Modules compatible build.dist/iife- An Immediately Invoked Function Expression (IIFE) version of the library.
Type definitions for CO2.js arepublished in the DefinitelyTyped project, and areavailable on NPM at@types/tgwf__co2.
If you want to use type definitions in your project, they should be installed as a devDependency.
npm install --dev @types/tgwf__co2
CO2.js includes yearly average grid intensity data fromEmber, as well as marginal intensity data from theUNFCCC (United Nations Framework Convention on Climate Change). You can find the data in JSON and CommonJS Module format in thedata/output folder.
You can import annual, country-level marginal or average grid intensity data into your projects directly from CO2.js. For example, if we wanted to use the average grid intensity for Australia in our project, we could use the code below:
import{averageIntensity}from"@tgwf/co2";const{ data}=averageIntensity;const{AUS}=data;console.log({AUS});
All countries are represented by their respectiveAlpha-3 ISO country code.
We usenp to publish new versions of this library to NPM. To do this:
- First login to NPM by running the
npm logincommand in your terminal. - Then run
npx np <VERSION>. npwill run several automated steps to publish the new package to NPM.- If everything runs successfully, you can then add release notes to GitHub for the newly published package.
CO2.js releases will be communicated through the following channels:
| Channel | Minor Release (0.xx) | Patch Release (0.xx.x) |
|---|---|---|
| Github | ✅ | ✅ |
| Green Web Foundation website | ✅ | ❌ |
| W3C Slack Sustainability Channel | ✅ | ❌ |
| ClimateAction.Tech Slack | ✅ | ❌ |
| Green Web Foundation LinkedIn Account | ✅ | ❌ |
The code for CO2.js is licensed Apache 2.0. (What does this mean?)
The average carbon intensity data from Ember is published under the Creative Commons ShareAlike Attribution Licence (CC BY-SA 4.0). (What does this mean?)
The marginal intensity data is published by the Green Web Foundation, under the Creative Commons ShareAlike Attribution Licence (CC BY-SA 4.0). (What does this mean?)
See LICENCE for more.
To contribute changes back to this project, please follow the steps outlined in theCONTRIBUTING.md file in this repository.
About
An npm module for accessing the green web API, and estimating the carbon emissions from using digital services
Topics
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.