@tgwf/co2 0.14.1 → 0.14.3
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.
- package/CHANGELOG.md +112 -73
- package/README.md +2 -3
- package/dist/cjs/data/average-intensities.min.js +1 -1
- package/dist/cjs/data/average-intensities.min.js.map +2 -2
- package/dist/cjs/helpers/index.js +4 -0
- package/dist/cjs/helpers/index.js.map +2 -2
- package/dist/cjs/hosting-api.js +12 -7
- package/dist/cjs/hosting-api.js.map +2 -2
- package/dist/cjs/hosting-node.js +10 -9
- package/dist/cjs/hosting-node.js.map +2 -2
- package/dist/cjs/hosting.js +2 -2
- package/dist/cjs/hosting.js.map +2 -2
- package/dist/esm/data/average-intensities.min.js +1 -1
- package/dist/esm/helpers/index.js +4 -0
- package/dist/esm/hosting-api.js +12 -7
- package/dist/esm/hosting.js +2 -2
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -12,58 +12,97 @@ 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
|
-
|
|
15
|
+
## Unreleased
|
|
16
16
|
|
|
17
|
-
-
|
|
17
|
+
- Add ability to create adaptors which provide access to external data sources
|
|
18
|
+
- Add access to the Electricity Maps API free tier
|
|
19
|
+
<!-- - _(Add a summary of your feature, and if relevant the issue, in your PR for merging into `main`)_ -->
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
## Released
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
### [0.14.2] - 2024-01-29
|
|
22
24
|
|
|
23
|
-
-
|
|
25
|
+
- Adds user agent header for requests to Green Web Foundation APIs
|
|
26
|
+
|
|
27
|
+
### [0.14.1] - 2024-01-09
|
|
28
|
+
|
|
29
|
+
#### Changed
|
|
30
|
+
|
|
31
|
+
- Removed `index.d.ts` in favour of importing type definitions from `@types/tgwf__co2`.
|
|
32
|
+
- Reduce package size by excluding files from publish NPM package.
|
|
24
33
|
- Automated monthly update of annual average grid intensity data.
|
|
25
34
|
|
|
26
|
-
|
|
35
|
+
### [0.13.10] - 2023-12-16
|
|
36
|
+
|
|
37
|
+
#### Changed
|
|
27
38
|
|
|
28
39
|
- Automated monthly update of annual average grid intensity data.
|
|
29
40
|
|
|
30
|
-
|
|
41
|
+
### [0.13.9] - 2023-11-07
|
|
42
|
+
|
|
43
|
+
#### Fixed
|
|
44
|
+
|
|
45
|
+
- Fix to return expected results when variables with 0 value are passed into function
|
|
46
|
+
|
|
47
|
+
#### Changed
|
|
48
|
+
|
|
49
|
+
- Automated monthly update of annual average grid intensity data.
|
|
50
|
+
|
|
51
|
+
### [0.13.8] - 2023-10-09
|
|
52
|
+
|
|
53
|
+
#### Fixed
|
|
54
|
+
|
|
55
|
+
- Properly use value of 0 for system segments and variables in the perByteTrace and perVisitTrace functions.
|
|
56
|
+
|
|
57
|
+
#### Changed
|
|
58
|
+
|
|
59
|
+
- Automated monthly update of annual average grid intensity data.
|
|
60
|
+
|
|
61
|
+
### [0.13.7] - 2023-09-13
|
|
62
|
+
|
|
63
|
+
#### Changed
|
|
64
|
+
|
|
65
|
+
- Automated monthly update of annual average grid intensity data.
|
|
66
|
+
|
|
67
|
+
### [0.13.6] - 2023-08-08
|
|
68
|
+
|
|
69
|
+
#### Changed
|
|
31
70
|
|
|
32
71
|
- Automated monthly update of annual average grid intensity data.
|
|
33
72
|
- Create FUNDING.yml to allow sponsor contribution to this project.
|
|
34
73
|
- Store segment flag on CO2 instance, not models.
|
|
35
74
|
|
|
36
|
-
|
|
75
|
+
### [0.13.5] - 2023-07-5
|
|
37
76
|
|
|
38
|
-
|
|
77
|
+
#### Changed
|
|
39
78
|
|
|
40
79
|
- Automated monthly update of annual average grid intensity data.
|
|
41
80
|
|
|
42
|
-
|
|
81
|
+
### [0.13.4] - 2023-05-24
|
|
43
82
|
|
|
44
|
-
|
|
83
|
+
#### Fixed
|
|
45
84
|
|
|
46
85
|
- Fixed an error when try to use global grid intensities in IIFE. (PR #147)
|
|
47
86
|
|
|
48
|
-
|
|
87
|
+
### [0.13.3] - 2023-05-18
|
|
49
88
|
|
|
50
|
-
|
|
89
|
+
#### Changed
|
|
51
90
|
|
|
52
91
|
- Updated the global grid intensity constant to use the latest WORLD grid intensity value from Ember. (PR #142)
|
|
53
92
|
|
|
54
|
-
|
|
93
|
+
### [0.13.2] - 2023-04-21
|
|
55
94
|
|
|
56
95
|
- Fix to ensure that region names that are keys in the average annual grid intensity export are capitalised.
|
|
57
96
|
|
|
58
|
-
|
|
97
|
+
### [0.13.1] - 2023-04-20
|
|
59
98
|
|
|
60
|
-
|
|
99
|
+
#### Fixed
|
|
61
100
|
|
|
62
101
|
- Fixed the import of average grid intensities in node. (PR #137)
|
|
63
102
|
|
|
64
|
-
|
|
103
|
+
### [0.13.0] - 2023-04-13
|
|
65
104
|
|
|
66
|
-
|
|
105
|
+
#### Changed
|
|
67
106
|
|
|
68
107
|
In PR #135 there were significant changes made to how average annual grid intensities are fetched and generated.
|
|
69
108
|
|
|
@@ -73,59 +112,59 @@ In PR #135 there were significant changes made to how average annual grid intens
|
|
|
73
112
|
- Get the _latest_ annual average values for each country/region.
|
|
74
113
|
- Renamed the average grid intensities export file.
|
|
75
114
|
|
|
76
|
-
|
|
115
|
+
### [0.12.2] - 2023-03-01
|
|
77
116
|
|
|
78
|
-
|
|
117
|
+
#### Added
|
|
79
118
|
|
|
80
119
|
- Add a module declaration for use from typescript (PR #131)
|
|
81
120
|
|
|
82
|
-
|
|
121
|
+
#### Changed
|
|
83
122
|
|
|
84
123
|
- Updated 2021 average annual grid intensity values (PR #133)
|
|
85
124
|
|
|
86
|
-
|
|
125
|
+
### [0.12.1] - 2023-02-02
|
|
87
126
|
|
|
88
|
-
|
|
127
|
+
#### Fixed
|
|
89
128
|
|
|
90
129
|
- Removed incorrectly imported constants in tests.
|
|
91
130
|
|
|
92
|
-
|
|
131
|
+
### [0.12.0] - 2023-02-02
|
|
93
132
|
|
|
94
|
-
|
|
133
|
+
#### Added
|
|
95
134
|
|
|
96
135
|
- 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)
|
|
97
136
|
|
|
98
|
-
|
|
137
|
+
#### Changed
|
|
99
138
|
|
|
100
139
|
- 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)
|
|
101
140
|
|
|
102
|
-
|
|
141
|
+
### [0.11.4] - 2022-12-02
|
|
103
142
|
|
|
104
|
-
|
|
143
|
+
#### Fixed
|
|
105
144
|
|
|
106
145
|
- Updated the `greenCheckMulti` function to work properly in ESM. (PR #123)
|
|
107
146
|
|
|
108
|
-
|
|
147
|
+
### [0.11.3] - 2022-10-13
|
|
109
148
|
|
|
110
|
-
|
|
149
|
+
#### Fixed
|
|
111
150
|
|
|
112
151
|
- Corrected the Node export for the hosting raised in issue #110. (PR #118)
|
|
113
152
|
|
|
114
|
-
|
|
153
|
+
### [0.11.2] - 2022-10-11
|
|
115
154
|
|
|
116
|
-
|
|
155
|
+
#### Fixed
|
|
117
156
|
|
|
118
157
|
- 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)
|
|
119
158
|
|
|
120
|
-
|
|
159
|
+
### [0.11.1] - 2022-10-07
|
|
121
160
|
|
|
122
|
-
|
|
161
|
+
#### Changed
|
|
123
162
|
|
|
124
163
|
- We have used generic filenames for data files, to avoid any confusion around the data being provided in this library. (PR #112)
|
|
125
164
|
|
|
126
|
-
|
|
165
|
+
### [0.11.0] - 2022-10-03
|
|
127
166
|
|
|
128
|
-
|
|
167
|
+
#### Added
|
|
129
168
|
|
|
130
169
|
- 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.
|
|
131
170
|
- 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).
|
|
@@ -133,32 +172,32 @@ In PR #135 there were significant changes made to how average annual grid intens
|
|
|
133
172
|
- Introduced scripts to automate the generation of grid intensity data based of Ember & UNFCCC source files.
|
|
134
173
|
- Introduced a `release:minor` command, to automate the publishing process, to complement `release:patch`.
|
|
135
174
|
|
|
136
|
-
|
|
175
|
+
#### Changed
|
|
137
176
|
|
|
138
177
|
- 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).
|
|
139
178
|
- Updated our release commands to generate and format the carbon intensity data as part of the release process.
|
|
140
179
|
|
|
141
|
-
|
|
180
|
+
### [0.10.4] - 2022-08-12
|
|
142
181
|
|
|
143
|
-
|
|
182
|
+
#### Added
|
|
144
183
|
|
|
145
184
|
- 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.
|
|
146
185
|
|
|
147
|
-
|
|
186
|
+
### [0.10.3] - 2022-08-12
|
|
148
187
|
|
|
149
|
-
|
|
188
|
+
#### Added
|
|
150
189
|
|
|
151
190
|
- Introduced a new `perVisit()` function for the Sustainable Web Design model, which applies [caching and return visits assumptions](https://sustainablewebdesign.org/calculating-digital-emissions/).
|
|
152
191
|
|
|
153
|
-
|
|
192
|
+
### [0.10.2] - 2022-08-12
|
|
154
193
|
|
|
155
194
|
- 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.
|
|
156
195
|
|
|
157
|
-
|
|
196
|
+
### [0.10.1] - 2022-08-01
|
|
158
197
|
|
|
159
198
|
This release used a version bump as previously we had released v0.10.0 under a pre-release tag.
|
|
160
199
|
|
|
161
|
-
|
|
200
|
+
### [0.10.0] - 2022-06-27
|
|
162
201
|
|
|
163
202
|
- Added ES import syntax as the main way for handling imports and exports of code within the module.
|
|
164
203
|
- Changed eslint settings to use later version of ecmascript (2020)
|
|
@@ -166,104 +205,104 @@ This release used a version bump as previously we had released v0.10.0 under a p
|
|
|
166
205
|
- Added more consistent use of the debug logging library in files using the updated import syntax
|
|
167
206
|
- 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.
|
|
168
207
|
|
|
169
|
-
|
|
208
|
+
### [0.9.0] - 2022-03-28
|
|
170
209
|
|
|
171
|
-
|
|
210
|
+
#### Added
|
|
172
211
|
|
|
173
212
|
- Added newly implemented Sustainable Web Design model [thanks @dryden!]
|
|
174
213
|
- Added new readme page for using both emissions models
|
|
175
214
|
- Added new source of data to the Sustainable Web Design model from Ember Climate.
|
|
176
215
|
|
|
177
|
-
|
|
216
|
+
#### Changed
|
|
178
217
|
|
|
179
218
|
- Changed the CO2 class to accept either the One Byte model or the Sustainable Web Design model
|
|
180
219
|
|
|
181
|
-
|
|
220
|
+
#### Fixed
|
|
182
221
|
|
|
183
222
|
- Fixed various typos.
|
|
184
223
|
|
|
185
|
-
|
|
224
|
+
### [0.8.0] - 2021-11-28
|
|
186
225
|
|
|
187
|
-
|
|
226
|
+
#### Fixed
|
|
188
227
|
|
|
189
228
|
- Update further dependencies
|
|
190
229
|
- Fix embarassing order of magnitude typo in 1byte model (thanks @mstaschik!)
|
|
191
230
|
|
|
192
|
-
|
|
231
|
+
#### Added
|
|
193
232
|
|
|
194
233
|
- Read JSON blob also as gzipped #44 (thanks @soulgalore)
|
|
195
234
|
|
|
196
|
-
|
|
235
|
+
#### Changed
|
|
197
236
|
|
|
198
237
|
- The 1byte model will give different numbers now. It's mentioned in `#fixed` but it's worth repeating.
|
|
199
238
|
|
|
200
|
-
|
|
239
|
+
### [0.7.0] - 2021-11-28
|
|
201
240
|
|
|
202
|
-
|
|
241
|
+
#### Fixed
|
|
203
242
|
|
|
204
243
|
- Update tests to avoid network requests #50
|
|
205
244
|
- Update dependencies across the board
|
|
206
245
|
|
|
207
|
-
|
|
246
|
+
#### Changed
|
|
208
247
|
|
|
209
248
|
- Switch to github actions instead of travis for CI.
|
|
210
249
|
|
|
211
|
-
|
|
250
|
+
### [0.6.1] - 2020-03-15
|
|
212
251
|
|
|
213
|
-
|
|
252
|
+
#### Fixed
|
|
214
253
|
|
|
215
254
|
- Added the function to load JSON, on the tgwg.hosting object, for use in the sustaiable web sitespeed plugin.
|
|
216
255
|
|
|
217
|
-
|
|
256
|
+
### [0.6.0] - 2020-03-15
|
|
218
257
|
|
|
219
|
-
|
|
258
|
+
#### Added
|
|
220
259
|
|
|
221
260
|
- Added the hosting-JSON for running local checks against an array instead of SQLite.
|
|
222
261
|
|
|
223
|
-
|
|
262
|
+
#### Changed
|
|
224
263
|
|
|
225
264
|
- Swapped out checking against a sqlite database `hosting-json`in favour of simple array in,
|
|
226
265
|
- Updated conventions for style - using kebab-cases over CamelCase for naming files
|
|
227
266
|
|
|
228
|
-
|
|
267
|
+
#### Removed
|
|
229
268
|
|
|
230
269
|
- Extracted sqlite usage and dependencies into a separate module, `url2green`. This means you no longer need to compile SQLite on install.
|
|
231
270
|
|
|
232
|
-
|
|
271
|
+
### [0.5.0] - 2020-03-03
|
|
233
272
|
|
|
234
|
-
|
|
273
|
+
#### Changed
|
|
235
274
|
|
|
236
275
|
- Updated README
|
|
237
276
|
- Updated the emissions figured for green energy after further research on methodology with @@JamieBeevor
|
|
238
277
|
- Incorporated class based CO2 models from @soulgalore
|
|
239
278
|
- Credit contributors
|
|
240
279
|
|
|
241
|
-
|
|
280
|
+
### [0.4.7] - 2020-03-02
|
|
242
281
|
|
|
243
|
-
|
|
282
|
+
#### Added
|
|
244
283
|
|
|
245
284
|
- Added a changelog at last!
|
|
246
285
|
|
|
247
|
-
|
|
286
|
+
### [0.4.6] - 2020-03-01
|
|
248
287
|
|
|
249
|
-
|
|
288
|
+
#### Added
|
|
250
289
|
|
|
251
290
|
- Changelog inconsistency section in Bad Practices
|
|
252
291
|
|
|
253
|
-
|
|
292
|
+
### [0.4.4] - 2020-03-01
|
|
254
293
|
|
|
255
|
-
|
|
294
|
+
#### Added
|
|
256
295
|
|
|
257
296
|
Added the (currently unused) green byte model.
|
|
258
297
|
|
|
259
|
-
|
|
298
|
+
#### Changed
|
|
260
299
|
|
|
261
300
|
Update the 1byte model to use an average of devices, rather than just wifi
|
|
262
301
|
|
|
263
|
-
|
|
302
|
+
### [0.4.3] - 2020-03-01
|
|
264
303
|
|
|
265
|
-
|
|
304
|
+
#### Added
|
|
266
305
|
|
|
267
|
-
|
|
306
|
+
#### Changed
|
|
268
307
|
|
|
269
308
|
Split hosting API into two separate files (one for sqlite, and one relying on the greencheck API)
|
package/README.md
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
# CO2.js
|
|
2
2
|
|
|
3
3
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
4
|
-
|
|
5
|
-
[](#contributors-)
|
|
6
|
-
|
|
4
|
+
[](#contributors-)
|
|
7
5
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
8
6
|
|
|
9
7
|
<img src="https://github.com/thegreenwebfoundation/co2.js/actions/workflows/unittests.yml/badge.svg" />
|
|
@@ -156,6 +154,7 @@ See LICENCE for more.
|
|
|
156
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>
|
|
157
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>
|
|
158
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>
|
|
159
158
|
</tr>
|
|
160
159
|
</tbody>
|
|
161
160
|
</table>
|
|
@@ -22,7 +22,7 @@ __export(average_intensities_min_exports, {
|
|
|
22
22
|
type: () => type
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(average_intensities_min_exports);
|
|
25
|
-
const data = { "AFG": 120.48, "AFRICA":
|
|
25
|
+
const data = { "AFG": 120.48, "AFRICA": 590.8, "ALB": 23.44, "DZA": 672.64, "ASM": 687.5, "AGO": 212.42, "ATG": 657.14, "ARG": 399.5, "ARM": 280.06, "ABW": 591.4, "ASEAN": 569.34, "ASIA": 594.16, "AUS": 570.35, "AUT": 141.79, "AZE": 719.39, "BHS": 698.11, "BHR": 956.55, "BGD": 719.78, "BRB": 644.86, "BLR": 465.34, "BEL": 139.79, "BLZ": 484.38, "BEN": 666.67, "BTN": 24.44, "BOL": 497.78, "BIH": 670.09, "BWA": 867.58, "BRA": 114.48, "BRN": 961.54, "BGR": 476.9, "BFA": 611.43, "BDI": 250, "CPV": 600, "KHM": 436.13, "CMR": 278.26, "CAN": 163.01, "CYM": 684.93, "CAF": 0, "TCD": 677.42, "CHL": 353.52, "CHN": 585.82, "COL": 198.53, "COM": 714.29, "COG": 723.88, "COD": 25.36, "COK": 400, "CRI": 37.21, "CIV": 453.55, "HRV": 242.28, "CUB": 677.47, "CYP": 555.13, "CZE": 488.3, "DNK": 201.78, "DJI": 666.67, "DMA": 529.41, "DOM": 592.49, "ECU": 192.39, "EGY": 612.16, "SLV": 211.29, "GNQ": 492.96, "ERI": 688.89, "EST": 489.89, "SWZ": 189.19, "ETH": 25.19, "EU": 291.9, "EUROPE": 330.47, "FLK": 500, "FRO": 428.57, "FJI": 289.47, "FIN": 130.42, "FRA": 78.81, "GUF": 254.72, "PYF": 471.43, "G20": 489.9, "G7": 375.97, "GAB": 397.38, "GMB": 700, "GEO": 176.97, "DEU": 420.06, "GHA": 498.81, "GRC": 378.18, "GRL": 133.33, "GRD": 714.29, "GLP": 647.06, "GUM": 670.33, "GTM": 331.72, "GIN": 208.63, "GNB": 750, "GUY": 642.28, "HTI": 606.06, "HND": 378.97, "HKG": 733.05, "HUN": 228.75, "ISL": 28.56, "IND": 705.13, "IDN": 675.93, "IRN": 665.15, "IRQ": 708.1, "IRL": 333.23, "ISR": 641.17, "ITA": 378.45, "JAM": 588.51, "JPN": 512.81, "JOR": 572.74, "KAZ": 830.41, "KEN": 101.13, "KIR": 666.67, "XKX": 945.01, "KWT": 691.31, "KGZ": 124.48, "LAO": 284.21, "LATIN AMERICA AND CARIBBEAN": 278.58, "LVA": 136.27, "LBN": 663.1, "LSO": 20, "LBR": 304.35, "LBY": 861.69, "LTU": 177.18, "LUX": 144.07, "MAC": 627.12, "MDG": 497.61, "MWI": 133.8, "MYS": 605.83, "MDV": 651.52, "MLI": 463.13, "MLT": 500, "MTQ": 698.63, "MRT": 526.6, "MUS": 631.94, "MEX": 515.62, "MIDDLE EAST": 673.63, "MDA": 871.66, "MNG": 852.82, "MNE": 483.38, "MSR": 1e3, "MAR": 705.67, "MOZ": 150.25, "MMR": 575.77, "NAM": 70.06, "NRU": 750, "NPL": 24.51, "NLD": 324.99, "NCL": 610.12, "NZL": 117.46, "NIC": 352.05, "NER": 622.22, "NGA": 513.24, "NORTH AMERICA": 378.27, "PRK": 124.57, "MKD": 639.86, "NOR": 26.5, "OCEANIA": 509.12, "OECD": 373.31, "OMN": 598.27, "PAK": 435.89, "PSE": 511.63, "PAN": 175, "PNG": 526.75, "PRY": 25.49, "PER": 312.59, "POL": 733.18, "PRT": 225.19, "PRI": 719.85, "QAT": 642.01, "REU": 519.03, "ROU": 297.94, "RUS": 451.95, "RWA": 294.12, "KNA": 681.82, "LCA": 685.71, "SPM": 800, "VCT": 500, "WSM": 470.59, "STP": 600, "SAU": 706.79, "SEN": 685.05, "SRB": 695.69, "SYC": 615.39, "SLE": 47.62, "SGP": 505.22, "SVK": 142.59, "SVN": 257.49, "SLB": 727.27, "SOM": 634.15, "ZAF": 762.46, "KOR": 470.4, "SSD": 684.21, "ESP": 217.77, "LKA": 543.12, "SDN": 288.13, "SUR": 356.44, "SWE": 41.07, "CHE": 36.14, "SYR": 758.35, "TWN": 678.87, "TJK": 99.34, "TZA": 374.08, "THA": 599.02, "PHL": 641.96, "TGO": 492.06, "TON": 625, "TTO": 723.94, "TUN": 592.21, "TUR": 453.01, "TKM": 1389.72, "TCA": 703.7, "UGA": 52.27, "UKR": 271.41, "ARE": 561.14, "GBR": 255.85, "USA": 410.37, "URY": 149.49, "UZB": 1176.69, "VUT": 571.43, "VEN": 298.5, "VNM": 409.8, "VGB": 714.29, "VIR": 685.71, "WORLD": 493.92, "YEM": 613.64, "ZMB": 86.39, "ZWE": 433.38 };
|
|
26
26
|
const type = "average";
|
|
27
27
|
var average_intensities_min_default = { data, type };
|
|
28
28
|
//# sourceMappingURL=average-intensities.min.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/data/average-intensities.min.js"],
|
|
4
|
-
"sourcesContent": ["const data = {\"AFG\":120.48,\"AFRICA\":
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,OAAO,EAAC,OAAM,QAAO,UAAS,OAAM,OAAM,OAAM,OAAM,QAAO,OAAM,OAAM,OAAM,QAAO,OAAM,QAAO,OAAM,
|
|
4
|
+
"sourcesContent": ["const data = {\"AFG\":120.48,\"AFRICA\":590.8,\"ALB\":23.44,\"DZA\":672.64,\"ASM\":687.5,\"AGO\":212.42,\"ATG\":657.14,\"ARG\":399.5,\"ARM\":280.06,\"ABW\":591.4,\"ASEAN\":569.34,\"ASIA\":594.16,\"AUS\":570.35,\"AUT\":141.79,\"AZE\":719.39,\"BHS\":698.11,\"BHR\":956.55,\"BGD\":719.78,\"BRB\":644.86,\"BLR\":465.34,\"BEL\":139.79,\"BLZ\":484.38,\"BEN\":666.67,\"BTN\":24.44,\"BOL\":497.78,\"BIH\":670.09,\"BWA\":867.58,\"BRA\":114.48,\"BRN\":961.54,\"BGR\":476.9,\"BFA\":611.43,\"BDI\":250,\"CPV\":600,\"KHM\":436.13,\"CMR\":278.26,\"CAN\":163.01,\"CYM\":684.93,\"CAF\":0,\"TCD\":677.42,\"CHL\":353.52,\"CHN\":585.82,\"COL\":198.53,\"COM\":714.29,\"COG\":723.88,\"COD\":25.36,\"COK\":400,\"CRI\":37.21,\"CIV\":453.55,\"HRV\":242.28,\"CUB\":677.47,\"CYP\":555.13,\"CZE\":488.3,\"DNK\":201.78,\"DJI\":666.67,\"DMA\":529.41,\"DOM\":592.49,\"ECU\":192.39,\"EGY\":612.16,\"SLV\":211.29,\"GNQ\":492.96,\"ERI\":688.89,\"EST\":489.89,\"SWZ\":189.19,\"ETH\":25.19,\"EU\":291.9,\"EUROPE\":330.47,\"FLK\":500,\"FRO\":428.57,\"FJI\":289.47,\"FIN\":130.42,\"FRA\":78.81,\"GUF\":254.72,\"PYF\":471.43,\"G20\":489.9,\"G7\":375.97,\"GAB\":397.38,\"GMB\":700,\"GEO\":176.97,\"DEU\":420.06,\"GHA\":498.81,\"GRC\":378.18,\"GRL\":133.33,\"GRD\":714.29,\"GLP\":647.06,\"GUM\":670.33,\"GTM\":331.72,\"GIN\":208.63,\"GNB\":750,\"GUY\":642.28,\"HTI\":606.06,\"HND\":378.97,\"HKG\":733.05,\"HUN\":228.75,\"ISL\":28.56,\"IND\":705.13,\"IDN\":675.93,\"IRN\":665.15,\"IRQ\":708.1,\"IRL\":333.23,\"ISR\":641.17,\"ITA\":378.45,\"JAM\":588.51,\"JPN\":512.81,\"JOR\":572.74,\"KAZ\":830.41,\"KEN\":101.13,\"KIR\":666.67,\"XKX\":945.01,\"KWT\":691.31,\"KGZ\":124.48,\"LAO\":284.21,\"LATIN AMERICA AND CARIBBEAN\":278.58,\"LVA\":136.27,\"LBN\":663.1,\"LSO\":20,\"LBR\":304.35,\"LBY\":861.69,\"LTU\":177.18,\"LUX\":144.07,\"MAC\":627.12,\"MDG\":497.61,\"MWI\":133.8,\"MYS\":605.83,\"MDV\":651.52,\"MLI\":463.13,\"MLT\":500,\"MTQ\":698.63,\"MRT\":526.6,\"MUS\":631.94,\"MEX\":515.62,\"MIDDLE EAST\":673.63,\"MDA\":871.66,\"MNG\":852.82,\"MNE\":483.38,\"MSR\":1000,\"MAR\":705.67,\"MOZ\":150.25,\"MMR\":575.77,\"NAM\":70.06,\"NRU\":750,\"NPL\":24.51,\"NLD\":324.99,\"NCL\":610.12,\"NZL\":117.46,\"NIC\":352.05,\"NER\":622.22,\"NGA\":513.24,\"NORTH AMERICA\":378.27,\"PRK\":124.57,\"MKD\":639.86,\"NOR\":26.5,\"OCEANIA\":509.12,\"OECD\":373.31,\"OMN\":598.27,\"PAK\":435.89,\"PSE\":511.63,\"PAN\":175,\"PNG\":526.75,\"PRY\":25.49,\"PER\":312.59,\"POL\":733.18,\"PRT\":225.19,\"PRI\":719.85,\"QAT\":642.01,\"REU\":519.03,\"ROU\":297.94,\"RUS\":451.95,\"RWA\":294.12,\"KNA\":681.82,\"LCA\":685.71,\"SPM\":800,\"VCT\":500,\"WSM\":470.59,\"STP\":600,\"SAU\":706.79,\"SEN\":685.05,\"SRB\":695.69,\"SYC\":615.39,\"SLE\":47.62,\"SGP\":505.22,\"SVK\":142.59,\"SVN\":257.49,\"SLB\":727.27,\"SOM\":634.15,\"ZAF\":762.46,\"KOR\":470.4,\"SSD\":684.21,\"ESP\":217.77,\"LKA\":543.12,\"SDN\":288.13,\"SUR\":356.44,\"SWE\":41.07,\"CHE\":36.14,\"SYR\":758.35,\"TWN\":678.87,\"TJK\":99.34,\"TZA\":374.08,\"THA\":599.02,\"PHL\":641.96,\"TGO\":492.06,\"TON\":625,\"TTO\":723.94,\"TUN\":592.21,\"TUR\":453.01,\"TKM\":1389.72,\"TCA\":703.7,\"UGA\":52.27,\"UKR\":271.41,\"ARE\":561.14,\"GBR\":255.85,\"USA\":410.37,\"URY\":149.49,\"UZB\":1176.69,\"VUT\":571.43,\"VEN\":298.5,\"VNM\":409.8,\"VGB\":714.29,\"VIR\":685.71,\"WORLD\":493.92,\"YEM\":613.64,\"ZMB\":86.39,\"ZWE\":433.38}; const type = \"average\"; export { data, type }; export default { data, type };"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,OAAO,EAAC,OAAM,QAAO,UAAS,OAAM,OAAM,OAAM,OAAM,QAAO,OAAM,OAAM,OAAM,QAAO,OAAM,QAAO,OAAM,OAAM,OAAM,QAAO,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AAM,QAAO,OAAM,OAAM,OAAM,OAAM,OAAM,QAAO,OAAM,QAAO,SAAQ,QAAO,OAAM,QAAO,OAAM,OAAM,OAAM,OAAM;AAAG,MAAM,OAAO;AAAkC,IAAO,kCAAQ,EAAE,MAAM,KAAK;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -18,6 +18,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
18
18
|
var helpers_exports = {};
|
|
19
19
|
__export(helpers_exports, {
|
|
20
20
|
formatNumber: () => formatNumber,
|
|
21
|
+
getApiRequestHeaders: () => getApiRequestHeaders,
|
|
21
22
|
parseOptions: () => parseOptions
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(helpers_exports);
|
|
@@ -159,4 +160,7 @@ Falling back to default value.`);
|
|
|
159
160
|
}
|
|
160
161
|
return adjustments;
|
|
161
162
|
}
|
|
163
|
+
function getApiRequestHeaders(comment = "") {
|
|
164
|
+
return { "User-Agent": `co2js/${"0.14.3"} ${comment}` };
|
|
165
|
+
}
|
|
162
166
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/index.js"],
|
|
4
|
-
"sourcesContent": ["import { averageIntensity } from \"../index.js\";\nimport {\n GLOBAL_GRID_INTENSITY,\n PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD,\n FIRST_TIME_VIEWING_PERCENTAGE,\n RETURNING_VISITOR_PERCENTAGE,\n} from \"../constants/index.js\";\nconst formatNumber = (num) => parseFloat(num.toFixed(2));\n\nfunction parseOptions(options) {\n // CHeck that it is an object\n if (typeof options !== \"object\") {\n throw new Error(\"Options must be an object\");\n }\n\n const adjustments = {};\n\n if (options?.gridIntensity) {\n adjustments.gridIntensity = {};\n const { device, dataCenter, network } = options.gridIntensity;\n if (device || device === 0) {\n if (typeof device === \"object\") {\n if (!averageIntensity.data[device.country?.toUpperCase()]) {\n console.warn(\n `\"${device.country}\" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \\nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \\nFalling back to global average grid intensity.`\n );\n adjustments.gridIntensity[\"device\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n }\n adjustments.gridIntensity[\"device\"] = {\n country: device.country,\n value: parseFloat(\n averageIntensity.data[device.country?.toUpperCase()]\n ),\n };\n } else if (typeof device === \"number\") {\n adjustments.gridIntensity[\"device\"] = {\n value: device,\n };\n } else {\n adjustments.gridIntensity[\"device\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n console.warn(\n `The device grid intensity must be a number or an object. You passed in a ${typeof device}. \\nFalling back to global average grid intensity.`\n );\n }\n }\n if (dataCenter || dataCenter === 0) {\n if (typeof dataCenter === \"object\") {\n if (!averageIntensity.data[dataCenter.country?.toUpperCase()]) {\n console.warn(\n `\"${dataCenter.country}\" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \\nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \\nFalling back to global average grid intensity.`\n );\n adjustments.gridIntensity[\"dataCenter\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n }\n adjustments.gridIntensity[\"dataCenter\"] = {\n country: dataCenter.country,\n value: parseFloat(\n averageIntensity.data[dataCenter.country?.toUpperCase()]\n ),\n };\n } else if (typeof dataCenter === \"number\") {\n adjustments.gridIntensity[\"dataCenter\"] = {\n value: dataCenter,\n };\n } else {\n adjustments.gridIntensity[\"dataCenter\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n console.warn(\n `The data center grid intensity must be a number or an object. You passed in a ${typeof dataCenter}. \\nFalling back to global average grid intensity.`\n );\n }\n }\n if (network || network === 0) {\n if (typeof network === \"object\") {\n if (!averageIntensity.data[network.country?.toUpperCase()]) {\n console.warn(\n `\"${network.country}\" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \\nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity. \\nFalling back to global average grid intensity.`\n );\n adjustments.gridIntensity[\"network\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n }\n adjustments.gridIntensity[\"network\"] = {\n country: network.country,\n value: parseFloat(\n averageIntensity.data[network.country?.toUpperCase()]\n ),\n };\n } else if (typeof network === \"number\") {\n adjustments.gridIntensity[\"network\"] = {\n value: network,\n };\n } else {\n adjustments.gridIntensity[\"network\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n console.warn(\n `The network grid intensity must be a number or an object. You passed in a ${typeof network}. \\nFalling back to global average grid intensity.`\n );\n }\n }\n }\n\n if (options?.dataReloadRatio || options.dataReloadRatio === 0) {\n if (typeof options.dataReloadRatio === \"number\") {\n if (options.dataReloadRatio >= 0 && options.dataReloadRatio <= 1) {\n adjustments.dataReloadRatio = options.dataReloadRatio;\n } else {\n adjustments.dataReloadRatio =\n PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD;\n console.warn(\n `The dataReloadRatio option must be a number between 0 and 1. You passed in ${options.dataReloadRatio}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.dataReloadRatio =\n PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD;\n console.warn(\n `The dataReloadRatio option must be a number. You passed in a ${typeof options.dataReloadRatio}. \\nFalling back to default value.`\n );\n }\n }\n\n if (options?.firstVisitPercentage || options.firstVisitPercentage === 0) {\n if (typeof options.firstVisitPercentage === \"number\") {\n if (\n options.firstVisitPercentage >= 0 &&\n options.firstVisitPercentage <= 1\n ) {\n adjustments.firstVisitPercentage = options.firstVisitPercentage;\n } else {\n adjustments.firstVisitPercentage = FIRST_TIME_VIEWING_PERCENTAGE;\n console.warn(\n `The firstVisitPercentage option must be a number between 0 and 1. You passed in ${options.firstVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.firstVisitPercentage = FIRST_TIME_VIEWING_PERCENTAGE;\n console.warn(\n `The firstVisitPercentage option must be a number. You passed in a ${typeof options.firstVisitPercentage}. \\nFalling back to default value.`\n );\n }\n }\n\n if (options?.returnVisitPercentage || options.returnVisitPercentage === 0) {\n if (typeof options.returnVisitPercentage === \"number\") {\n if (\n options.returnVisitPercentage >= 0 &&\n options.returnVisitPercentage <= 1\n ) {\n adjustments.returnVisitPercentage = options.returnVisitPercentage;\n } else {\n adjustments.returnVisitPercentage = RETURNING_VISITOR_PERCENTAGE;\n console.warn(\n `The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.returnVisitPercentage = RETURNING_VISITOR_PERCENTAGE;\n console.warn(\n `The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}. \\nFalling back to default value.`\n );\n }\n }\n\n return adjustments;\n}\n\nexport { formatNumber, parseOptions };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAAiC;AACjC,uBAKO;AACP,MAAM,eAAe,CAAC,QAAQ,WAAW,IAAI,QAAQ,CAAC,CAAC;AAEvD,sBAAsB,SAAS;AAT/B;AAWE,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC7C;AAEA,QAAM,cAAc,CAAC;AAErB,MAAI,mCAAS,eAAe;AAC1B,gBAAY,gBAAgB,CAAC;AAC7B,UAAM,EAAE,QAAQ,YAAY,YAAY,QAAQ;AAChD,QAAI,UAAU,WAAW,GAAG;AAC1B,UAAI,OAAO,WAAW,UAAU;AAC9B,YAAI,CAAC,0BAAiB,KAAK,aAAO,YAAP,mBAAgB,gBAAgB;AACzD,kBAAQ,KACN,IAAI,OAAO;AAAA;AAAA,+CACb;AACA,sBAAY,cAAc,YAAY;AAAA,YACpC,OAAO;AAAA,UACT;AAAA,QACF;AACA,oBAAY,cAAc,YAAY;AAAA,UACpC,SAAS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oBAAY,wBAAwB;AACpC,gBAAQ,KACN,oFAAoF,QAAQ;AAAA,+BAC9F;AAAA,MACF;AAAA,IACF,OAAO;AACL,kBAAY,wBAAwB;AACpC,cAAQ,KACN,sEAAsE,OAAO,QAAQ;AAAA,+BACvF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
4
|
+
"sourcesContent": ["import { averageIntensity } from \"../index.js\";\nimport {\n GLOBAL_GRID_INTENSITY,\n PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD,\n FIRST_TIME_VIEWING_PERCENTAGE,\n RETURNING_VISITOR_PERCENTAGE,\n} from \"../constants/index.js\";\nconst formatNumber = (num) => parseFloat(num.toFixed(2));\n\nfunction parseOptions(options) {\n // CHeck that it is an object\n if (typeof options !== \"object\") {\n throw new Error(\"Options must be an object\");\n }\n\n const adjustments = {};\n\n if (options?.gridIntensity) {\n adjustments.gridIntensity = {};\n const { device, dataCenter, network } = options.gridIntensity;\n if (device || device === 0) {\n if (typeof device === \"object\") {\n if (!averageIntensity.data[device.country?.toUpperCase()]) {\n console.warn(\n `\"${device.country}\" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \\nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \\nFalling back to global average grid intensity.`\n );\n adjustments.gridIntensity[\"device\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n }\n adjustments.gridIntensity[\"device\"] = {\n country: device.country,\n value: parseFloat(\n averageIntensity.data[device.country?.toUpperCase()]\n ),\n };\n } else if (typeof device === \"number\") {\n adjustments.gridIntensity[\"device\"] = {\n value: device,\n };\n } else {\n adjustments.gridIntensity[\"device\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n console.warn(\n `The device grid intensity must be a number or an object. You passed in a ${typeof device}. \\nFalling back to global average grid intensity.`\n );\n }\n }\n if (dataCenter || dataCenter === 0) {\n if (typeof dataCenter === \"object\") {\n if (!averageIntensity.data[dataCenter.country?.toUpperCase()]) {\n console.warn(\n `\"${dataCenter.country}\" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \\nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \\nFalling back to global average grid intensity.`\n );\n adjustments.gridIntensity[\"dataCenter\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n }\n adjustments.gridIntensity[\"dataCenter\"] = {\n country: dataCenter.country,\n value: parseFloat(\n averageIntensity.data[dataCenter.country?.toUpperCase()]\n ),\n };\n } else if (typeof dataCenter === \"number\") {\n adjustments.gridIntensity[\"dataCenter\"] = {\n value: dataCenter,\n };\n } else {\n adjustments.gridIntensity[\"dataCenter\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n console.warn(\n `The data center grid intensity must be a number or an object. You passed in a ${typeof dataCenter}. \\nFalling back to global average grid intensity.`\n );\n }\n }\n if (network || network === 0) {\n if (typeof network === \"object\") {\n if (!averageIntensity.data[network.country?.toUpperCase()]) {\n console.warn(\n `\"${network.country}\" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \\nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity. \\nFalling back to global average grid intensity.`\n );\n adjustments.gridIntensity[\"network\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n }\n adjustments.gridIntensity[\"network\"] = {\n country: network.country,\n value: parseFloat(\n averageIntensity.data[network.country?.toUpperCase()]\n ),\n };\n } else if (typeof network === \"number\") {\n adjustments.gridIntensity[\"network\"] = {\n value: network,\n };\n } else {\n adjustments.gridIntensity[\"network\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n console.warn(\n `The network grid intensity must be a number or an object. You passed in a ${typeof network}. \\nFalling back to global average grid intensity.`\n );\n }\n }\n }\n\n if (options?.dataReloadRatio || options.dataReloadRatio === 0) {\n if (typeof options.dataReloadRatio === \"number\") {\n if (options.dataReloadRatio >= 0 && options.dataReloadRatio <= 1) {\n adjustments.dataReloadRatio = options.dataReloadRatio;\n } else {\n adjustments.dataReloadRatio =\n PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD;\n console.warn(\n `The dataReloadRatio option must be a number between 0 and 1. You passed in ${options.dataReloadRatio}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.dataReloadRatio =\n PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD;\n console.warn(\n `The dataReloadRatio option must be a number. You passed in a ${typeof options.dataReloadRatio}. \\nFalling back to default value.`\n );\n }\n }\n\n if (options?.firstVisitPercentage || options.firstVisitPercentage === 0) {\n if (typeof options.firstVisitPercentage === \"number\") {\n if (\n options.firstVisitPercentage >= 0 &&\n options.firstVisitPercentage <= 1\n ) {\n adjustments.firstVisitPercentage = options.firstVisitPercentage;\n } else {\n adjustments.firstVisitPercentage = FIRST_TIME_VIEWING_PERCENTAGE;\n console.warn(\n `The firstVisitPercentage option must be a number between 0 and 1. You passed in ${options.firstVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.firstVisitPercentage = FIRST_TIME_VIEWING_PERCENTAGE;\n console.warn(\n `The firstVisitPercentage option must be a number. You passed in a ${typeof options.firstVisitPercentage}. \\nFalling back to default value.`\n );\n }\n }\n\n if (options?.returnVisitPercentage || options.returnVisitPercentage === 0) {\n if (typeof options.returnVisitPercentage === \"number\") {\n if (\n options.returnVisitPercentage >= 0 &&\n options.returnVisitPercentage <= 1\n ) {\n adjustments.returnVisitPercentage = options.returnVisitPercentage;\n } else {\n adjustments.returnVisitPercentage = RETURNING_VISITOR_PERCENTAGE;\n console.warn(\n `The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.returnVisitPercentage = RETURNING_VISITOR_PERCENTAGE;\n console.warn(\n `The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}. \\nFalling back to default value.`\n );\n }\n }\n\n return adjustments;\n}\n\n/**\n * Returns an object containing all the HTTP headers to use when making a request to the Green Web Foundation API.\n * @param {string} comment - Optional. The app, site, or organisation that is making the request.\n *\n * @returns {import('http').OutgoingHttpHeaders}\n */\nfunction getApiRequestHeaders(comment = \"\") {\n return { \"User-Agent\": `co2js/${process.env.CO2JS_VERSION} ${comment}` };\n}\n\nexport { formatNumber, parseOptions, getApiRequestHeaders };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAAiC;AACjC,uBAKO;AACP,MAAM,eAAe,CAAC,QAAQ,WAAW,IAAI,QAAQ,CAAC,CAAC;AAEvD,sBAAsB,SAAS;AAT/B;AAWE,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC7C;AAEA,QAAM,cAAc,CAAC;AAErB,MAAI,mCAAS,eAAe;AAC1B,gBAAY,gBAAgB,CAAC;AAC7B,UAAM,EAAE,QAAQ,YAAY,YAAY,QAAQ;AAChD,QAAI,UAAU,WAAW,GAAG;AAC1B,UAAI,OAAO,WAAW,UAAU;AAC9B,YAAI,CAAC,0BAAiB,KAAK,aAAO,YAAP,mBAAgB,gBAAgB;AACzD,kBAAQ,KACN,IAAI,OAAO;AAAA;AAAA,+CACb;AACA,sBAAY,cAAc,YAAY;AAAA,YACpC,OAAO;AAAA,UACT;AAAA,QACF;AACA,oBAAY,cAAc,YAAY;AAAA,UACpC,SAAS,OAAO;AAAA,UAChB,OAAO,WACL,0BAAiB,KAAK,aAAO,YAAP,mBAAgB,cACxC;AAAA,QACF;AAAA,MACF,WAAW,OAAO,WAAW,UAAU;AACrC,oBAAY,cAAc,YAAY;AAAA,UACpC,OAAO;AAAA,QACT;AAAA,MACF,OAAO;AACL,oBAAY,cAAc,YAAY;AAAA,UACpC,OAAO;AAAA,QACT;AACA,gBAAQ,KACN,4EAA4E,OAAO;AAAA,+CACrF;AAAA,MACF;AAAA,IACF;AACA,QAAI,cAAc,eAAe,GAAG;AAClC,UAAI,OAAO,eAAe,UAAU;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 __export(hosting_api_exports, {
|
|
|
21
21
|
default: () => hosting_api_default
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(hosting_api_exports);
|
|
24
|
-
|
|
24
|
+
var import_helpers = require("./helpers/index.js");
|
|
25
|
+
function check(domain, userAgentIdentifier) {
|
|
25
26
|
if (typeof domain === "string") {
|
|
26
|
-
return checkAgainstAPI(domain);
|
|
27
|
+
return checkAgainstAPI(domain, userAgentIdentifier);
|
|
27
28
|
} else {
|
|
28
|
-
return checkDomainsAgainstAPI(domain);
|
|
29
|
+
return checkDomainsAgainstAPI(domain, userAgentIdentifier);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
async function checkAgainstAPI(domain) {
|
|
32
|
-
const req = await fetch(`https://api.thegreenwebfoundation.org/greencheck/${domain}
|
|
32
|
+
async function checkAgainstAPI(domain, userAgentIdentifier) {
|
|
33
|
+
const req = await fetch(`https://api.thegreenwebfoundation.org/greencheck/${domain}`, {
|
|
34
|
+
headers: (0, import_helpers.getApiRequestHeaders)(userAgentIdentifier)
|
|
35
|
+
});
|
|
33
36
|
const res = await req.json();
|
|
34
37
|
return res.green;
|
|
35
38
|
}
|
|
36
|
-
async function checkDomainsAgainstAPI(domains) {
|
|
39
|
+
async function checkDomainsAgainstAPI(domains, userAgentIdentifier) {
|
|
37
40
|
try {
|
|
38
41
|
const apiPath = "https://api.thegreenwebfoundation.org/v2/greencheckmulti";
|
|
39
42
|
const domainsString = JSON.stringify(domains);
|
|
40
|
-
const req = await fetch(`${apiPath}/${domainsString}
|
|
43
|
+
const req = await fetch(`${apiPath}/${domainsString}`, {
|
|
44
|
+
headers: (0, import_helpers.getApiRequestHeaders)(userAgentIdentifier)
|
|
45
|
+
});
|
|
41
46
|
const allGreenCheckResults = await req.json();
|
|
42
47
|
return greenDomainsFromResults(allGreenCheckResults);
|
|
43
48
|
} catch (e) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hosting-api.js"],
|
|
4
|
-
"sourcesContent": ["\"use strict\";\n\n/**\n * Check if a string or array of domains has been provided\n * @param {string|array} domain - The domain to check, or an array of domains to be checked.\n */\n\nfunction check(domain) {\n // is it a single domain or an array of them?\n if (typeof domain === \"string\") {\n return checkAgainstAPI(domain);\n } else {\n return checkDomainsAgainstAPI(domain);\n }\n}\n\n/**\n * Check if a domain is hosted by a green web host by querying the Green Web Foundation API.\n * @param {string} domain - The domain to check.\n * @returns {boolean} - A boolean indicating whether the domain is hosted by a green web host.\n */\nasync function checkAgainstAPI(domain) {\n const req = await fetch(\n `https://api.thegreenwebfoundation.org/greencheck/${domain}
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["\"use strict\";\n\nimport { getApiRequestHeaders } from \"./helpers/index.js\";\n\n/**\n * Check if a string or array of domains has been provided\n * @param {string|array} domain - The domain to check, or an array of domains to be checked.\n * @param {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.\n */\n\nfunction check(domain, userAgentIdentifier) {\n // is it a single domain or an array of them?\n if (typeof domain === \"string\") {\n return checkAgainstAPI(domain, userAgentIdentifier);\n } else {\n return checkDomainsAgainstAPI(domain, userAgentIdentifier);\n }\n}\n\n/**\n * Check if a domain is hosted by a green web host by querying the Green Web Foundation API.\n * @param {string} domain - The domain to check.\n * @param {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.\n * @returns {boolean} - A boolean indicating whether the domain is hosted by a green web host.\n */\nasync function checkAgainstAPI(domain, userAgentIdentifier) {\n const req = await fetch(\n `https://api.thegreenwebfoundation.org/greencheck/${domain}`,\n {\n headers: getApiRequestHeaders(userAgentIdentifier),\n }\n );\n const res = await req.json();\n return res.green;\n}\n\n/**\n * Check if an array of domains is hosted by a green web host by querying the Green Web Foundation API.\n * @param {array} domains - An array of domains to check.\n * @param {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.\n * @returns {array} - An array of domains that are hosted by a green web host.\n */\n\nasync function checkDomainsAgainstAPI(domains, userAgentIdentifier) {\n try {\n const apiPath = \"https://api.thegreenwebfoundation.org/v2/greencheckmulti\";\n const domainsString = JSON.stringify(domains);\n\n const req = await fetch(`${apiPath}/${domainsString}`, {\n headers: getApiRequestHeaders(userAgentIdentifier),\n });\n\n const allGreenCheckResults = await req.json();\n\n return greenDomainsFromResults(allGreenCheckResults);\n } catch (e) {\n return [];\n }\n}\n\n/**\n * Extract the green domains from the results of a green check.\n * @param {object} greenResults - The results of a green check.\n * @returns {array} - An array of domains that are hosted by a green web host.\n */\nfunction greenDomainsFromResults(greenResults) {\n const entries = Object.entries(greenResults);\n const greenEntries = entries.filter(([key, val]) => val.green);\n return greenEntries.map(([key, val]) => val.url);\n}\n\nexport default {\n check,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAAqC;AAQrC,eAAe,QAAQ,qBAAqB;AAE1C,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,gBAAgB,QAAQ,mBAAmB;AAAA,EACpD,OAAO;AACL,WAAO,uBAAuB,QAAQ,mBAAmB;AAAA,EAC3D;AACF;AAQA,+BAA+B,QAAQ,qBAAqB;AAC1D,QAAM,MAAM,MAAM,MAChB,oDAAoD,UACpD;AAAA,IACE,SAAS,yCAAqB,mBAAmB;AAAA,EACnD,CACF;AACA,QAAM,MAAM,MAAM,IAAI,KAAK;AAC3B,SAAO,IAAI;AACb;AASA,sCAAsC,SAAS,qBAAqB;AAClE,MAAI;AACF,UAAM,UAAU;AAChB,UAAM,gBAAgB,KAAK,UAAU,OAAO;AAE5C,UAAM,MAAM,MAAM,MAAM,GAAG,WAAW,iBAAiB;AAAA,MACrD,SAAS,yCAAqB,mBAAmB;AAAA,IACnD,CAAC;AAED,UAAM,uBAAuB,MAAM,IAAI,KAAK;AAE5C,WAAO,wBAAwB,oBAAoB;AAAA,EACrD,SAAS,GAAP;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAOA,iCAAiC,cAAc;AAC7C,QAAM,UAAU,OAAO,QAAQ,YAAY;AAC3C,QAAM,eAAe,QAAQ,OAAO,CAAC,CAAC,KAAK,SAAS,IAAI,KAAK;AAC7D,SAAO,aAAa,IAAI,CAAC,CAAC,KAAK,SAAS,IAAI,GAAG;AACjD;AAEA,IAAO,sBAAQ;AAAA,EACb;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/hosting-node.js
CHANGED
|
@@ -25,9 +25,10 @@ __export(hosting_node_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(hosting_node_exports);
|
|
26
26
|
var import_https = __toESM(require("https"));
|
|
27
27
|
var import_hosting_json_node = __toESM(require("./hosting-json.node.js"));
|
|
28
|
-
|
|
28
|
+
var import_helpers = require("./helpers/index.js");
|
|
29
|
+
async function getBody(url, userAgentIdentifier) {
|
|
29
30
|
return new Promise(function(resolve, reject) {
|
|
30
|
-
const req = import_https.default.get(url, function(res) {
|
|
31
|
+
const req = import_https.default.get(url, { headers: (0, import_helpers.getApiRequestHeaders)(userAgentIdentifier) }, function(res) {
|
|
31
32
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
32
33
|
return reject(new Error(`Could not get info from: ${url}. Status Code: ${res.statusCode}`));
|
|
33
34
|
}
|
|
@@ -40,23 +41,23 @@ async function getBody(url) {
|
|
|
40
41
|
req.end();
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
|
-
function check(domain, db) {
|
|
44
|
+
function check(domain, db, userAgentIdentifier) {
|
|
44
45
|
if (db) {
|
|
45
46
|
return import_hosting_json_node.default.check(domain, db);
|
|
46
47
|
}
|
|
47
48
|
if (typeof domain === "string") {
|
|
48
|
-
return checkAgainstAPI(domain);
|
|
49
|
+
return checkAgainstAPI(domain, userAgentIdentifier);
|
|
49
50
|
} else {
|
|
50
|
-
return checkDomainsAgainstAPI(domain);
|
|
51
|
+
return checkDomainsAgainstAPI(domain, userAgentIdentifier);
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
|
-
async function checkAgainstAPI(domain) {
|
|
54
|
-
const res = JSON.parse(await getBody(`https://api.thegreenwebfoundation.org/greencheck/${domain}
|
|
54
|
+
async function checkAgainstAPI(domain, userAgentIdentifier) {
|
|
55
|
+
const res = JSON.parse(await getBody(`https://api.thegreenwebfoundation.org/greencheck/${domain}`, userAgentIdentifier));
|
|
55
56
|
return res.green;
|
|
56
57
|
}
|
|
57
|
-
async function checkDomainsAgainstAPI(domains) {
|
|
58
|
+
async function checkDomainsAgainstAPI(domains, userAgentIdentifier) {
|
|
58
59
|
try {
|
|
59
|
-
const allGreenCheckResults = JSON.parse(await getBody(`https://api.thegreenwebfoundation.org/v2/greencheckmulti/${JSON.stringify(domains)}
|
|
60
|
+
const allGreenCheckResults = JSON.parse(await getBody(`https://api.thegreenwebfoundation.org/v2/greencheckmulti/${JSON.stringify(domains)}`, userAgentIdentifier));
|
|
60
61
|
return import_hosting_json_node.default.greenDomainsFromResults(allGreenCheckResults);
|
|
61
62
|
} catch (e) {
|
|
62
63
|
return [];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hosting-node.js"],
|
|
4
|
-
"sourcesContent": ["/*\n\nWe have a separate node-specific hosting.js file for node.\nThis uses the node-specific APIs for making http requests,\nand doing lookups against local JSON and sqlite databases.\nThis is used in the CommonJS build of co2.js\n\nThis lets us keep the total library small, and dependencies minimal.\n*/\n\nimport https from \"https\";\n\nimport hostingJSON from \"./hosting-json.node.js\";\n\n/**\n * Accept a url and perform an http request, returning the body\n * for parsing as JSON.\n *\n * @param {string} url\n * @return {string}\n */\nasync function getBody(url) {\n return new Promise(function (resolve, reject) {\n // Do async job\n const req = https.get(url
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,mBAAkB;AAElB,+BAAwB;
|
|
4
|
+
"sourcesContent": ["/*\n\nWe have a separate node-specific hosting.js file for node.\nThis uses the node-specific APIs for making http requests,\nand doing lookups against local JSON and sqlite databases.\nThis is used in the CommonJS build of co2.js\n\nThis lets us keep the total library small, and dependencies minimal.\n*/\n\nimport https from \"https\";\n\nimport hostingJSON from \"./hosting-json.node.js\";\nimport { getApiRequestHeaders } from \"./helpers/index.js\";\n\n/**\n * Accept a url and perform an http request, returning the body\n * for parsing as JSON.\n *\n * @param {string} url\n * @param {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.\n * @return {string}\n */\nasync function getBody(url, userAgentIdentifier) {\n return new Promise(function (resolve, reject) {\n // Do async job\n const req = https.get(\n url,\n { headers: getApiRequestHeaders(userAgentIdentifier) },\n function (res) {\n if (res.statusCode < 200 || res.statusCode >= 300) {\n return reject(\n new Error(\n `Could not get info from: ${url}. Status Code: ${res.statusCode}`\n )\n );\n }\n const data = [];\n\n res.on(\"data\", (chunk) => {\n data.push(chunk);\n });\n\n res.on(\"end\", () => resolve(Buffer.concat(data).toString()));\n }\n );\n req.end();\n });\n}\n\n/**\n * Check if a domain is hosted by a green web host.\n * @param {string|array} domain - The domain to check, or an array of domains to be checked.\n * @param {object} db - Optional. A database object to use for lookups.\n * @param {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.\n * @returns {boolean|array} - A boolean if a string was provided, or an array of booleans if an array of domains was provided.\n */\n\nfunction check(domain, db, userAgentIdentifier) {\n if (db) {\n return hostingJSON.check(domain, db);\n }\n\n // is it a single domain or an array of them?\n if (typeof domain === \"string\") {\n return checkAgainstAPI(domain, userAgentIdentifier);\n } else {\n return checkDomainsAgainstAPI(domain, userAgentIdentifier);\n }\n}\n\n/**\n * Check if a domain is hosted by a green web host by querying the Green Web Foundation API.\n * @param {string} domain - The domain to check.\n * @param {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.\n * @returns {boolean} - A boolean indicating whether the domain is hosted by a green web host.\n */\nasync function checkAgainstAPI(domain, userAgentIdentifier) {\n const res = JSON.parse(\n await getBody(\n `https://api.thegreenwebfoundation.org/greencheck/${domain}`,\n userAgentIdentifier\n )\n );\n return res.green;\n}\n\n/**\n * Check if an array of domains is hosted by a green web host by querying the Green Web Foundation API.\n * @param {array} domains - An array of domains to check.\n * @param {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.\n * @returns {array} - An array of domains that are hosted by a green web host.\n */\nasync function checkDomainsAgainstAPI(domains, userAgentIdentifier) {\n try {\n const allGreenCheckResults = JSON.parse(\n await getBody(\n `https://api.thegreenwebfoundation.org/v2/greencheckmulti/${JSON.stringify(\n domains\n )}`,\n userAgentIdentifier\n )\n );\n return hostingJSON.greenDomainsFromResults(allGreenCheckResults);\n } catch (e) {\n return [];\n }\n}\n\n/**\n * Take the result of a pageXray and check the domains in it against the database.\n * @param {object} pageXray - The result of a pageXray.\n * @param {object} db - A database object to use for lookups.\n * @returns {array} - An array indicating whether the domain is hosted by a green web host.\n */\nasync function checkPage(pageXray, db) {\n const domains = Object.keys(pageXray.domains);\n return check(domains, db);\n}\n\nexport default {\n check,\n checkPage,\n greendomains: hostingJSON.greenDomainsFromResults,\n loadJSON: hostingJSON.loadJSON,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,mBAAkB;AAElB,+BAAwB;AACxB,qBAAqC;AAUrC,uBAAuB,KAAK,qBAAqB;AAC/C,SAAO,IAAI,QAAQ,SAAU,SAAS,QAAQ;AAE5C,UAAM,MAAM,qBAAM,IAChB,KACA,EAAE,SAAS,yCAAqB,mBAAmB,EAAE,GACrD,SAAU,KAAK;AACb,UAAI,IAAI,aAAa,OAAO,IAAI,cAAc,KAAK;AACjD,eAAO,OACL,IAAI,MACF,4BAA4B,qBAAqB,IAAI,YACvD,CACF;AAAA,MACF;AACA,YAAM,OAAO,CAAC;AAEd,UAAI,GAAG,QAAQ,CAAC,UAAU;AACxB,aAAK,KAAK,KAAK;AAAA,MACjB,CAAC;AAED,UAAI,GAAG,OAAO,MAAM,QAAQ,OAAO,OAAO,IAAI,EAAE,SAAS,CAAC,CAAC;AAAA,IAC7D,CACF;AACA,QAAI,IAAI;AAAA,EACV,CAAC;AACH;AAUA,eAAe,QAAQ,IAAI,qBAAqB;AAC9C,MAAI,IAAI;AACN,WAAO,iCAAY,MAAM,QAAQ,EAAE;AAAA,EACrC;AAGA,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,gBAAgB,QAAQ,mBAAmB;AAAA,EACpD,OAAO;AACL,WAAO,uBAAuB,QAAQ,mBAAmB;AAAA,EAC3D;AACF;AAQA,+BAA+B,QAAQ,qBAAqB;AAC1D,QAAM,MAAM,KAAK,MACf,MAAM,QACJ,oDAAoD,UACpD,mBACF,CACF;AACA,SAAO,IAAI;AACb;AAQA,sCAAsC,SAAS,qBAAqB;AAClE,MAAI;AACF,UAAM,uBAAuB,KAAK,MAChC,MAAM,QACJ,4DAA4D,KAAK,UAC/D,OACF,KACA,mBACF,CACF;AACA,WAAO,iCAAY,wBAAwB,oBAAoB;AAAA,EACjE,SAAS,GAAP;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAQA,yBAAyB,UAAU,IAAI;AACrC,QAAM,UAAU,OAAO,KAAK,SAAS,OAAO;AAC5C,SAAO,MAAM,SAAS,EAAE;AAC1B;AAEA,IAAO,uBAAQ;AAAA,EACb;AAAA,EACA;AAAA,EACA,cAAc,iCAAY;AAAA,EAC1B,UAAU,iCAAY;AACxB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/hosting.js
CHANGED
|
@@ -25,8 +25,8 @@ __export(hosting_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(hosting_exports);
|
|
27
27
|
var import_hosting_api = __toESM(require("./hosting-api.js"));
|
|
28
|
-
function check(domain) {
|
|
29
|
-
return import_hosting_api.default.check(domain);
|
|
28
|
+
function check(domain, userAgentIdentifier) {
|
|
29
|
+
return import_hosting_api.default.check(domain, userAgentIdentifier);
|
|
30
30
|
}
|
|
31
31
|
var hosting_default = {
|
|
32
32
|
check
|
package/dist/cjs/hosting.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hosting.js"],
|
|
4
|
-
"sourcesContent": ["\"use strict\";\n\nimport hostingAPI from \"./hosting-api.js\";\n\n/**\n * Check if a domain is hosted by a green web host.\n * @param {string|array} domain - The domain to check, or an array of domains to be checked.\n * @returns {boolean|array} - A boolean if a string was provided, or an array of booleans if an array of domains was provided.\n */\nfunction check(domain) {\n return hostingAPI.check(domain);\n}\n\nexport default {\n check,\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,yBAAuB;
|
|
4
|
+
"sourcesContent": ["\"use strict\";\n\nimport hostingAPI from \"./hosting-api.js\";\n\n/**\n * Check if a domain is hosted by a green web host.\n * @param {string|array} domain - The domain to check, or an array of domains to be checked.\n * @param {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.\n * @returns {boolean|array} - A boolean if a string was provided, or an array of booleans if an array of domains was provided.\n */\nfunction check(domain, userAgentIdentifier) {\n return hostingAPI.check(domain, userAgentIdentifier);\n}\n\nexport default {\n check,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,yBAAuB;AAQvB,eAAe,QAAQ,qBAAqB;AAC1C,SAAO,2BAAW,MAAM,QAAQ,mBAAmB;AACrD;AAEA,IAAO,kBAAQ;AAAA,EACb;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const data = { "AFG": 120.48, "AFRICA":
|
|
1
|
+
const data = { "AFG": 120.48, "AFRICA": 590.8, "ALB": 23.44, "DZA": 672.64, "ASM": 687.5, "AGO": 212.42, "ATG": 657.14, "ARG": 399.5, "ARM": 280.06, "ABW": 591.4, "ASEAN": 569.34, "ASIA": 594.16, "AUS": 570.35, "AUT": 141.79, "AZE": 719.39, "BHS": 698.11, "BHR": 956.55, "BGD": 719.78, "BRB": 644.86, "BLR": 465.34, "BEL": 139.79, "BLZ": 484.38, "BEN": 666.67, "BTN": 24.44, "BOL": 497.78, "BIH": 670.09, "BWA": 867.58, "BRA": 114.48, "BRN": 961.54, "BGR": 476.9, "BFA": 611.43, "BDI": 250, "CPV": 600, "KHM": 436.13, "CMR": 278.26, "CAN": 163.01, "CYM": 684.93, "CAF": 0, "TCD": 677.42, "CHL": 353.52, "CHN": 585.82, "COL": 198.53, "COM": 714.29, "COG": 723.88, "COD": 25.36, "COK": 400, "CRI": 37.21, "CIV": 453.55, "HRV": 242.28, "CUB": 677.47, "CYP": 555.13, "CZE": 488.3, "DNK": 201.78, "DJI": 666.67, "DMA": 529.41, "DOM": 592.49, "ECU": 192.39, "EGY": 612.16, "SLV": 211.29, "GNQ": 492.96, "ERI": 688.89, "EST": 489.89, "SWZ": 189.19, "ETH": 25.19, "EU": 291.9, "EUROPE": 330.47, "FLK": 500, "FRO": 428.57, "FJI": 289.47, "FIN": 130.42, "FRA": 78.81, "GUF": 254.72, "PYF": 471.43, "G20": 489.9, "G7": 375.97, "GAB": 397.38, "GMB": 700, "GEO": 176.97, "DEU": 420.06, "GHA": 498.81, "GRC": 378.18, "GRL": 133.33, "GRD": 714.29, "GLP": 647.06, "GUM": 670.33, "GTM": 331.72, "GIN": 208.63, "GNB": 750, "GUY": 642.28, "HTI": 606.06, "HND": 378.97, "HKG": 733.05, "HUN": 228.75, "ISL": 28.56, "IND": 705.13, "IDN": 675.93, "IRN": 665.15, "IRQ": 708.1, "IRL": 333.23, "ISR": 641.17, "ITA": 378.45, "JAM": 588.51, "JPN": 512.81, "JOR": 572.74, "KAZ": 830.41, "KEN": 101.13, "KIR": 666.67, "XKX": 945.01, "KWT": 691.31, "KGZ": 124.48, "LAO": 284.21, "LATIN AMERICA AND CARIBBEAN": 278.58, "LVA": 136.27, "LBN": 663.1, "LSO": 20, "LBR": 304.35, "LBY": 861.69, "LTU": 177.18, "LUX": 144.07, "MAC": 627.12, "MDG": 497.61, "MWI": 133.8, "MYS": 605.83, "MDV": 651.52, "MLI": 463.13, "MLT": 500, "MTQ": 698.63, "MRT": 526.6, "MUS": 631.94, "MEX": 515.62, "MIDDLE EAST": 673.63, "MDA": 871.66, "MNG": 852.82, "MNE": 483.38, "MSR": 1e3, "MAR": 705.67, "MOZ": 150.25, "MMR": 575.77, "NAM": 70.06, "NRU": 750, "NPL": 24.51, "NLD": 324.99, "NCL": 610.12, "NZL": 117.46, "NIC": 352.05, "NER": 622.22, "NGA": 513.24, "NORTH AMERICA": 378.27, "PRK": 124.57, "MKD": 639.86, "NOR": 26.5, "OCEANIA": 509.12, "OECD": 373.31, "OMN": 598.27, "PAK": 435.89, "PSE": 511.63, "PAN": 175, "PNG": 526.75, "PRY": 25.49, "PER": 312.59, "POL": 733.18, "PRT": 225.19, "PRI": 719.85, "QAT": 642.01, "REU": 519.03, "ROU": 297.94, "RUS": 451.95, "RWA": 294.12, "KNA": 681.82, "LCA": 685.71, "SPM": 800, "VCT": 500, "WSM": 470.59, "STP": 600, "SAU": 706.79, "SEN": 685.05, "SRB": 695.69, "SYC": 615.39, "SLE": 47.62, "SGP": 505.22, "SVK": 142.59, "SVN": 257.49, "SLB": 727.27, "SOM": 634.15, "ZAF": 762.46, "KOR": 470.4, "SSD": 684.21, "ESP": 217.77, "LKA": 543.12, "SDN": 288.13, "SUR": 356.44, "SWE": 41.07, "CHE": 36.14, "SYR": 758.35, "TWN": 678.87, "TJK": 99.34, "TZA": 374.08, "THA": 599.02, "PHL": 641.96, "TGO": 492.06, "TON": 625, "TTO": 723.94, "TUN": 592.21, "TUR": 453.01, "TKM": 1389.72, "TCA": 703.7, "UGA": 52.27, "UKR": 271.41, "ARE": 561.14, "GBR": 255.85, "USA": 410.37, "URY": 149.49, "UZB": 1176.69, "VUT": 571.43, "VEN": 298.5, "VNM": 409.8, "VGB": 714.29, "VIR": 685.71, "WORLD": 493.92, "YEM": 613.64, "ZMB": 86.39, "ZWE": 433.38 };
|
|
2
2
|
const type = "average";
|
|
3
3
|
var average_intensities_min_default = { data, type };
|
|
4
4
|
export {
|
|
@@ -141,7 +141,11 @@ Falling back to default value.`);
|
|
|
141
141
|
}
|
|
142
142
|
return adjustments;
|
|
143
143
|
}
|
|
144
|
+
function getApiRequestHeaders(comment = "") {
|
|
145
|
+
return { "User-Agent": `co2js/${"0.14.3"} ${comment}` };
|
|
146
|
+
}
|
|
144
147
|
export {
|
|
145
148
|
formatNumber,
|
|
149
|
+
getApiRequestHeaders,
|
|
146
150
|
parseOptions
|
|
147
151
|
};
|
package/dist/esm/hosting-api.js
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
import { getApiRequestHeaders } from "./helpers/index.js";
|
|
3
|
+
function check(domain, userAgentIdentifier) {
|
|
3
4
|
if (typeof domain === "string") {
|
|
4
|
-
return checkAgainstAPI(domain);
|
|
5
|
+
return checkAgainstAPI(domain, userAgentIdentifier);
|
|
5
6
|
} else {
|
|
6
|
-
return checkDomainsAgainstAPI(domain);
|
|
7
|
+
return checkDomainsAgainstAPI(domain, userAgentIdentifier);
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
|
-
async function checkAgainstAPI(domain) {
|
|
10
|
-
const req = await fetch(`https://api.thegreenwebfoundation.org/greencheck/${domain}
|
|
10
|
+
async function checkAgainstAPI(domain, userAgentIdentifier) {
|
|
11
|
+
const req = await fetch(`https://api.thegreenwebfoundation.org/greencheck/${domain}`, {
|
|
12
|
+
headers: getApiRequestHeaders(userAgentIdentifier)
|
|
13
|
+
});
|
|
11
14
|
const res = await req.json();
|
|
12
15
|
return res.green;
|
|
13
16
|
}
|
|
14
|
-
async function checkDomainsAgainstAPI(domains) {
|
|
17
|
+
async function checkDomainsAgainstAPI(domains, userAgentIdentifier) {
|
|
15
18
|
try {
|
|
16
19
|
const apiPath = "https://api.thegreenwebfoundation.org/v2/greencheckmulti";
|
|
17
20
|
const domainsString = JSON.stringify(domains);
|
|
18
|
-
const req = await fetch(`${apiPath}/${domainsString}
|
|
21
|
+
const req = await fetch(`${apiPath}/${domainsString}`, {
|
|
22
|
+
headers: getApiRequestHeaders(userAgentIdentifier)
|
|
23
|
+
});
|
|
19
24
|
const allGreenCheckResults = await req.json();
|
|
20
25
|
return greenDomainsFromResults(allGreenCheckResults);
|
|
21
26
|
} catch (e) {
|
package/dist/esm/hosting.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tgwf/co2",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3",
|
|
4
4
|
"description": "Work out the co2 of your digital services",
|
|
5
5
|
"main": "dist/cjs/index-node.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"intensity-data:average": "node data/functions/generate_average_co2.js",
|
|
30
30
|
"intensity-data:marginal": "node data/functions/generate_marginal_co2.js",
|
|
31
31
|
"intensity-data": "npm run intensity-data:average && npm run intensity-data:marginal && npm run format-data",
|
|
32
|
-
"format-data": "cd data && prettier --write '**/*.{js,json}'"
|
|
32
|
+
"format-data": "cd data && prettier --write '**/*.{js,json}'",
|
|
33
|
+
"version": "npm run build"
|
|
33
34
|
},
|
|
34
35
|
"keywords": [
|
|
35
36
|
"sustainability",
|