@tgwf/co2 0.14.0 → 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +183 -44
  2. package/README.md +70 -16
  3. package/dist/cjs/co2.js +14 -22
  4. package/dist/cjs/co2.js.map +2 -2
  5. package/dist/cjs/data/average-intensities.min.js +1 -1
  6. package/dist/cjs/data/average-intensities.min.js.map +2 -2
  7. package/dist/cjs/helpers/index.js +10 -6
  8. package/dist/cjs/helpers/index.js.map +2 -2
  9. package/dist/cjs/hosting-api.js +12 -7
  10. package/dist/cjs/hosting-api.js.map +2 -2
  11. package/dist/cjs/hosting-node.js +10 -9
  12. package/dist/cjs/hosting-node.js.map +2 -2
  13. package/dist/cjs/hosting.js +2 -2
  14. package/dist/cjs/hosting.js.map +2 -2
  15. package/dist/cjs/sustainable-web-design.js +9 -6
  16. package/dist/cjs/sustainable-web-design.js.map +2 -2
  17. package/dist/esm/co2.js +16 -24
  18. package/dist/esm/data/average-intensities.min.js +1 -1
  19. package/dist/esm/helpers/index.js +10 -6
  20. package/dist/esm/hosting-api.js +12 -7
  21. package/dist/esm/hosting.js +2 -2
  22. package/dist/esm/sustainable-web-design.js +9 -6
  23. package/package.json +11 -7
  24. package/.all-contributorsrc +0 -39
  25. package/.esbuild.browser.js +0 -11
  26. package/.esbuild.esm.js +0 -25
  27. package/.esbuild.node.js +0 -16
  28. package/.eslintignore +0 -1
  29. package/.gitpod.yml +0 -8
  30. package/data/output/average-intensities.js +0 -226
  31. package/data/output/average-intensities.json +0 -1328
  32. package/data/output/marginal-intensities-2021.js +0 -238
  33. package/data/output/marginal-intensities-2021.json +0 -2801
  34. package/dist/iife/index.js +0 -20
  35. package/dist/iife/index.js.map +0 -7
  36. package/fixup +0 -19
  37. package/index.d.ts +0 -2
  38. package/src/1byte.js +0 -77
  39. package/src/co2.js +0 -311
  40. package/src/constants/file-size.js +0 -5
  41. package/src/constants/index.js +0 -39
  42. package/src/data/average-intensities.min.js +0 -1
  43. package/src/data/marginal-intensities-2021.min.js +0 -1
  44. package/src/helpers/index.js +0 -175
  45. package/src/hosting-api.js +0 -64
  46. package/src/hosting-json.node.js +0 -107
  47. package/src/hosting-node.js +0 -113
  48. package/src/hosting.js +0 -16
  49. package/src/index-node.js +0 -5
  50. package/src/index.js +0 -7
  51. package/src/sustainable-web-design.js +0 -329
package/CHANGELOG.md CHANGED
@@ -12,15 +12,154 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
12
12
  > - **Fixed** for any bug fixes.
13
13
  > - **Security** in case of vulnerabilities.
14
14
 
15
- # Unreleased
15
+ ## Unreleased
16
16
 
17
- - _(Add a summary of your feature, and if relevant the issue, in your PR for merging into `main`)_
17
+ - Adds user agent header for requests to Green Web Foundation APIs
18
+ <!-- - _(Add a summary of your feature, and if relevant the issue, in your PR for merging into `main`)_ -->
18
19
 
19
- # Released
20
+ ## Released
20
21
 
21
- ## [0.11.0] - 2022-10-03
22
+ ### [0.14.1] - 2024-01-09
22
23
 
