UNPKG

13.3 kBMarkdownView Raw
1# CO2.js
2
3<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
4[![All Contributors](https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square)](#contributors-)
5<!-- ALL-CONTRIBUTORS-BADGE:END -->
6
7<img src="https://github.com/thegreenwebfoundation/co2.js/actions/workflows/unittests.yml/badge.svg" />
8
9One 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.
10
11## [Documentation](https://developers.thegreenwebfoundation.org/co2js/overview/) | [Changelog](/CHANGELOG.md) | [Roadmap](https://github.com/orgs/thegreenwebfoundation/projects/3/views/1)
12
13## What is CO2.js?
14
15CO2.js is a JavaScript library that enables developers a way to estimate the emissions related to use of their apps, websites, and software.
16
17## Why use it?
18
19Being able to estimate the CO2 emissions associated with digital activities can be of benefit to both developers and users.
20
21Internally, you may want to use this library to create a _carbon budget_ for your site or app. It is also useful for inclusion in dashboards and monitoring tools.
22
23For 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).
24
25The above a 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](https://www.thegreenwebfoundation.org/support-form/) via our website.
26
27## Installation
28
29### Using NPM
30
31You can install CO2.js as a dependency for your projects using NPM.
32
33```bash
34npm install @tgwf/co2
35```
36
37### Using Skypack
38
39You can import the CO2.js library into projects using Skypack.
40
41```js
42import tgwf from "https://cdn.skypack.dev/@tgwf/co2";
43```
44
45## Using a JS CDN
46
47You can get the latest version of CO2.js using one of the content delivery networks below.
48
49### jsDelivr
50
51You can find the package at [https://www.jsdelivr.com/package/npm/@tgwf/co2](https://www.jsdelivr.com/package/npm/@tgwf/co2).
52
53- CommonJS compatible build `https://cdn.jsdelivr.net/npm/@tgwf/co2@latest/dist/cjs/index-node.min.js`
54- ES Modules compatible build `https://cdn.jsdelivr.net/npm/@tgwf/co2@latest/dist/esm/index.js`
55- IIFE compatible build `https://cdn.jsdelivr.net/npm/@tgwf/co2@latest/dist/iife/index.js`
56
57### Unpkgd
58
59You can find the package at [https://unpkg.com/browse/@tgwf/co2@latest/](https://unpkg.com/browse/@tgwf/co2@latest/).
60
61- CommonJS compatible build `https://unpkg.com/@tgwf/co2@latest/dist/cjs/index-node.min.js`
62- ES Modules compatible build `https://unpkg.com/@tgwf/co2@latest/dist/esm/index.js`
63- IIFE compatible build `https://unpkg.com/@tgwf/co2@latest/dist/iife/index.js`
64
65### Build it yourself
66
67You can also build the CO2.js library from the source code. To do this:
68
691. Go to the [CO2.js repository](https://github.com/thegreenwebfoundation/co2.js) on GitHub.
701. Clone or fork the repository.
711. Navigate to the folder on your machine and run `npm run build` in your terminal.
721. Once the build has finished running, you will find a `/dist` folder has been created. Inside you can find:
73
74 - `dist/cjs` - A CommonJS compatible build.
75 - `dist/esm` - An ES Modules compatible build.
76 - `dist/iife` - An Immediately Invoked Function Expression (IIFE) version of the library.
77
78## TypeScript support
79
80Type definitions for CO2.js are [published in the DefinitelyTyped project](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/tgwf__co2), and are [available on NPM](https://www.npmjs.com/package/@types/tgwf__co2) at `@types/tgwf__co2`.
81
82If you want to use type definitions in your project, they should be installed as a devDependency.
83
84`npm install --dev @types/tgwf__co2`
85
86## Marginal and average emissions intensity data
87
88CO2.js includes yearly average grid intensity data from [Ember](https://ember-climate.org/data/data-explorer/), as well as marginal intensity data from the [UNFCCC](https://unfccc.int/) (United Nations Framework Convention on Climate Change). You can find the data in JSON and CommonJS Module format in the `data/output` folder.
89
90### Using emissions intensity data
91
92You 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:
93
94```js
95import { averageIntensity } from "@tgwf/co2";
96const { data } = averageIntensity;
97const { AUS } = data;
98console.log({ AUS });
99```
100
101All countries are represented by their respective [Alpha-3 ISO country code](https://www.iso.org/obp/ui/#search).
102
103## Publishing to NPM
104
105We use [`np`](https://www.npmjs.com/package/np) to publish new versions of this library to NPM. To do this:
106
1071. First login to NPM by running the `npm login` command in your terminal.
1082. Then run `npx np <VERSION>`.
1093. `np` will run several automated steps to publish the new package to NPM.
1104. If everything runs successfully, you can then add release notes to GitHub for the newly published package.
111
112## Release communication
113
114CO2.js releases will be communicated through the following channels:
115
116| Channel | Minor Release (0.xx) | Patch Release (0.xx.x) |
117| ----------------------------------------------------------------------------------------------- | -------------------- | ---------------------- |
118| [Github](https://github.com/thegreenwebfoundation/co2.js/releases) | ✅ | ✅ |
119| [Green Web Foundation website](https://www.thegreenwebfoundation.org/co2-js/#releases) | ✅ | ❌ |
120| W3C Slack Sustainability Channel | ✅ | ❌ |
121| ClimateAction.Tech Slack | ✅ | ❌ |
122| [Green Web Foundation LinkedIn Account](https://www.linkedin.com/company/green-web-foundation/) | ✅ | ❌ |
123
124## Licenses
125
126The code for CO2.js is licensed Apache 2.0. ([What does this mean?](<https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)>))
127
128The average carbon intensity data from Ember is published under the Creative Commons ShareAlike Attribution Licence ([CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)). ([What does this mean?](https://www.tldrlegal.com/license/creative-commons-attribution-share-alike-cc-sa))
129
130The marginal intensity data is published by the Green Web Foundation, under the Creative Commons ShareAlike Attribution Licence ([CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)). ([What does this mean?](https://www.tldrlegal.com/license/creative-commons-attribution-share-alike-cc-sa))
131
132See LICENCE for more.
133
134## Contributors
135
136<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
137<!-- prettier-ignore-start -->
138<!-- markdownlint-disable -->
139<table>
140 <tbody>
141 <tr>
142 <td align="center" valign="top" width="14.28%"><a href="https://github.com/mrchrisadams"><img src="https://avatars.githubusercontent.com/u/17906?v=4?s=100" width="100px;" alt="Chris Adams"/><br /><sub><b>Chris Adams</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=mrchrisadams" title="Code">💻</a></td>
143 <td align="center" valign="top" width="14.28%"><a href="https://www.fershad.com/"><img src="https://avatars.githubusercontent.com/u/27988517?v=4?s=100" width="100px;" alt="fershad"/><br /><sub><b>fershad</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=fershad" title="Code">💻</a> <a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=fershad" title="Documentation">📖</a> <a href="#maintenance-fershad" title="Maintenance">🚧</a></td>
144 <td align="center" valign="top" width="14.28%"><a href="https://www.peterhedenskog.com/"><img src="https://avatars.githubusercontent.com/u/540757?v=4?s=100" width="100px;" alt="Peter Hedenskog"/><br /><sub><b>Peter Hedenskog</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=soulgalore" title="Code">💻</a></td>
145 <td align="center" valign="top" width="14.28%"><a href="https://www.drydenwilliams.co.uk/"><img src="https://avatars.githubusercontent.com/u/4403089?v=4?s=100" width="100px;" alt="Dryden"/><br /><sub><b>Dryden</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=drydenwilliams" title="Code">💻</a></td>
146 <td align="center" valign="top" width="14.28%"><a href="https://evanhahn.com/"><img src="https://avatars.githubusercontent.com/u/777712?v=4?s=100" width="100px;" alt="Evan Hahn"/><br /><sub><b>Evan Hahn</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=EvanHahn" title="Code">💻</a> <a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=EvanHahn" title="Tests">⚠️</a></td>
147 <td align="center" valign="top" width="14.28%"><a href="https://github.com/PrathumP"><img src="https://avatars.githubusercontent.com/u/115390367?v=4?s=100" width="100px;" alt="Prathum Pandey"/><br /><sub><b>Prathum Pandey</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/issues?q=author%3APrathumP" title="Bug reports">🐛</a> <a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=PrathumP" title="Code">💻</a></td>
148 <td align="center" valign="top" width="14.28%"><a href="https://github.com/Fdawgs"><img src="https://avatars.githubusercontent.com/u/43814140?v=4?s=100" width="100px;" alt="Frazer Smith"/><br /><sub><b>Frazer Smith</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=Fdawgs" title="Code">💻</a> <a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=Fdawgs" title="Tests">⚠️</a></td>
149 </tr>
150 <tr>
151 <td align="center" valign="top" width="14.28%"><a href="https://github.com/hamishfagg"><img src="https://avatars.githubusercontent.com/u/895845?v=4?s=100" width="100px;" alt="Hamish Fagg"/><br /><sub><b>Hamish Fagg</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=hamishfagg" title="Code">💻</a></td>
152 <td align="center" valign="top" width="14.28%"><a href="http://portfolio.toolness.org/"><img src="https://avatars.githubusercontent.com/u/124687?v=4?s=100" width="100px;" alt="Atul Varma"/><br /><sub><b>Atul Varma</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=toolness" title="Code">💻</a></td>
153 <td align="center" valign="top" width="14.28%"><a href="https://www.intersectionalenvironmentalist.com/"><img src="https://avatars.githubusercontent.com/u/1530684?v=4?s=100" width="100px;" alt="Piper"/><br /><sub><b>Piper</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=piperchester" title="Code">💻</a></td>
154 <td align="center" valign="top" width="14.28%"><a href="https://vasquezruiz.com/"><img src="https://avatars.githubusercontent.com/u/108420?v=4?s=100" width="100px;" alt="Raymundo Vásquez Ruiz"/><br /><sub><b>Raymundo Vásquez Ruiz</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=raymundovr" title="Code">💻</a></td>
155 <td align="center" valign="top" width="14.28%"><a href="https://greengumption.co.uk/"><img src="https://avatars.githubusercontent.com/u/26165947?v=4?s=100" width="100px;" alt="JamieB"/><br /><sub><b>JamieB</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=JamieBeevor" title="Code">💻</a></td>
156 <td align="center" valign="top" width="14.28%"><a href="https://github.com/p-gerard"><img src="https://avatars.githubusercontent.com/u/97036756?v=4?s=100" width="100px;" alt="p-gerard"/><br /><sub><b>p-gerard</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/issues?q=author%3Ap-gerard" title="Bug reports">🐛</a> <a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=p-gerard" title="Code">💻</a></td>
157 <td align="center" valign="top" width="14.28%"><a href="https://github.com/sfishel18"><img src="https://avatars.githubusercontent.com/u/294695?v=4?s=100" width="100px;" alt="Simon Fishel"/><br /><sub><b>Simon Fishel</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=sfishel18" title="Code">💻</a></td>
158 </tr>
159 </tbody>
160</table>
161
162<!-- markdownlint-restore -->
163<!-- prettier-ignore-end -->
164
165<!-- ALL-CONTRIBUTORS-LIST:END -->
166<!-- prettier-ignore-start -->
167<!-- markdownlint-disable -->
168
169<!-- markdownlint-restore -->
170<!-- prettier-ignore-end -->
171
172<!-- ALL-CONTRIBUTORS-LIST:END -->