23
- ### Added
24
+ #### Changed
25
+
26
+ - Removed `index.d.ts` in favour of importing type definitions from `@types/tgwf__co2`.
27
+ - Reduce package size by excluding files from publish NPM package.
28
+ - Automated monthly update of annual average grid intensity data.
29
+
30
+ ### [0.13.10] - 2023-12-16
31
+
32
+ #### Changed
33
+
34
+ - Automated monthly update of annual average grid intensity data.
35
+
36
+ ### [0.13.9] - 2023-11-07
37
+
38
+ #### Fixed
39
+
40
+ - Fix to return expected results when variables with 0 value are passed into function
41
+
42
+ #### Changed
43
+
44
+ - Automated monthly update of annual average grid intensity data.
45
+
46
+ ### [0.13.8] - 2023-10-09
47
+
48
+ #### Fixed
49
+
50
+ - Properly use value of 0 for system segments and variables in the perByteTrace and perVisitTrace functions.
51
+
52
+ #### Changed
53
+
54
+ - Automated monthly update of annual average grid intensity data.
55
+
56
+ ### [0.13.7] - 2023-09-13
57
+
58
+ #### Changed
59
+
60
+ - Automated monthly update of annual average grid intensity data.
61
+
62
+ ### [0.13.6] - 2023-08-08
63
+
64
+ #### Changed
65
+
66
+ - Automated monthly update of annual average grid intensity data.
67
+ - Create FUNDING.yml to allow sponsor contribution to this project.
68
+ - Store segment flag on CO2 instance, not models.
69
+
70
+ ### [0.13.5] - 2023-07-5
71
+
72
+ #### Changed
73
+
74
+ - Automated monthly update of annual average grid intensity data.
75
+
76
+ ### [0.13.4] - 2023-05-24
77
+
78
+ #### Fixed
79
+
80
+ - Fixed an error when try to use global grid intensities in IIFE. (PR #147)
81
+
82
+ ### [0.13.3] - 2023-05-18
83
+
84
+ #### Changed
85
+
86
+ - Updated the global grid intensity constant to use the latest WORLD grid intensity value from Ember. (PR #142)
87
+
88
+ ### [0.13.2] - 2023-04-21
89
+
90
+ - Fix to ensure that region names that are keys in the average annual grid intensity export are capitalised.
91
+
92
+ ### [0.13.1] - 2023-04-20
93
+
94
+ #### Fixed
95
+
96
+ - Fixed the import of average grid intensities in node. (PR #137)
97
+
98
+ ### [0.13.0] - 2023-04-13
99
+
100
+ #### Changed
101
+
102
+ In PR #135 there were significant changes made to how average annual grid intensities are fetched and generated.
103
+
104
+ - Updated average annual grid intensities to include 2022 values from Ember.
105
+ - Changed the functions to generate average grid intensities to:
106
+ - Fetch data directly from Ember's API.
107
+ - Get the _latest_ annual average values for each country/region.
108
+ - Renamed the average grid intensities export file.
109
+
110
+ ### [0.12.2] - 2023-03-01
111
+
112
+ #### Added
113
+
114
+ - Add a module declaration for use from typescript (PR #131)
115
+
116
+ #### Changed
117
+
118
+ - Updated 2021 average annual grid intensity values (PR #133)
119
+
120
+ ### [0.12.1] - 2023-02-02
121
+
122
+ #### Fixed
123
+
124
+ - Removed incorrectly imported constants in tests.
125
+
126
+ ### [0.12.0] - 2023-02-02
127
+
128
+ #### Added
129
+
130
+ - Introduced two new functions `perByteTrace` and `perVisitTrace` which allow developers to pass an options object containing customised values for the constants used in the Sustainable Web Design model. (PR #126)
131
+
132
+ #### Changed
133
+
134
+ - Allowed developers now have the option to return a breakdown of carbon emissions estimates by system segment when using the Sustainable Web Design model. (PR #113)
135
+
136
+ ### [0.11.4] - 2022-12-02
137
+
138
+ #### Fixed
139
+
140
+ - Updated the `greenCheckMulti` function to work properly in ESM. (PR #123)
141
+
142
+ ### [0.11.3] - 2022-10-13
143
+
144
+ #### Fixed
145
+
146
+ - Corrected the Node export for the hosting raised in issue #110. (PR #118)
147
+
148
+ ### [0.11.2] - 2022-10-11
149
+
150
+ #### Fixed
151
+
152
+ - v0.11.x updates increased library size to 17MB + when published to NPM. This has been raised in [#108](https://github.com/thegreenwebfoundation/co2.js/issues/108) and it was found data files were being included in the published package. (PR #117)
153
+
154
+ ### [0.11.1] - 2022-10-07
155
+
156
+ #### Changed
157
+
158
+ - We have used generic filenames for data files, to avoid any confusion around the data being provided in this library. (PR #112)
159
+
160
+ ### [0.11.0] - 2022-10-03
161
+
162
+ #### Added
24
163
 
25
164
  - Introduced average and marginal carbon intensity data into the library. This comes from [Ember Climate](https://ember-climate.org/data/data-explorer/) (for average carbon intensity data), and [The Green Web Foundation](https://developers.thegreenwebfoundation.org/co2js/data) (marginal intensity data, originally sourced from the UNFCCC - the United Nations Framework Convention on Climate Change). For more, [see our release guide for v0.11](https://www.thegreenwebfoundation.org/news/release-guide-co2-js-v0-11/) about the differences between the kinds of data. See [#64](https://github.com/thegreenwebfoundation/co2.js/issues/64), and [#97](https://github.com/thegreenwebfoundation/co2.js/issues/97) for more.
26
165
  - Added new paths to `import` and `require` the annual, country-level average and marginal carbon intensity data mentioned above like, as javascript objects, or as JSON. See [#104 for more](https://github.com/thegreenwebfoundation/co2.js/issues/104).
@@ -28,32 +167,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
28
167
  - Introduced scripts to automate the generation of grid intensity data based of Ember & UNFCCC source files.
29
168
  - Introduced a `release:minor` command, to automate the publishing process, to complement `release:patch`.
30
169
 
31
- ### Changed
170
+ #### Changed
32
171
 
33
- - Changed the default model for transfer based CO2 calculations from the _1byte_ model to the _Sustainable Web Design_ model instead. See https://developers.thegreenwebfoundation.org/co2js/models/ for guidance on the differences and how to migrate between them. See [#94 for more](https://github.com/thegreenwebfoundation/co2.js/issues/94).
172
+ - Changed the default model for transfer based CO2 calculations from the _1byte_ model to the _Sustainable Web Design_ model instead. See <https://developers.thegreenwebfoundation.org/co2js/models/> for guidance on the differences and how to migrate between them. See [#94 for more](https://github.com/thegreenwebfoundation/co2.js/issues/94).
34
173
  - Updated our release commands to generate and format the carbon intensity data as part of the release process.
35
174
 
36
- ## 0.10.4 2022-08-12
175
+ ### [0.10.4] - 2022-08-12
37
176
 
38
- ### Added
177
+ #### Added
39
178
 
40
179
  - Introduced a `release:patch` command, to automate the publishing process. This is designed to make sure we always publish the most recent compiled code, by adding a rebuild step that can be easy to forget.
41
180
 
42
- ## 0.10.3 2022-08-12
181
+ ### [0.10.3] - 2022-08-12
43
182
 
44
- ### Added
183
+ #### Added
45
184
 
46
185
  - Introduced a new `perVisit()` function for the Sustainable Web Design model, which applies [caching and return visits assumptions](https://sustainablewebdesign.org/calculating-digital-emissions/).
47
186
 
48
- ## [0.10.2] - 2022-08-12
187
+ ### [0.10.2] - 2022-08-12
49
188
 
50
189
  - Added the ability to set the model used by CO2.js to the Sustainable Web Design model, using a simple 'swd' string, instead of needing to pass in a class.
51
190
 
52
- ## [0.10.1] - 2022-08-01
191
+ ### [0.10.1] - 2022-08-01
53
192
 
54
193
  This release used a version bump as previously we had released v0.10.0 under a pre-release tag.
55
194
 
56
- ## [0.10.0] - 2022-06-27
195
+ ### [0.10.0] - 2022-06-27
57
196
 
58
197
  - Added ES import syntax as the main way for handling imports and exports of code within the module.
59
198
  - Changed eslint settings to use later version of ecmascript (2020)
@@ -61,104 +200,104 @@ This release used a version bump as previously we had released v0.10.0 under a p
61
200
  - Added more consistent use of the debug logging library in files using the updated import syntax
62
201
  - Fixed the incorrect order of FIRST_TIME_VIEWING_PERCENTAGE and RETURNING_VISITOR_PERCENTAGE constants in the SWD model. This will result in **larger** values for calculations using the sustainable web design, and the default caching assumptions.
63
202
 
64
- ## [0.9.0] - 2022-03-28
203
+ ### [0.9.0] - 2022-03-28
65
204
 
66
- ### Added
205
+ #### Added
67
206
 
68
207
  - Added newly implemented Sustainable Web Design model [thanks @dryden!]
69
208
  - Added new readme page for using both emissions models
70
209
  - Added new source of data to the Sustainable Web Design model from Ember Climate.
71
210
 
72
- ### Changed
211
+ #### Changed
73
212
 
74
213
  - Changed the CO2 class to accept either the One Byte model or the Sustainable Web Design model
75
214
 
76
- ### Fixed
215
+ #### Fixed
77
216
 
78
217
  - Fixed various typos.
79
218
 
80
- ## [0.8.0] - 2021-11-28
219
+ ### [0.8.0] - 2021-11-28
81
220
 
82
- ###  Fixed
221
+ ####  Fixed
83
222
 
84
223
  - Update further dependencies
85
224
  - Fix embarassing order of magnitude typo in 1byte model (thanks @mstaschik!)
86
225
 
87
- ## Added
226
+ #### Added
88
227
 
89
228
  - Read JSON blob also as gzipped #44 (thanks @soulgalore)
90
229
 
91
- ### Changed
230
+ #### Changed
92
231
 
93
232
  - The 1byte model will give different numbers now. It's mentioned in `#fixed` but it's worth repeating.
94
233
 
95
- ## [0.7.0] - 2021-11-28
234
+ ### [0.7.0] - 2021-11-28
96
235
 
97
- ### Fixed
236
+ #### Fixed
98
237
 
99
238
  - Update tests to avoid network requests #50
100
239
  - Update dependencies across the board
101
240
 
102
- ###  Changed
241
+ ####  Changed
103
242
 
104
243
  - Switch to github actions instead of travis for CI.
105
244
 
106
- ## [0.6.1] - 2020-03-15
245
+ ### [0.6.1] - 2020-03-15
107
246
 
108
- ### Fixed
247
+ #### Fixed
109
248
 
110
249
  - Added the function to load JSON, on the tgwg.hosting object, for use in the sustaiable web sitespeed plugin.
111
250
 
112
- ## [0.6.0] - 2020-03-15
251
+ ### [0.6.0] - 2020-03-15
113
252
 
114
- ### Added
253
+ #### Added
115
254
 
116
255
  - Added the hosting-JSON for running local checks against an array instead of SQLite.
117
256
 
118
- ### Changed
257
+ #### Changed
119
258
 
120
259
  - Swapped out checking against a sqlite database `hosting-json`in favour of simple array in,
121
260
  - Updated conventions for style - using kebab-cases over CamelCase for naming files
122
261
 
123
- ### Removed
262
+ #### Removed
124
263
 
125
- - Extracted sqlite usage and dependencies into a separate module, `url2green`. This means you no longer need to compile SQLite on install.
264
+ - Extracted sqlite usage and dependencies into a separate module, `url2green`. This means you no longer need to compile SQLite on install.
126
265
 
127
- ## [0.5.0] - 2020-03-03
266
+ ### [0.5.0] - 2020-03-03
128
267
 
129
- ### Changed
268
+ #### Changed
130
269
 
131
270
  - Updated README
132
271
  - Updated the emissions figured for green energy after further research on methodology with @@JamieBeevor
133
272
  - Incorporated class based CO2 models from @soulgalore
134
273
  - Credit contributors
135
274
 
136
- ## [0.4.7] - 2020-03-02
275
+ ### [0.4.7] - 2020-03-02
137
276
 
138
- ### Added
277
+ #### Added
139
278
 
140
279
  - Added a changelog at last!
141
280
 
142
- ## [0.4.6] - 2020-03-01
281
+ ### [0.4.6] - 2020-03-01
143
282
 
144
- ### Added
283
+ #### Added
145
284
 
146
285
  - Changelog inconsistency section in Bad Practices
147
286
 
148
- ## [0.4.4] - 2020-03-01
287
+ ### [0.4.4] - 2020-03-01
149
288
 
150
- ### Added
289
+ #### Added
151
290
 
152
291
  Added the (currently unused) green byte model.
153
292
 
154
- ### Changed
293
+ #### Changed
155
294
 
156
295
  Update the 1byte model to use an average of devices, rather than just wifi
157
296
 
158
- ## [0.4.3] - 2020-03-01
297
+ ### [0.4.3] - 2020-03-01
159
298
 
160
- ### Added
299
+ #### Added
161
300
 
162
- ### Changed
301
+ #### Changed
163
302
 
164
303
  Split hosting API into two separate files (one for sqlite, and one relying on the greencheck API)
package/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CO2.js
2
2
 
3
+ <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
4
+
5
+ [![All Contributors](https://img.shields.io/badge/all_contributors-13-orange.svg?style=flat-square)](#contributors-)
6
+
7
+ <!-- ALL-CONTRIBUTORS-BADGE:END -->
8
+
3
9
  <img src="https://github.com/thegreenwebfoundation/co2.js/actions/workflows/unittests.yml/badge.svg" />
4
10
 
5
11
  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.
@@ -14,7 +20,7 @@ CO2.js is a JavaScript library that enables developers a way to estimate the emi
14
20
 
15
21
  Being able to estimate the CO2 emissions associated with digital activities can be of benefit to both developers and users.
16
22
 
17
- Internally, 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.
23
+ Internally, 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.
18
24
 
19
25
  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).
20
26
 
@@ -35,7 +41,7 @@ npm install @tgwf/co2
35
41
  You can import the CO2.js library into projects using Skypack.
36
42
 
37
43
  ```js
38
- import tgwf from 'https://cdn.skypack.dev/@tgwf/co2';
44
+ import tgwf from "https://cdn.skypack.dev/@tgwf/co2";
39
45
  ```
40
46
 
41
47
  ## Using a JS CDN
@@ -66,10 +72,18 @@ You can also build the CO2.js library from the source code. To do this:
66
72
  1. Clone or fork the repository.
67
73
  1. Navigate to the folder on your machine and run `npm run build` in your terminal.
68
74
  1. Once the build has finished running, you will find a `/dist` folder has been created. Inside you can find:
69
-
70
- - `dist/cjs` - A CommonJS compatible build.
71
- - `dist/esm` - An ES Modules compatible build.
72
- - `dist/iife` - An Immediately Invoked Function Expression (IIFE) version of the library.
75
+
76
+ - `dist/cjs` - A CommonJS compatible build.
77
+ - `dist/esm` - An ES Modules compatible build.
78
+ - `dist/iife` - An Immediately Invoked Function Expression (IIFE) version of the library.
79
+
80
+ ## TypeScript support
81
+
82
+ Type 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`.
83
+
84
+ If you want to use type definitions in your project, they should be installed as a devDependency.
85
+
86
+ `npm install --dev @types/tgwf__co2`
73
87
 
74
88
  ## Marginal and average emissions intensity data
75
89
 
@@ -80,13 +94,14 @@ CO2.js includes yearly average grid intensity data from [Ember](https://ember-cl
80
94
  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:
81
95
 
82
96
  ```js
83
- import { averageIntensity } from '@tgwf/co2';
97
+ import { averageIntensity } from "@tgwf/co2";
84
98
  const { data } = averageIntensity;
85
99
  const { AUS } = data;
86
- console.log({ AUS })
100
+ console.log({ AUS });
87
101
  ```
88
102
 
89
103
  All countries are represented by their respective [Alpha-3 ISO country code](https://www.iso.org/obp/ui/#search).
104
+
90
105
  ## Publishing to NPM
91
106
 
92
107
  We use [`np`](https://www.npmjs.com/package/np) to publish new versions of this library to NPM. To do this:
@@ -100,20 +115,59 @@ We use [`np`](https://www.npmjs.com/package/np) to publish new versions of this
100
115
 
101
116
  CO2.js releases will be communicated through the following channels:
102
117
 
103
- | Channel | Minor Release (0.xx) | Patch Release (0.xx.x) |
104
- |----------|----------------------|----------------------|
105
- | [Github](https://github.com/thegreenwebfoundation/co2.js/releases) | ✅ | ✅ |
106
- | [Green Web Foundation website](https://www.thegreenwebfoundation.org/co2-js/#releases) | ✅ | ❌ |
107
- | W3C Slack Sustainability Channel | ✅ | ❌ |
108
- | ClimateAction.Tech Slack | ✅ | ❌ |
109
- | [Green Web Foundation LinkedIn Account](https://www.linkedin.com/company/green-web-foundation/) | ✅ | ❌ |
118
+ | Channel | Minor Release (0.xx) | Patch Release (0.xx.x) |
119
+ | ----------------------------------------------------------------------------------------------- | -------------------- | ---------------------- |
120
+ | [Github](https://github.com/thegreenwebfoundation/co2.js/releases) | ✅ | ✅ |
121
+ | [Green Web Foundation website](https://www.thegreenwebfoundation.org/co2-js/#releases) | ✅ | ❌ |
122
+ | W3C Slack Sustainability Channel | ✅ | ❌ |
123
+ | ClimateAction.Tech Slack | ✅ | ❌ |
124
+ | [Green Web Foundation LinkedIn Account](https://www.linkedin.com/company/green-web-foundation/) | ✅ | ❌ |
110
125
 
111
126
  ## Licenses
112
127
 
113
- The code for CO2.js is licensed Apache 2.0. ([What does this mean?](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)))
128
+ The code for CO2.js is licensed Apache 2.0. ([What does this mean?](<https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)>))
114
129
 
115
130
  The 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))
116
131
 
117
132
  The 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))
118
133
 
119
134
  See LICENCE for more.
135
+
136
+ ## Contributors
137
+
138
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
139
+ <!-- prettier-ignore-start -->
140
+ <!-- markdownlint-disable -->
141
+ <table>
142
+ <tbody>
143
+ <tr>
144
+ <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>
145
+ <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>
146
+ <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>
147
+ <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>
148
+ <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>
149
+ <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>
150
+ <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>
151
+ </tr>
152
+ <tr>
153
+ <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>
154
+ <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>
155
+ <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>
156
+ <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>
157
+ <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>
158
+ <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>
159
+ </tr>
160
+ </tbody>
161
+ </table>
162
+
163
+ <!-- markdownlint-restore -->
164
+ <!-- prettier-ignore-end -->
165
+
166
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
167
+ <!-- prettier-ignore-start -->
168
+ <!-- markdownlint-disable -->
169
+
170
+ <!-- markdownlint-restore -->
171
+ <!-- prettier-ignore-end -->
172
+
173
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
package/dist/cjs/co2.js CHANGED
@@ -40,23 +40,15 @@ class CO2 {
40
40
  throw new Error(`"${options.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model.
41
41
  See https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);
42
42
  }
43
- if ((options == null ? void 0 : options.results) === "segment") {
44
- this.model.results = {
45
- segment: true
46
- };
47
- } else {
48
- this.model.results = {
49
- segment: false
50
- };
51
- }
43
+ this._segment = (options == null ? void 0 : options.results) === "segment";
52
44
  }
53
45
  perByte(bytes, green = false) {
54
- return this.model.perByte(bytes, green, this.model.results.segment);
46
+ return this.model.perByte(bytes, green, this._segment);
55
47
  }
56
48
  perVisit(bytes, green = false) {
57
49
  var _a;
58
50
  if ((_a = this.model) == null ? void 0 : _a.perVisit) {
59
- return this.model.perVisit(bytes, green, this.model.results.segment);
51
+ return this.model.perVisit(bytes, green, this._segment);
60
52
  } else {
61
53
  throw new Error(`The perVisit() method is not supported in the model you are using. Try using perByte() instead.
62
54
  See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`);
@@ -69,17 +61,17 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
69
61
  adjustments = (0, import_helpers.parseOptions)(options);
70
62
  }
71
63
  return {
72
- co2: this.model.perByte(bytes, green, this.model.results.segment, adjustments),
64
+ co2: this.model.perByte(bytes, green, this._segment, adjustments),
73
65
  green,
74
66
  variables: {
75
67
  description: "Below are the variables used to calculate this CO2 estimate.",
76
68
  bytes,
77
69
  gridIntensity: {
78
70
  description: "The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",
79
- network: ((_b = (_a = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _a.network) == null ? void 0 : _b.value) || import_constants.GLOBAL_GRID_INTENSITY,
80
- dataCenter: green ? import_constants.RENEWABLES_GRID_INTENSITY : ((_d = (_c = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _c.dataCenter) == null ? void 0 : _d.value) || import_constants.GLOBAL_GRID_INTENSITY,
71
+ network: ((_b = (_a = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _a.network) == null ? void 0 : _b.value) ?? import_constants.GLOBAL_GRID_INTENSITY,
72
+ dataCenter: green ? import_constants.RENEWABLES_GRID_INTENSITY : ((_d = (_c = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _c.dataCenter) == null ? void 0 : _d.value) ?? import_constants.GLOBAL_GRID_INTENSITY,
81
73
  production: import_constants.GLOBAL_GRID_INTENSITY,
82
- device: ((_f = (_e = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _e.device) == null ? void 0 : _f.value) || import_constants.GLOBAL_GRID_INTENSITY
74
+ device: ((_f = (_e = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _e.device) == null ? void 0 : _f.value) ?? import_constants.GLOBAL_GRID_INTENSITY
83
75
  }
84
76
  }
85
77
  };
@@ -92,21 +84,21 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
92
84
  adjustments = (0, import_helpers.parseOptions)(options);
93
85
  }
94
86
  return {
95
- co2: this.model.perVisit(bytes, green, this.model.results.segment, adjustments),
87
+ co2: this.model.perVisit(bytes, green, this._segment, adjustments),
96
88
  green,
97
89
  variables: {
98
90
  description: "Below are the variables used to calculate this CO2 estimate.",
99
91
  bytes,
100
92
  gridIntensity: {
101
93
  description: "The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",
102
- network: ((_c = (_b = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _b.network) == null ? void 0 : _c.value) || import_constants.GLOBAL_GRID_INTENSITY,
103
- dataCenter: green ? import_constants.RENEWABLES_GRID_INTENSITY : ((_e = (_d = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _d.dataCenter) == null ? void 0 : _e.value) || import_constants.GLOBAL_GRID_INTENSITY,
94
+ network: ((_c = (_b = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _b.network) == null ? void 0 : _c.value) ?? import_constants.GLOBAL_GRID_INTENSITY,
95
+ dataCenter: green ? import_constants.RENEWABLES_GRID_INTENSITY : ((_e = (_d = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _d.dataCenter) == null ? void 0 : _e.value) ?? import_constants.GLOBAL_GRID_INTENSITY,
104
96
  production: import_constants.GLOBAL_GRID_INTENSITY,
105
- device: ((_g = (_f = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _f.device) == null ? void 0 : _g.value) || import_constants.GLOBAL_GRID_INTENSITY
97
+ device: ((_g = (_f = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _f.device) == null ? void 0 : _g.value) ?? import_constants.GLOBAL_GRID_INTENSITY
106
98
  },
107
- dataReloadRatio: (adjustments == null ? void 0 : adjustments.dataReloadRatio) || 0.02,
108
- firstVisitPercentage: (adjustments == null ? void 0 : adjustments.firstVisitPercentage) || 0.75,
109
- returnVisitPercentage: (adjustments == null ? void 0 : adjustments.returnVisitPercentage) || 0.25
99
+ dataReloadRatio: (adjustments == null ? void 0 : adjustments.dataReloadRatio) ?? 0.02,
100
+ firstVisitPercentage: (adjustments == null ? void 0 : adjustments.firstVisitPercentage) ?? 0.75,
101
+ returnVisitPercentage: (adjustments == null ? void 0 : adjustments.returnVisitPercentage) ?? 0.25
110
102
  }
111
103
  };
112
104
  } else {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/co2.js"],
4
- "sourcesContent": ["\"use strict\";\n\n/**\n * @typedef {Object} CO2EstimateTraceResultPerByte\n * @property {number} co2 - The CO2 estimate in grams/kilowatt-hour\n * @property {boolean} green - Whether the domain is green or not\n * @property {TraceResultVariables} variables - The variables used to calculate the CO2 estimate\n */\n\n/**\n * @typedef {Object} CO2EstimateTraceResultPerVisit\n * @property {number} co2 - The CO2 estimate in grams/kilowatt-hour\n * @property {boolean} green - Whether the domain is green or not\n * @property {TraceResultVariables} variables - The variables used to calculate the CO2 estimate\n */\n\n/**\n * @typedef {Object} TraceResultVariablesPerByte\n * @property {GridIntensityVariables} gridIntensity - The grid intensity related variables\n */\n/**\n * @typedef {Object} TraceResultVariablesPerVisit\n * @property {GridIntensityVariables} gridIntensity - The grid intensity related variables\n * @property {number} dataReloadRatio - What percentage of a page is reloaded on each subsequent page view\n * @property {number} firstVisitPercentage - What percentage of visits are loading this page for subsequent times\n * @property {number} returnVisitPercentage - What percentage of visits are loading this page for the second or more time\n */\n\n/**\n * @typedef {Object} GridIntensityVariables\n * @property {string} description - The description of the variables\n * @property {number} network - The network grid intensity set by the user or the default\n * @property {number} dataCenter - The data center grid intensity set by the user or the default\n * @property {number} device - The device grid intensity set by the user or the default\n * @property {number} production - The production grid intensity set by the user or the default\n */\n\nimport OneByte from \"./1byte.js\";\nimport SustainableWebDesign from \"./sustainable-web-design.js\";\n\nimport {\n GLOBAL_GRID_INTENSITY,\n RENEWABLES_GRID_INTENSITY,\n} from \"./constants/index.js\";\nimport { parseOptions } from \"./helpers/index.js\";\n\nclass CO2 {\n constructor(options) {\n this.model = new SustainableWebDesign();\n // Using optional chaining allows an empty object to be passed\n // in without breaking the code.\n if (options?.model === \"1byte\") {\n this.model = new OneByte();\n } else if (options?.model === \"swd\") {\n this.model = new SustainableWebDesign();\n } else if (options?.model) {\n throw new Error(\n `\"${options.model}\" is not a valid model. Please use \"1byte\" for the OneByte model, and \"swd\" for the Sustainable Web Design model.\\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`\n );\n }\n\n if (options?.results === \"segment\") {\n this.model.results = {\n segment: true,\n };\n } else {\n this.model.results = {\n segment: false,\n };\n }\n }\n\n /**\n * Accept a figure in bytes for data transfer, and a boolean for whether\n * the domain shows as 'green', and return a CO2 figure for energy used to shift the corresponding\n * the data transfer.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @return {number} the amount of CO2 in grammes\n */\n perByte(bytes, green = false) {\n return this.model.perByte(bytes, green, this.model.results.segment);\n }\n\n /**\n * Accept a figure in bytes for data transfer, and a boolean for whether\n * the domain shows as 'green', and return a CO2 figure for energy used to shift the corresponding\n * the data transfer.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @return {number} the amount of CO2 in grammes\n */\n perVisit(bytes, green = false) {\n if (this.model?.perVisit) {\n return this.model.perVisit(bytes, green, this.model.results.segment);\n } else {\n throw new Error(\n `The perVisit() method is not supported in the model you are using. Try using perByte() instead.\\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`\n );\n }\n }\n\n /**\n * Accept a figure in bytes for data transfer, a boolean for whether\n * the domain shows as 'green', and an options object.\n * Returns an object containing CO2 figure, green boolean, and object of the variables used in calculating the CO2 figure.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @param {Object} options\n * @return {CO2EstimateTraceResultPerByte} the amount of CO2 in grammes\n */\n perByteTrace(bytes, green = false, options = {}) {\n let adjustments = {};\n if (options) {\n // If there are options, parse them and add them to the model.\n adjustments = parseOptions(options);\n }\n return {\n co2: this.model.perByte(\n bytes,\n green,\n this.model.results.segment,\n adjustments\n ),\n green,\n variables: {\n description:\n \"Below are the variables used to calculate this CO2 estimate.\",\n bytes,\n gridIntensity: {\n description:\n \"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.\",\n network:\n adjustments?.gridIntensity?.network?.value || GLOBAL_GRID_INTENSITY,\n dataCenter: green\n ? RENEWABLES_GRID_INTENSITY\n : adjustments?.gridIntensity?.dataCenter?.value ||\n GLOBAL_GRID_INTENSITY,\n production: GLOBAL_GRID_INTENSITY,\n device:\n adjustments?.gridIntensity?.device?.value || GLOBAL_GRID_INTENSITY,\n },\n },\n };\n }\n\n /**\n * Accept a figure in bytes for data transfer, a boolean for whether\n * the domain shows as 'green', and an options object.\n * Returns an object containing CO2 figure, green boolean, and object of the variables used in calculating the CO2 figure.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @param {Object} options\n * @return {CO2EstimateTraceResultPerVisit} the amount of CO2 in grammes\n */\n perVisitTrace(bytes, green = false, options = {}) {\n if (this.model?.perVisit) {\n let adjustments = {};\n if (options) {\n // If there are options, parse them and add them to the model.\n adjustments = parseOptions(options);\n }\n\n return {\n co2: this.model.perVisit(\n bytes,\n green,\n this.model.results.segment,\n adjustments\n ),\n green,\n variables: {\n description:\n \"Below are the variables used to calculate this CO2 estimate.\",\n bytes,\n gridIntensity: {\n description:\n \"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.\",\n network:\n adjustments?.gridIntensity?.network?.value ||\n GLOBAL_GRID_INTENSITY,\n dataCenter: green\n ? RENEWABLES_GRID_INTENSITY\n : adjustments?.gridIntensity?.dataCenter?.value ||\n GLOBAL_GRID_INTENSITY,\n production: GLOBAL_GRID_INTENSITY,\n device:\n adjustments?.gridIntensity?.device?.value ||\n GLOBAL_GRID_INTENSITY,\n },\n dataReloadRatio: adjustments?.dataReloadRatio || 0.02,\n firstVisitPercentage: adjustments?.firstVisitPercentage || 0.75,\n returnVisitPercentage: adjustments?.returnVisitPercentage || 0.25,\n },\n };\n } else {\n throw new Error(\n `The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead.\\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`\n );\n }\n }\n\n perDomain(pageXray, greenDomains) {\n const co2PerDomain = [];\n for (let domain of Object.keys(pageXray.domains)) {\n let co2;\n if (greenDomains && greenDomains.indexOf(domain) > -1) {\n co2 = this.perByte(pageXray.domains[domain].transferSize, true);\n } else {\n co2 = this.perByte(pageXray.domains[domain].transferSize);\n }\n co2PerDomain.push({\n domain,\n co2,\n transferSize: pageXray.domains[domain].transferSize,\n });\n }\n co2PerDomain.sort((a, b) => b.co2 - a.co2);\n\n return co2PerDomain;\n }\n\n perPage(pageXray, green) {\n // Accept an xray object, and if we receive a boolean as the second\n // argument, we assume every request we make is sent to a server\n // running on renwewable power.\n\n // if we receive an array of domains, return a number accounting the\n // reduced CO2 from green hosted domains\n\n const domainCO2 = this.perDomain(pageXray, green);\n let totalCO2 = 0;\n for (let domain of domainCO2) {\n totalCO2 += domain.co2;\n }\n return totalCO2;\n }\n\n perContentType(pageXray, greenDomains) {\n const co2PerContentType = {};\n for (let asset of pageXray.assets) {\n const domain = new URL(asset.url).domain;\n const transferSize = asset.transferSize;\n const co2ForTransfer = this.perByte(\n transferSize,\n greenDomains && greenDomains.indexOf(domain) > -1\n );\n const contentType = asset.type;\n if (!co2PerContentType[contentType]) {\n co2PerContentType[contentType] = { co2: 0, transferSize: 0 };\n }\n co2PerContentType[contentType].co2 += co2ForTransfer;\n co2PerContentType[contentType].transferSize += transferSize;\n }\n // restructure and sort\n const all = [];\n for (let type of Object.keys(co2PerContentType)) {\n all.push({\n type,\n co2: co2PerContentType[type].co2,\n transferSize: co2PerContentType[type].transferSize,\n });\n }\n all.sort((a, b) => b.co2 - a.co2);\n return all;\n }\n\n dirtiestResources(pageXray, greenDomains) {\n const allAssets = [];\n for (let asset of pageXray.assets) {\n const domain = new URL(asset.url).domain;\n const transferSize = asset.transferSize;\n const co2ForTransfer = this.perByte(\n transferSize,\n greenDomains && greenDomains.indexOf(domain) > -1\n );\n allAssets.push({ url: asset.url, co2: co2ForTransfer, transferSize });\n }\n allAssets.sort((a, b) => b.co2 - a.co2);\n\n return allAssets.slice(0, allAssets.length > 10 ? 10 : allAssets.length);\n }\n\n perParty(pageXray, greenDomains) {\n let firstParty = 0;\n let thirdParty = 0;\n // calculate co2 per first/third party\n const firstPartyRegEx = pageXray.firstPartyRegEx;\n for (let d of Object.keys(pageXray.domains)) {\n if (!d.match(firstPartyRegEx)) {\n thirdParty += this.perByte(\n pageXray.domains[d].transferSize,\n greenDomains && greenDomains.indexOf(d) > -1\n );\n } else {\n firstParty += this.perByte(\n pageXray.domains[d].transferSize,\n greenDomains && greenDomains.indexOf(d) > -1\n );\n }\n }\n return { firstParty, thirdParty };\n }\n}\n\nexport { CO2 };\nexport default CO2;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqCA,kBAAoB;AACpB,oCAAiC;AAEjC,uBAGO;AACP,qBAA6B;AAE7B,MAAM,IAAI;AAAA,EACR,YAAY,SAAS;AACnB,SAAK,QAAQ,IAAI,sCAAqB;AAGtC,QAAI,oCAAS,WAAU,SAAS;AAC9B,WAAK,QAAQ,IAAI,oBAAQ;AAAA,IAC3B,WAAW,oCAAS,WAAU,OAAO;AACnC,WAAK,QAAQ,IAAI,sCAAqB;AAAA,IACxC,WAAW,mCAAS,OAAO;AACzB,YAAM,IAAI,MACR,IAAI,QAAQ;AAAA,mHACd;AAAA,IACF;AAEA,QAAI,oCAAS,aAAY,WAAW;AAClC,WAAK,MAAM,UAAU;AAAA,QACnB,SAAS;AAAA,MACX;AAAA,IACF,OAAO;AACL,WAAK,MAAM,UAAU;AAAA,QACnB,SAAS;AAAA,MACX;AAAA,IACF;AAAA,EACF;AAAA,EAWA,QAAQ,OAAO,QAAQ,OAAO;AAC5B,WAAO,KAAK,MAAM,QAAQ,OAAO,OAAO,KAAK,MAAM,QAAQ,OAAO;AAAA,EACpE;AAAA,EAWA,SAAS,OAAO,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K,QACjB,SAAS,QAAQ,GAAG,cACpB,gBAAgB,aAAa,QAAQ,CAAC,IAAI,EAC5C;AAAA,MACF;AAAA,IACF;AACA,WAAO,EAAE,YAAY,WAAW;AAAA,EAClC;AACF;AAGA,IAAO,cAAQ;",
4
+ "sourcesContent": ["\"use strict\";\n\n/**\n * @typedef {Object} CO2EstimateTraceResultPerByte\n * @property {number} co2 - The CO2 estimate in grams/kilowatt-hour\n * @property {boolean} green - Whether the domain is green or not\n * @property {TraceResultVariables} variables - The variables used to calculate the CO2 estimate\n */\n\n/**\n * @typedef {Object} CO2EstimateTraceResultPerVisit\n * @property {number} co2 - The CO2 estimate in grams/kilowatt-hour\n * @property {boolean} green - Whether the domain is green or not\n * @property {TraceResultVariables} variables - The variables used to calculate the CO2 estimate\n */\n\n/**\n * @typedef {Object} TraceResultVariablesPerByte\n * @property {GridIntensityVariables} gridIntensity - The grid intensity related variables\n */\n/**\n * @typedef {Object} TraceResultVariablesPerVisit\n * @property {GridIntensityVariables} gridIntensity - The grid intensity related variables\n * @property {number} dataReloadRatio - What percentage of a page is reloaded on each subsequent page view\n * @property {number} firstVisitPercentage - What percentage of visits are loading this page for subsequent times\n * @property {number} returnVisitPercentage - What percentage of visits are loading this page for the second or more time\n */\n\n/**\n * @typedef {Object} GridIntensityVariables\n * @property {string} description - The description of the variables\n * @property {number} network - The network grid intensity set by the user or the default\n * @property {number} dataCenter - The data center grid intensity set by the user or the default\n * @property {number} device - The device grid intensity set by the user or the default\n * @property {number} production - The production grid intensity set by the user or the default\n */\n\nimport OneByte from \"./1byte.js\";\nimport SustainableWebDesign from \"./sustainable-web-design.js\";\n\nimport {\n GLOBAL_GRID_INTENSITY,\n RENEWABLES_GRID_INTENSITY,\n} from \"./constants/index.js\";\nimport { parseOptions } from \"./helpers/index.js\";\n\nclass CO2 {\n constructor(options) {\n this.model = new SustainableWebDesign();\n // Using optional chaining allows an empty object to be passed\n // in without breaking the code.\n if (options?.model === \"1byte\") {\n this.model = new OneByte();\n } else if (options?.model === \"swd\") {\n this.model = new SustainableWebDesign();\n } else if (options?.model) {\n throw new Error(\n `\"${options.model}\" is not a valid model. Please use \"1byte\" for the OneByte model, and \"swd\" for the Sustainable Web Design model.\\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`\n );\n }\n\n /** @private */\n this._segment = options?.results === \"segment\";\n }\n\n /**\n * Accept a figure in bytes for data transfer, and a boolean for whether\n * the domain shows as 'green', and return a CO2 figure for energy used to shift the corresponding\n * the data transfer.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @return {number} the amount of CO2 in grammes\n */\n perByte(bytes, green = false) {\n return this.model.perByte(bytes, green, this._segment);\n }\n\n /**\n * Accept a figure in bytes for data transfer, and a boolean for whether\n * the domain shows as 'green', and return a CO2 figure for energy used to shift the corresponding\n * the data transfer.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @return {number} the amount of CO2 in grammes\n */\n perVisit(bytes, green = false) {\n if (this.model?.perVisit) {\n return this.model.perVisit(bytes, green, this._segment);\n } else {\n throw new Error(\n `The perVisit() method is not supported in the model you are using. Try using perByte() instead.\\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`\n );\n }\n }\n\n /**\n * Accept a figure in bytes for data transfer, a boolean for whether\n * the domain shows as 'green', and an options object.\n * Returns an object containing CO2 figure, green boolean, and object of the variables used in calculating the CO2 figure.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @param {Object} options\n * @return {CO2EstimateTraceResultPerByte} the amount of CO2 in grammes\n */\n perByteTrace(bytes, green = false, options = {}) {\n let adjustments = {};\n if (options) {\n // If there are options, parse them and add them to the model.\n adjustments = parseOptions(options);\n }\n return {\n co2: this.model.perByte(bytes, green, this._segment, adjustments),\n green,\n variables: {\n description:\n \"Below are the variables used to calculate this CO2 estimate.\",\n bytes,\n gridIntensity: {\n description:\n \"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.\",\n network:\n adjustments?.gridIntensity?.network?.value ?? GLOBAL_GRID_INTENSITY,\n dataCenter: green\n ? RENEWABLES_GRID_INTENSITY\n : adjustments?.gridIntensity?.dataCenter?.value ??\n GLOBAL_GRID_INTENSITY,\n production: GLOBAL_GRID_INTENSITY,\n device:\n adjustments?.gridIntensity?.device?.value ?? GLOBAL_GRID_INTENSITY,\n },\n },\n };\n }\n\n /**\n * Accept a figure in bytes for data transfer, a boolean for whether\n * the domain shows as 'green', and an options object.\n * Returns an object containing CO2 figure, green boolean, and object of the variables used in calculating the CO2 figure.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @param {Object} options\n * @return {CO2EstimateTraceResultPerVisit} the amount of CO2 in grammes\n */\n perVisitTrace(bytes, green = false, options = {}) {\n if (this.model?.perVisit) {\n let adjustments = {};\n if (options) {\n // If there are options, parse them and add them to the model.\n adjustments = parseOptions(options);\n }\n\n return {\n co2: this.model.perVisit(bytes, green, this._segment, adjustments),\n green,\n variables: {\n description:\n \"Below are the variables used to calculate this CO2 estimate.\",\n bytes,\n gridIntensity: {\n description:\n \"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.\",\n network:\n adjustments?.gridIntensity?.network?.value ??\n GLOBAL_GRID_INTENSITY,\n dataCenter: green\n ? RENEWABLES_GRID_INTENSITY\n : adjustments?.gridIntensity?.dataCenter?.value ??\n GLOBAL_GRID_INTENSITY,\n production: GLOBAL_GRID_INTENSITY,\n device:\n adjustments?.gridIntensity?.device?.value ??\n GLOBAL_GRID_INTENSITY,\n },\n dataReloadRatio: adjustments?.dataReloadRatio ?? 0.02,\n firstVisitPercentage: adjustments?.firstVisitPercentage ?? 0.75,\n returnVisitPercentage: adjustments?.returnVisitPercentage ?? 0.25,\n },\n };\n } else {\n throw new Error(\n `The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead.\\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`\n );\n }\n }\n\n perDomain(pageXray, greenDomains) {\n const co2PerDomain = [];\n for (let domain of Object.keys(pageXray.domains)) {\n let co2;\n if (greenDomains && greenDomains.indexOf(domain) > -1) {\n co2 = this.perByte(pageXray.domains[domain].transferSize, true);\n } else {\n co2 = this.perByte(pageXray.domains[domain].transferSize);\n }\n co2PerDomain.push({\n domain,\n co2,\n transferSize: pageXray.domains[domain].transferSize,\n });\n }\n co2PerDomain.sort((a, b) => b.co2 - a.co2);\n\n return co2PerDomain;\n }\n\n perPage(pageXray, green) {\n // Accept an xray object, and if we receive a boolean as the second\n // argument, we assume every request we make is sent to a server\n // running on renwewable power.\n\n // if we receive an array of domains, return a number accounting the\n // reduced CO2 from green hosted domains\n\n const domainCO2 = this.perDomain(pageXray, green);\n let totalCO2 = 0;\n for (let domain of domainCO2) {\n totalCO2 += domain.co2;\n }\n return totalCO2;\n }\n\n perContentType(pageXray, greenDomains) {\n const co2PerContentType = {};\n for (let asset of pageXray.assets) {\n const domain = new URL(asset.url).domain;\n const transferSize = asset.transferSize;\n const co2ForTransfer = this.perByte(\n transferSize,\n greenDomains && greenDomains.indexOf(domain) > -1\n );\n const contentType = asset.type;\n if (!co2PerContentType[contentType]) {\n co2PerContentType[contentType] = { co2: 0, transferSize: 0 };\n }\n co2PerContentType[contentType].co2 += co2ForTransfer;\n co2PerContentType[contentType].transferSize += transferSize;\n }\n // restructure and sort\n const all = [];\n for (let type of Object.keys(co2PerContentType)) {\n all.push({\n type,\n co2: co2PerContentType[type].co2,\n transferSize: co2PerContentType[type].transferSize,\n });\n }\n all.sort((a, b) => b.co2 - a.co2);\n return all;\n }\n\n dirtiestResources(pageXray, greenDomains) {\n const allAssets = [];\n for (let asset of pageXray.assets) {\n const domain = new URL(asset.url).domain;\n const transferSize = asset.transferSize;\n const co2ForTransfer = this.perByte(\n transferSize,\n greenDomains && greenDomains.indexOf(domain) > -1\n );\n allAssets.push({ url: asset.url, co2: co2ForTransfer, transferSize });\n }\n allAssets.sort((a, b) => b.co2 - a.co2);\n\n return allAssets.slice(0, allAssets.length > 10 ? 10 : allAssets.length);\n }\n\n perParty(pageXray, greenDomains) {\n let firstParty = 0;\n let thirdParty = 0;\n // calculate co2 per first/third party\n const firstPartyRegEx = pageXray.firstPartyRegEx;\n for (let d of Object.keys(pageXray.domains)) {\n if (!d.match(firstPartyRegEx)) {\n thirdParty += this.perByte(\n pageXray.domains[d].transferSize,\n greenDomains && greenDomains.indexOf(d) > -1\n );\n } else {\n firstParty += this.perByte(\n pageXray.domains[d].transferSize,\n greenDomains && greenDomains.indexOf(d) > -1\n );\n }\n }\n return { firstParty, thirdParty };\n }\n}\n\nexport { CO2 };\nexport default CO2;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqCA,kBAAoB;AACpB,oCAAiC;AAEjC,uBAGO;AACP,qBAA6B;AAE7B,MAAM,IAAI;AAAA,EACR,YAAY,SAAS;AACnB,SAAK,QAAQ,IAAI,sCAAqB;AAGtC,QAAI,oCAAS,WAAU,SAAS;AAC9B,WAAK,QAAQ,IAAI,oBAAQ;AAAA,IAC3B,WAAW,oCAAS,WAAU,OAAO;AACnC,WAAK,QAAQ,IAAI,sCAAqB;AAAA,IACxC,WAAW,mCAAS,OAAO;AACzB,YAAM,IAAI,MACR,IAAI,QAAQ;AAAA,mHACd;AAAA,IACF;AAGA,SAAK,WAAW,oCAAS,aAAY;AAAA,EACvC;AAAA,EAWA,QAAQ,OAAO,QAAQ,OAAO;AAC5B,WAAO,KAAK,MAAM,QAAQ,OAAO,OAAO,KAAK,QAAQ;AAAA,EACvD;AAAA,EAWA,SAAS,OAAO,QAAQ,OAAO;AAvFjC;AAwFI,QAAI,WAAK,UAAL,mBAAY,UAAU;AACxB,aAAO,KAAK,MAAM,SAAS,OAAO,OAAO,KAAK,QAAQ;AAAA,IACxD,OAAO;AACL,YAAM,IAAI,MACR;AAAA,qHACF;AAAA,IACF;AAAA,EACF;AAAA,EAYA,aAAa,OAAO,QAAQ,OAAO,UAAU,CAAC,GAA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