@tgwf/co2 0.13.7 → 0.13.8
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/.all-contributorsrc +10 -0
- package/CHANGELOG.md +14 -4
- package/README.md +2 -1
- package/data/output/average-intensities.js +1 -1
- package/data/output/average-intensities.json +1 -1
- package/dist/cjs/co2.js +9 -9
- package/dist/cjs/co2.js.map +1 -1
- package/dist/cjs/data/average-intensities.min.js +1 -1
- package/dist/cjs/data/average-intensities.min.js.map +1 -1
- package/dist/cjs/helpers/index.js +6 -6
- package/dist/cjs/helpers/index.js.map +2 -2
- package/dist/data/functions/generate_average_co2.d.ts +2 -0
- package/dist/data/functions/generate_average_co2.d.ts.map +1 -0
- package/dist/data/functions/generate_marginal_co2.d.ts +2 -0
- package/dist/data/functions/generate_marginal_co2.d.ts.map +1 -0
- package/dist/data/output/average-intensities.d.ts +231 -0
- package/dist/data/output/average-intensities.d.ts.map +1 -0
- package/dist/data/output/marginal-intensities-2021.d.ts +243 -0
- package/dist/data/output/marginal-intensities-2021.d.ts.map +1 -0
- package/dist/data/utils/getCountryCodes.d.ts +3 -0
- package/dist/data/utils/getCountryCodes.d.ts.map +1 -0
- package/dist/data/utils/mapCountries.d.ts +3 -0
- package/dist/data/utils/mapCountries.d.ts.map +1 -0
- package/dist/data/utils/parseCSVRow.d.ts +8 -0
- package/dist/data/utils/parseCSVRow.d.ts.map +1 -0
- package/dist/esm/co2.js +11 -11
- package/dist/esm/data/average-intensities.min.js +1 -1
- package/dist/esm/helpers/index.js +6 -6
- package/dist/iife/index.js +12 -12
- package/dist/iife/index.js.map +2 -2
- package/package.json +1 -1
- package/src/co2.js +9 -9
- package/src/data/average-intensities.min.js +1 -1
- package/src/helpers/index.js +6 -6
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
export { data };
|
|
3
|
+
export { type };
|
|
4
|
+
export { year };
|
|
5
|
+
}
|
|
6
|
+
export default _default;
|
|
7
|
+
export const data: {
|
|
8
|
+
AFG: string;
|
|
9
|
+
ALB: string;
|
|
10
|
+
DZA: string;
|
|
11
|
+
ASM: string;
|
|
12
|
+
AND: string;
|
|
13
|
+
AGO: string;
|
|
14
|
+
AIA: string;
|
|
15
|
+
ATG: string;
|
|
16
|
+
ARG: string;
|
|
17
|
+
ARM: string;
|
|
18
|
+
ABW: string;
|
|
19
|
+
AUS: string;
|
|
20
|
+
AUT: string;
|
|
21
|
+
AZE: string;
|
|
22
|
+
"AZORES (PORTUGAL)": string;
|
|
23
|
+
BHS: string;
|
|
24
|
+
BHR: string;
|
|
25
|
+
BGD: string;
|
|
26
|
+
BRB: string;
|
|
27
|
+
BLR: string;
|
|
28
|
+
BEL: string;
|
|
29
|
+
BLZ: string;
|
|
30
|
+
BEN: string;
|
|
31
|
+
BMU: string;
|
|
32
|
+
BTN: string;
|
|
33
|
+
BOL: string;
|
|
34
|
+
BES: string;
|
|
35
|
+
BIH: string;
|
|
36
|
+
BWA: string;
|
|
37
|
+
BRA: string;
|
|
38
|
+
VGB: string;
|
|
39
|
+
BRN: string;
|
|
40
|
+
BGR: string;
|
|
41
|
+
BFA: string;
|
|
42
|
+
BDI: string;
|
|
43
|
+
KHM: string;
|
|
44
|
+
CMR: string;
|
|
45
|
+
CAN: string;
|
|
46
|
+
CYM: string;
|
|
47
|
+
CPV: string;
|
|
48
|
+
CAF: string;
|
|
49
|
+
TCD: string;
|
|
50
|
+
"CHANNEL ISLANDS (U.K)": string;
|
|
51
|
+
CHL: string;
|
|
52
|
+
CHN: string;
|
|
53
|
+
COL: string;
|
|
54
|
+
COM: string;
|
|
55
|
+
COD: string;
|
|
56
|
+
COG: string;
|
|
57
|
+
COK: string;
|
|
58
|
+
CRI: string;
|
|
59
|
+
CIV: string;
|
|
60
|
+
HRV: string;
|
|
61
|
+
CUB: string;
|
|
62
|
+
CUW: string;
|
|
63
|
+
CYP: string;
|
|
64
|
+
CZE: string;
|
|
65
|
+
DNK: string;
|
|
66
|
+
DJI: string;
|
|
67
|
+
DMA: string;
|
|
68
|
+
DOM: string;
|
|
69
|
+
ECU: string;
|
|
70
|
+
EGY: string;
|
|
71
|
+
SLV: string;
|
|
72
|
+
GNQ: string;
|
|
73
|
+
ERI: string;
|
|
74
|
+
EST: string;
|
|
75
|
+
SWZ: string;
|
|
76
|
+
ETH: string;
|
|
77
|
+
FLK: string;
|
|
78
|
+
FRO: string;
|
|
79
|
+
FJI: string;
|
|
80
|
+
FIN: string;
|
|
81
|
+
FRA: string;
|
|
82
|
+
GUF: string;
|
|
83
|
+
PYF: string;
|
|
84
|
+
GAB: string;
|
|
85
|
+
GMB: string;
|
|
86
|
+
GEO: string;
|
|
87
|
+
DEU: string;
|
|
88
|
+
GHA: string;
|
|
89
|
+
GIB: string;
|
|
90
|
+
GRC: string;
|
|
91
|
+
GRL: string;
|
|
92
|
+
GRD: string;
|
|
93
|
+
GLP: string;
|
|
94
|
+
GUM: string;
|
|
95
|
+
GTM: string;
|
|
96
|
+
GIN: string;
|
|
97
|
+
GNB: string;
|
|
98
|
+
GUY: string;
|
|
99
|
+
HTI: string;
|
|
100
|
+
HND: string;
|
|
101
|
+
HUN: string;
|
|
102
|
+
ISL: string;
|
|
103
|
+
IND: string;
|
|
104
|
+
IDN: string;
|
|
105
|
+
IRN: string;
|
|
106
|
+
IRQ: string;
|
|
107
|
+
IRL: string;
|
|
108
|
+
IMN: string;
|
|
109
|
+
ISR: string;
|
|
110
|
+
ITA: string;
|
|
111
|
+
JAM: string;
|
|
112
|
+
JPN: string;
|
|
113
|
+
JOR: string;
|
|
114
|
+
KAZ: string;
|
|
115
|
+
KEN: string;
|
|
116
|
+
KIR: string;
|
|
117
|
+
PRK: string;
|
|
118
|
+
KOR: string;
|
|
119
|
+
XKX: string;
|
|
120
|
+
KWT: string;
|
|
121
|
+
KGZ: string;
|
|
122
|
+
LAO: string;
|
|
123
|
+
LVA: string;
|
|
124
|
+
LBN: string;
|
|
125
|
+
LSO: string;
|
|
126
|
+
LBR: string;
|
|
127
|
+
LBY: string;
|
|
128
|
+
LIE: string;
|
|
129
|
+
LTU: string;
|
|
130
|
+
LUX: string;
|
|
131
|
+
MDG: string;
|
|
132
|
+
"MADEIRA (PORTUGAL)": string;
|
|
133
|
+
MWI: string;
|
|
134
|
+
MYS: string;
|
|
135
|
+
MDV: string;
|
|
136
|
+
MLI: string;
|
|
137
|
+
MLT: string;
|
|
138
|
+
MHL: string;
|
|
139
|
+
MTQ: string;
|
|
140
|
+
MRT: string;
|
|
141
|
+
MUS: string;
|
|
142
|
+
MYT: string;
|
|
143
|
+
MEX: string;
|
|
144
|
+
FSM: string;
|
|
145
|
+
MDA: string;
|
|
146
|
+
MCO: string;
|
|
147
|
+
MNG: string;
|
|
148
|
+
MNE: string;
|
|
149
|
+
MSR: string;
|
|
150
|
+
MAR: string;
|
|
151
|
+
MOZ: string;
|
|
152
|
+
MMR: string;
|
|
153
|
+
NAM: string;
|
|
154
|
+
NRU: string;
|
|
155
|
+
NPL: string;
|
|
156
|
+
NLD: string;
|
|
157
|
+
NCL: string;
|
|
158
|
+
NZL: string;
|
|
159
|
+
NIC: string;
|
|
160
|
+
NER: string;
|
|
161
|
+
NGA: string;
|
|
162
|
+
NIU: string;
|
|
163
|
+
MKD: string;
|
|
164
|
+
MNP: string;
|
|
165
|
+
NOR: string;
|
|
166
|
+
OMN: string;
|
|
167
|
+
PAK: string;
|
|
168
|
+
PLW: string;
|
|
169
|
+
PSE: string;
|
|
170
|
+
PAN: string;
|
|
171
|
+
PNG: string;
|
|
172
|
+
PRY: string;
|
|
173
|
+
PER: string;
|
|
174
|
+
PHL: string;
|
|
175
|
+
POL: string;
|
|
176
|
+
PRT: string;
|
|
177
|
+
PRI: string;
|
|
178
|
+
QAT: string;
|
|
179
|
+
REU: string;
|
|
180
|
+
ROU: string;
|
|
181
|
+
RUS: string;
|
|
182
|
+
RWA: string;
|
|
183
|
+
SHN: string;
|
|
184
|
+
KNA: string;
|
|
185
|
+
LCA: string;
|
|
186
|
+
MAF: string;
|
|
187
|
+
SPM: string;
|
|
188
|
+
VCT: string;
|
|
189
|
+
WSM: string;
|
|
190
|
+
SMR: string;
|
|
191
|
+
STP: string;
|
|
192
|
+
SAU: string;
|
|
193
|
+
SEN: string;
|
|
194
|
+
SRB: string;
|
|
195
|
+
SYC: string;
|
|
196
|
+
SLE: string;
|
|
197
|
+
SGP: string;
|
|
198
|
+
SXM: string;
|
|
199
|
+
SVK: string;
|
|
200
|
+
SVN: string;
|
|
201
|
+
SLB: string;
|
|
202
|
+
SOM: string;
|
|
203
|
+
ZAF: string;
|
|
204
|
+
SSD: string;
|
|
205
|
+
ESP: string;
|
|
206
|
+
LKA: string;
|
|
207
|
+
SDN: string;
|
|
208
|
+
SUR: string;
|
|
209
|
+
SWE: string;
|
|
210
|
+
CHE: string;
|
|
211
|
+
SYR: string;
|
|
212
|
+
TWN: string;
|
|
213
|
+
TJK: string;
|
|
214
|
+
TZA: string;
|
|
215
|
+
THA: string;
|
|
216
|
+
TLS: string;
|
|
217
|
+
TGO: string;
|
|
218
|
+
TON: string;
|
|
219
|
+
TTO: string;
|
|
220
|
+
TUN: string;
|
|
221
|
+
TUR: string;
|
|
222
|
+
TKM: string;
|
|
223
|
+
TCA: string;
|
|
224
|
+
TUV: string;
|
|
225
|
+
UGA: string;
|
|
226
|
+
UKR: string;
|
|
227
|
+
ARE: string;
|
|
228
|
+
GBR: string;
|
|
229
|
+
USA: string;
|
|
230
|
+
URY: string;
|
|
231
|
+
UZB: string;
|
|
232
|
+
VUT: string;
|
|
233
|
+
VEN: string;
|
|
234
|
+
VNM: string;
|
|
235
|
+
VIR: string;
|
|
236
|
+
YEM: string;
|
|
237
|
+
ZMB: string;
|
|
238
|
+
ZWE: string;
|
|
239
|
+
"MEMO: EU 27": string;
|
|
240
|
+
};
|
|
241
|
+
export const type: "marginal";
|
|
242
|
+
export const year: "2021";
|
|
243
|
+
//# sourceMappingURL=marginal-intensities-2021.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marginal-intensities-2021.d.ts","sourceRoot":"","sources":["../../../data/output/marginal-intensities-2021.js"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyOE;AACF,8BAAwB;AACxB,0BAAoB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCountryCodes.d.ts","sourceRoot":"","sources":["../../../data/utils/getCountryCodes.js"],"names":[],"mappings":";AAeA,8DAQC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapCountries.d.ts","sourceRoot":"","sources":["../../../data/utils/mapCountries.js"],"names":[],"mappings":";AAeA,uCAkBC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export = parseCSVRow;
|
|
2
|
+
/**
|
|
3
|
+
* Parses a string from a comma separated CSV file and returns an array of values.
|
|
4
|
+
* @param {string} currentArrayString - The string to parse.
|
|
5
|
+
* @returns {array} - Returns an array of values.
|
|
6
|
+
*/
|
|
7
|
+
declare function parseCSVRow(currentArrayString: string): any[];
|
|
8
|
+
//# sourceMappingURL=parseCSVRow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseCSVRow.d.ts","sourceRoot":"","sources":["../../../data/utils/parseCSVRow.js"],"names":[],"mappings":";AAAA;;;;GAIG;AAEH,iDAJW,MAAM,SAwBd"}
|
package/dist/esm/co2.js
CHANGED
|
@@ -32,7 +32,7 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
perByteTrace(bytes, green = false, options = {}) {
|
|
35
|
-
var _a, _b, _c, _d, _e, _f;
|
|
35
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
36
36
|
let adjustments = {};
|
|
37
37
|
if (options) {
|
|
38
38
|
adjustments = parseOptions(options);
|
|
@@ -45,16 +45,16 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
|
|
|
45
45
|
bytes,
|
|
46
46
|
gridIntensity: {
|
|
47
47
|
description: "The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",
|
|
48
|
-
network: ((_b = (_a = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _a.network) == null ? void 0 : _b.value)
|
|
49
|
-
dataCenter: green ? RENEWABLES_GRID_INTENSITY : ((
|
|
48
|
+
network: (_c = (_b = (_a = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _a.network) == null ? void 0 : _b.value) != null ? _c : GLOBAL_GRID_INTENSITY,
|
|
49
|
+
dataCenter: green ? RENEWABLES_GRID_INTENSITY : (_f = (_e = (_d = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _d.dataCenter) == null ? void 0 : _e.value) != null ? _f : GLOBAL_GRID_INTENSITY,
|
|
50
50
|
production: GLOBAL_GRID_INTENSITY,
|
|
51
|
-
device: ((
|
|
51
|
+
device: (_i = (_h = (_g = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _g.device) == null ? void 0 : _h.value) != null ? _i : GLOBAL_GRID_INTENSITY
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
perVisitTrace(bytes, green = false, options = {}) {
|
|
57
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
57
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
58
58
|
if ((_a = this.model) == null ? void 0 : _a.perVisit) {
|
|
59
59
|
let adjustments = {};
|
|
60
60
|
if (options) {
|
|
@@ -68,14 +68,14 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
|
|
|
68
68
|
bytes,
|
|
69
69
|
gridIntensity: {
|
|
70
70
|
description: "The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",
|
|
71
|
-
network: ((_c = (_b = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _b.network) == null ? void 0 : _c.value)
|
|
72
|
-
dataCenter: green ? RENEWABLES_GRID_INTENSITY : ((
|
|
71
|
+
network: (_d = (_c = (_b = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _b.network) == null ? void 0 : _c.value) != null ? _d : GLOBAL_GRID_INTENSITY,
|
|
72
|
+
dataCenter: green ? RENEWABLES_GRID_INTENSITY : (_g = (_f = (_e = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _e.dataCenter) == null ? void 0 : _f.value) != null ? _g : GLOBAL_GRID_INTENSITY,
|
|
73
73
|
production: GLOBAL_GRID_INTENSITY,
|
|
74
|
-
device: ((
|
|
74
|
+
device: (_j = (_i = (_h = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _h.device) == null ? void 0 : _i.value) != null ? _j : GLOBAL_GRID_INTENSITY
|
|
75
75
|
},
|
|
76
|
-
dataReloadRatio: (adjustments == null ? void 0 : adjustments.dataReloadRatio)
|
|
77
|
-
firstVisitPercentage: (adjustments == null ? void 0 : adjustments.firstVisitPercentage)
|
|
78
|
-
returnVisitPercentage: (adjustments == null ? void 0 : adjustments.returnVisitPercentage)
|
|
76
|
+
dataReloadRatio: (_k = adjustments == null ? void 0 : adjustments.dataReloadRatio) != null ? _k : 0.02,
|
|
77
|
+
firstVisitPercentage: (_l = adjustments == null ? void 0 : adjustments.firstVisitPercentage) != null ? _l : 0.75,
|
|
78
|
+
returnVisitPercentage: (_m = adjustments == null ? void 0 : adjustments.returnVisitPercentage) != null ? _m : 0.25
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
81
|
} else {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const data = { "AFG": 120.48, "AFRICA": 484.16, "ALB": 23.44, "DZA": 498.9, "ASM": 687.5, "AGO": 195.98, "ATG": 657.14, "ARG": 344.31, "ARM": 222.68, "ABW": 591.4, "ASEAN": 508.06, "ASIA": 535.23, "AUS": 501.7, "AUT": 157.52, "AZE": 532.9, "BHS": 698.11, "BHR": 494.02, "BGD": 577.03, "BRB": 644.86, "BLR": 415.64, "BEL": 165.36, "BLZ": 484.38, "BEN": 666.67, "BTN": 24.44, "BOL": 322.09, "BIH": 516.01, "BWA": 794.52, "BRA": 102.09, "BRN": 658.85, "BGR": 399.57, "BFA": 611.43, "BDI": 250, "CPV": 600, "KHM": 400.46, "CMR": 278.26, "CAN": 125.84, "CYM": 684.93, "CAF": 0, "TCD": 677.42, "CHL": 332.61, "CHN": 533.98, "COL": 168.95, "COM": 714.29, "COG": 395.52, "COD": 25.36, "COK": 400, "CRI": 37.21, "CIV": 410.75, "HRV": 246.46, "CUB": 602.23, "CYP": 589.35, "CZE": 415.35, "DNK": 180.71, "DJI": 666.67, "DMA": 529.41, "DOM": 549.8, "ECU": 188.71, "EGY": 469.63, "SLV": 194.23, "GNQ": 492.96, "ERI": 688.89, "EST": 464.03, "SWZ": 189.19, "ETH": 25.19, "EU": 277.19, "EUROPE": 296.45, "FLK": 500, "FRO": 428.57, "FJI": 289.47, "FIN": 130.98, "FRA": 84.82, "GUF": 254.72, "PYF": 471.43, "G20": 442.38, "G7": 343.92, "GAB": 397.38, "GMB": 700, "GEO": 134.83, "DEU": 384.83, "GHA": 361.2, "GRC": 343.82, "GRL": 133.33, "GRD": 714.29, "GLP": 623.53, "GUM": 670.33, "GTM": 291.55, "GIN": 208.63, "GNB": 750, "GUY": 642.28, "HTI": 606.06, "HND": 373.96, "HKG": 683.97, "HUN": 222.97, "ISL": 28.56, "IND": 633.4, "IDN": 619.02, "IRN": 487.86, "IRQ": 498.87, "IRL": 346.33, "ISR": 548.03, "ITA": 371.69, "JAM": 537.93, "JPN": 494.86, "JOR": 399.91, "KAZ": 635.57, "KEN": 100.57, "KIR": 666.67, "XKX": 768.73, "KWT": 551.74, "KGZ": 104.43, "LAO": 242.18, "LATIN AMERICA AND CARIBBEAN": 238.68, "LVA": 181.82, "LBN": 605.74, "LSO": 20, "LBR": 304.35, "LBY": 550.42, "LTU": 194.25, "LUX": 168.14, "MAC": 491.53, "MDG": 483.25, "MWI": 133.8, "MYS": 543.87, "MDV": 651.52, "MLI": 463.13, "MLT": 495, "MTQ": 698.63, "MRT": 526.6, "MUS": 611.11, "MEX": 423.81, "MIDDLE EAST": 516.02, "MDA": 677.18, "MNG": 749.66, "MNE": 399.38, "MSR": 1e3, "MAR": 610.41, "MOZ": 126.63, "MMR": 344.37, "NAM": 63.69, "NRU": 750, "NPL": 24.51, "NLD": 355.78, "NCL": 610.12, "NZL": 97.73, "NIC": 354.21, "NER": 622.22, "NGA": 368.11, "NORTH AMERICA": 336.01, "PRK": 157.79, "MKD": 529.33, "NOR": 28.82, "OCEANIA": 449.71, "OECD": 340.95, "OMN": 488.27, "PAK": 344.16, "PSE": 465.12, "PAN": 186.61, "PNG": 526.75, "PRY": 25.49, "PER": 256.51, "POL": 633.1, "PRT": 234.03, "PRI": 681.47, "QAT": 489.88, "REU": 519.03, "ROU": 264.12, "RUS": 363.68, "RWA": 294.12, "KNA": 681.82, "LCA": 685.71, "SPM": 800, "VCT": 500, "WSM": 470.59, "STP": 600, "SAU": 557.78, "SEN": 523.13, "SRB": 569.38, "SYC": 615.39, "SLE": 47.62, "SGP": 488.78, "SVK": 140.67, "SVN": 237.38, "SLB": 727.27, "SOM": 634.15, "ZAF": 708.19, "KOR": 437.6, "SSD": 684.21, "ESP": 217.37, "LKA": 463, "SDN": 264.01, "SUR": 356.44, "SWE": 45.08, "CHE": 45.62, "SYR": 541.17, "TWN":
|
|
1
|
+
const data = { "AFG": 120.48, "AFRICA": 484.16, "ALB": 23.44, "DZA": 498.9, "ASM": 687.5, "AGO": 195.98, "ATG": 657.14, "ARG": 344.31, "ARM": 222.68, "ABW": 591.4, "ASEAN": 508.06, "ASIA": 535.23, "AUS": 501.7, "AUT": 157.52, "AZE": 532.9, "BHS": 698.11, "BHR": 494.02, "BGD": 577.03, "BRB": 644.86, "BLR": 415.64, "BEL": 165.36, "BLZ": 484.38, "BEN": 666.67, "BTN": 24.44, "BOL": 322.09, "BIH": 516.01, "BWA": 794.52, "BRA": 102.09, "BRN": 658.85, "BGR": 399.57, "BFA": 611.43, "BDI": 250, "CPV": 600, "KHM": 400.46, "CMR": 278.26, "CAN": 125.84, "CYM": 684.93, "CAF": 0, "TCD": 677.42, "CHL": 332.61, "CHN": 533.98, "COL": 168.95, "COM": 714.29, "COG": 395.52, "COD": 25.36, "COK": 400, "CRI": 37.21, "CIV": 410.75, "HRV": 246.46, "CUB": 602.23, "CYP": 589.35, "CZE": 415.35, "DNK": 180.71, "DJI": 666.67, "DMA": 529.41, "DOM": 549.8, "ECU": 188.71, "EGY": 469.63, "SLV": 194.23, "GNQ": 492.96, "ERI": 688.89, "EST": 464.03, "SWZ": 189.19, "ETH": 25.19, "EU": 277.19, "EUROPE": 296.45, "FLK": 500, "FRO": 428.57, "FJI": 289.47, "FIN": 130.98, "FRA": 84.82, "GUF": 254.72, "PYF": 471.43, "G20": 442.38, "G7": 343.92, "GAB": 397.38, "GMB": 700, "GEO": 134.83, "DEU": 384.83, "GHA": 361.2, "GRC": 343.82, "GRL": 133.33, "GRD": 714.29, "GLP": 623.53, "GUM": 670.33, "GTM": 291.55, "GIN": 208.63, "GNB": 750, "GUY": 642.28, "HTI": 606.06, "HND": 373.96, "HKG": 683.97, "HUN": 222.97, "ISL": 28.56, "IND": 633.4, "IDN": 619.02, "IRN": 487.86, "IRQ": 498.87, "IRL": 346.33, "ISR": 548.03, "ITA": 371.69, "JAM": 537.93, "JPN": 494.86, "JOR": 399.91, "KAZ": 635.57, "KEN": 100.57, "KIR": 666.67, "XKX": 768.73, "KWT": 551.74, "KGZ": 104.43, "LAO": 242.18, "LATIN AMERICA AND CARIBBEAN": 238.68, "LVA": 181.82, "LBN": 605.74, "LSO": 20, "LBR": 304.35, "LBY": 550.42, "LTU": 194.25, "LUX": 168.14, "MAC": 491.53, "MDG": 483.25, "MWI": 133.8, "MYS": 543.87, "MDV": 651.52, "MLI": 463.13, "MLT": 495, "MTQ": 698.63, "MRT": 526.6, "MUS": 611.11, "MEX": 423.81, "MIDDLE EAST": 516.02, "MDA": 677.18, "MNG": 749.66, "MNE": 399.38, "MSR": 1e3, "MAR": 610.41, "MOZ": 126.63, "MMR": 344.37, "NAM": 63.69, "NRU": 750, "NPL": 24.51, "NLD": 355.78, "NCL": 610.12, "NZL": 97.73, "NIC": 354.21, "NER": 622.22, "NGA": 368.11, "NORTH AMERICA": 336.01, "PRK": 157.79, "MKD": 529.33, "NOR": 28.82, "OCEANIA": 449.71, "OECD": 340.95, "OMN": 488.27, "PAK": 344.16, "PSE": 465.12, "PAN": 186.61, "PNG": 526.75, "PRY": 25.49, "PER": 256.51, "POL": 633.1, "PRT": 234.03, "PRI": 681.47, "QAT": 489.88, "REU": 519.03, "ROU": 264.12, "RUS": 363.68, "RWA": 294.12, "KNA": 681.82, "LCA": 685.71, "SPM": 800, "VCT": 500, "WSM": 470.59, "STP": 600, "SAU": 557.78, "SEN": 523.13, "SRB": 569.38, "SYC": 615.39, "SLE": 47.62, "SGP": 488.78, "SVK": 140.67, "SVN": 237.38, "SLB": 727.27, "SOM": 634.15, "ZAF": 708.19, "KOR": 437.6, "SSD": 684.21, "ESP": 217.37, "LKA": 463, "SDN": 264.01, "SUR": 356.44, "SWE": 45.08, "CHE": 45.62, "SYR": 541.17, "TWN": 560.98, "TJK": 83.63, "TZA": 366.75, "THA": 501.57, "PHL": 582.84, "TGO": 460.32, "TON": 625, "TTO": 491.41, "TUN": 469.43, "TUR": 413.63, "TKM": 490.19, "TCA": 703.7, "UGA": 52.27, "UKR": 187.06, "ARE": 407.98, "GBR": 261.24, "USA": 367.26, "URY": 114.89, "UZB": 505.41, "VUT": 571.43, "VEN": 212.48, "VNM": 386.49, "VGB": 714.29, "VIR": 685.71, "WORLD": 437.26, "YEM": 543.91, "ZMB": 84.7, "ZWE": 392.28 };
|
|
2
2
|
const type = "average";
|
|
3
3
|
var average_intensities_min_default = { data, type };
|
|
4
4
|
export {
|
|
@@ -15,7 +15,7 @@ function parseOptions(options) {
|
|
|
15
15
|
if (options == null ? void 0 : options.gridIntensity) {
|
|
16
16
|
adjustments.gridIntensity = {};
|
|
17
17
|
const { device, dataCenter, network } = options.gridIntensity;
|
|
18
|
-
if (device) {
|
|
18
|
+
if (device || device === 0) {
|
|
19
19
|
if (typeof device === "object") {
|
|
20
20
|
if (!averageIntensity.data[(_a = device.country) == null ? void 0 : _a.toUpperCase()]) {
|
|
21
21
|
console.warn(`"${device.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
@@ -41,7 +41,7 @@ Falling back to global average grid intensity.`);
|
|
|
41
41
|
Falling back to global average grid intensity.`);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
if (dataCenter) {
|
|
44
|
+
if (dataCenter || dataCenter === 0) {
|
|
45
45
|
if (typeof dataCenter === "object") {
|
|
46
46
|
if (!averageIntensity.data[(_c = dataCenter.country) == null ? void 0 : _c.toUpperCase()]) {
|
|
47
47
|
console.warn(`"${dataCenter.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
@@ -67,7 +67,7 @@ Falling back to global average grid intensity.`);
|
|
|
67
67
|
Falling back to global average grid intensity.`);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
if (network) {
|
|
70
|
+
if (network || network === 0) {
|
|
71
71
|
if (typeof network === "object") {
|
|
72
72
|
if (!averageIntensity.data[(_e = network.country) == null ? void 0 : _e.toUpperCase()]) {
|
|
73
73
|
console.warn(`"${network.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
@@ -94,7 +94,7 @@ Falling back to global average grid intensity.`);
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
if (options == null ? void 0 : options.dataReloadRatio) {
|
|
97
|
+
if ((options == null ? void 0 : options.dataReloadRatio) || options.dataReloadRatio === 0) {
|
|
98
98
|
if (typeof options.dataReloadRatio === "number") {
|
|
99
99
|
if (options.dataReloadRatio >= 0 && options.dataReloadRatio <= 1) {
|
|
100
100
|
adjustments.dataReloadRatio = options.dataReloadRatio;
|
|
@@ -109,7 +109,7 @@ Falling back to default value.`);
|
|
|
109
109
|
Falling back to default value.`);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
if (options == null ? void 0 : options.firstVisitPercentage) {
|
|
112
|
+
if ((options == null ? void 0 : options.firstVisitPercentage) || options.firstVisitPercentage === 0) {
|
|
113
113
|
if (typeof options.firstVisitPercentage === "number") {
|
|
114
114
|
if (options.firstVisitPercentage >= 0 && options.firstVisitPercentage <= 1) {
|
|
115
115
|
adjustments.firstVisitPercentage = options.firstVisitPercentage;
|
|
@@ -124,7 +124,7 @@ Falling back to default value.`);
|
|
|
124
124
|
Falling back to default value.`);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
if (options == null ? void 0 : options.returnVisitPercentage) {
|
|
127
|
+
if ((options == null ? void 0 : options.returnVisitPercentage) || options.returnVisitPercentage === 0) {
|
|
128
128
|
if (typeof options.returnVisitPercentage === "number") {
|
|
129
129
|
if (options.returnVisitPercentage >= 0 && options.returnVisitPercentage <= 1) {
|
|
130
130
|
adjustments.returnVisitPercentage = options.returnVisitPercentage;
|
package/dist/iife/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
var co2=(()=>{var I=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var F=(o,e)=>{for(var r in e)I(o,r,{get:e[r],enumerable:!0})},W=(o,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of K(e))!w.call(o,t)&&t!==r&&I(o,t,{get:()=>e[t],enumerable:!(n=U(e,t))||n.enumerable});return o};var Y=o=>W(I({},"__esModule",{value:!0}),o);var ee={};F(ee,{averageIntensity:()=>E,co2:()=>h,default:()=>X,hosting:()=>M,marginalIntensity:()=>b});var A=4883333333333333e-25;var T=class{constructor(e){this.options=e,this.KWH_PER_BYTE_FOR_NETWORK=A}perByte(e,r){if(e<1)return 0;if(r){let t=e*72e-12*0,
|
|
1
|
+
var co2=(()=>{var I=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var F=(o,e)=>{for(var r in e)I(o,r,{get:e[r],enumerable:!0})},W=(o,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of K(e))!w.call(o,t)&&t!==r&&I(o,t,{get:()=>e[t],enumerable:!(n=U(e,t))||n.enumerable});return o};var Y=o=>W(I({},"__esModule",{value:!0}),o);var ee={};F(ee,{averageIntensity:()=>E,co2:()=>h,default:()=>X,hosting:()=>M,marginalIntensity:()=>b});var A=4883333333333333e-25;var T=class{constructor(e){this.options=e,this.KWH_PER_BYTE_FOR_NETWORK=A}perByte(e,r){if(e<1)return 0;if(r){let t=e*72e-12*0,a=e*A*475;return t+a}let n=72e-12+A;return e*n*519}};var V=T;var m={GIGABYTE:1e9};var H={AFG:120.48,AFRICA:484.16,ALB:23.44,DZA:498.9,ASM:687.5,AGO:195.98,ATG:657.14,ARG:344.31,ARM:222.68,ABW:591.4,ASEAN:508.06,ASIA:535.23,AUS:501.7,AUT:157.52,AZE:532.9,BHS:698.11,BHR:494.02,BGD:577.03,BRB:644.86,BLR:415.64,BEL:165.36,BLZ:484.38,BEN:666.67,BTN:24.44,BOL:322.09,BIH:516.01,BWA:794.52,BRA:102.09,BRN:658.85,BGR:399.57,BFA:611.43,BDI:250,CPV:600,KHM:400.46,CMR:278.26,CAN:125.84,CYM:684.93,CAF:0,TCD:677.42,CHL:332.61,CHN:533.98,COL:168.95,COM:714.29,COG:395.52,COD:25.36,COK:400,CRI:37.21,CIV:410.75,HRV:246.46,CUB:602.23,CYP:589.35,CZE:415.35,DNK:180.71,DJI:666.67,DMA:529.41,DOM:549.8,ECU:188.71,EGY:469.63,SLV:194.23,GNQ:492.96,ERI:688.89,EST:464.03,SWZ:189.19,ETH:25.19,EU:277.19,EUROPE:296.45,FLK:500,FRO:428.57,FJI:289.47,FIN:130.98,FRA:84.82,GUF:254.72,PYF:471.43,G20:442.38,G7:343.92,GAB:397.38,GMB:700,GEO:134.83,DEU:384.83,GHA:361.2,GRC:343.82,GRL:133.33,GRD:714.29,GLP:623.53,GUM:670.33,GTM:291.55,GIN:208.63,GNB:750,GUY:642.28,HTI:606.06,HND:373.96,HKG:683.97,HUN:222.97,ISL:28.56,IND:633.4,IDN:619.02,IRN:487.86,IRQ:498.87,IRL:346.33,ISR:548.03,ITA:371.69,JAM:537.93,JPN:494.86,JOR:399.91,KAZ:635.57,KEN:100.57,KIR:666.67,XKX:768.73,KWT:551.74,KGZ:104.43,LAO:242.18,"LATIN AMERICA AND CARIBBEAN":238.68,LVA:181.82,LBN:605.74,LSO:20,LBR:304.35,LBY:550.42,LTU:194.25,LUX:168.14,MAC:491.53,MDG:483.25,MWI:133.8,MYS:543.87,MDV:651.52,MLI:463.13,MLT:495,MTQ:698.63,MRT:526.6,MUS:611.11,MEX:423.81,"MIDDLE EAST":516.02,MDA:677.18,MNG:749.66,MNE:399.38,MSR:1e3,MAR:610.41,MOZ:126.63,MMR:344.37,NAM:63.69,NRU:750,NPL:24.51,NLD:355.78,NCL:610.12,NZL:97.73,NIC:354.21,NER:622.22,NGA:368.11,"NORTH AMERICA":336.01,PRK:157.79,MKD:529.33,NOR:28.82,OCEANIA:449.71,OECD:340.95,OMN:488.27,PAK:344.16,PSE:465.12,PAN:186.61,PNG:526.75,PRY:25.49,PER:256.51,POL:633.1,PRT:234.03,PRI:681.47,QAT:489.88,REU:519.03,ROU:264.12,RUS:363.68,RWA:294.12,KNA:681.82,LCA:685.71,SPM:800,VCT:500,WSM:470.59,STP:600,SAU:557.78,SEN:523.13,SRB:569.38,SYC:615.39,SLE:47.62,SGP:488.78,SVK:140.67,SVN:237.38,SLB:727.27,SOM:634.15,ZAF:708.19,KOR:437.6,SSD:684.21,ESP:217.37,LKA:463,SDN:264.01,SUR:356.44,SWE:45.08,CHE:45.62,SYR:541.17,TWN:560.98,TJK:83.63,TZA:366.75,THA:501.57,PHL:582.84,TGO:460.32,TON:625,TTO:491.41,TUN:469.43,TUR:413.63,TKM:490.19,TCA:703.7,UGA:52.27,UKR:187.06,ARE:407.98,GBR:261.24,USA:367.26,URY:114.89,UZB:505.41,VUT:571.43,VEN:212.48,VNM:386.49,VGB:714.29,VIR:685.71,WORLD:437.26,YEM:543.91,ZMB:84.7,ZWE:392.28},k="average";var E={data:H,type:k};var D=.81,C=.52,O=.14,p=.15,S=.19,s=E.data.WORLD,f=50,g=.75,y=.25,N=.02;var R=o=>parseFloat(o.toFixed(2));function B(o){if(typeof o!="object")throw new Error("Options must be an object");let e={};if(o?.gridIntensity){e.gridIntensity={};let{device:r,dataCenter:n,network:t}=o.gridIntensity;(r||r===0)&&(typeof r=="object"?(E.data[r.country?.toUpperCase()]||(console.warn(`"${r.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
2
2
|
See https://developers.thegreenwebfoundation.org/co2js/data/ for more information.
|
|
3
3
|
Falling back to global average grid intensity.`),e.gridIntensity.device={value:s}),e.gridIntensity.device={country:r.country,value:parseFloat(E.data[r.country?.toUpperCase()])}):typeof r=="number"?e.gridIntensity.device={value:r}:(e.gridIntensity.device={value:s},console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof r}.
|
|
4
|
-
Falling back to global average grid intensity.`))),n&&(typeof n=="object"?(E.data[n.country?.toUpperCase()]||(console.warn(`"${n.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
4
|
+
Falling back to global average grid intensity.`))),(n||n===0)&&(typeof n=="object"?(E.data[n.country?.toUpperCase()]||(console.warn(`"${n.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
5
5
|
See https://developers.thegreenwebfoundation.org/co2js/data/ for more information.
|
|
6
6
|
Falling back to global average grid intensity.`),e.gridIntensity.dataCenter={value:s}),e.gridIntensity.dataCenter={country:n.country,value:parseFloat(E.data[n.country?.toUpperCase()])}):typeof n=="number"?e.gridIntensity.dataCenter={value:n}:(e.gridIntensity.dataCenter={value:s},console.warn(`The data center grid intensity must be a number or an object. You passed in a ${typeof n}.
|
|
7
|
-
Falling back to global average grid intensity.`))),t&&(typeof t=="object"?(E.data[t.country?.toUpperCase()]||(console.warn(`"${t.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
7
|
+
Falling back to global average grid intensity.`))),(t||t===0)&&(typeof t=="object"?(E.data[t.country?.toUpperCase()]||(console.warn(`"${t.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
8
8
|
See https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity.
|
|
9
9
|
Falling back to global average grid intensity.`),e.gridIntensity.network={value:s}),e.gridIntensity.network={country:t.country,value:parseFloat(E.data[t.country?.toUpperCase()])}):typeof t=="number"?e.gridIntensity.network={value:t}:(e.gridIntensity.network={value:s},console.warn(`The network grid intensity must be a number or an object. You passed in a ${typeof t}.
|
|
10
|
-
Falling back to global average grid intensity.`)))}return
|
|
11
|
-
Falling back to default value.`)):(e.dataReloadRatio=
|
|
12
|
-
Falling back to default value.`))),o?.firstVisitPercentage&&(typeof o.firstVisitPercentage=="number"?o.firstVisitPercentage>=0&&o.firstVisitPercentage<=1?e.firstVisitPercentage=o.firstVisitPercentage:(e.firstVisitPercentage=
|
|
13
|
-
Falling back to default value.`)):(e.firstVisitPercentage=
|
|
14
|
-
Falling back to default value.`))),o?.returnVisitPercentage&&(typeof o.returnVisitPercentage=="number"?o.returnVisitPercentage>=0&&o.returnVisitPercentage<=1?e.returnVisitPercentage=o.returnVisitPercentage:(e.returnVisitPercentage=
|
|
15
|
-
Falling back to default value.`)):(e.returnVisitPercentage=
|
|
16
|
-
Falling back to default value.`))),e}var
|
|
10
|
+
Falling back to global average grid intensity.`)))}return(o?.dataReloadRatio||o.dataReloadRatio===0)&&(typeof o.dataReloadRatio=="number"?o.dataReloadRatio>=0&&o.dataReloadRatio<=1?e.dataReloadRatio=o.dataReloadRatio:(e.dataReloadRatio=N,console.warn(`The dataReloadRatio option must be a number between 0 and 1. You passed in ${o.dataReloadRatio}.
|
|
11
|
+
Falling back to default value.`)):(e.dataReloadRatio=N,console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof o.dataReloadRatio}.
|
|
12
|
+
Falling back to default value.`))),(o?.firstVisitPercentage||o.firstVisitPercentage===0)&&(typeof o.firstVisitPercentage=="number"?o.firstVisitPercentage>=0&&o.firstVisitPercentage<=1?e.firstVisitPercentage=o.firstVisitPercentage:(e.firstVisitPercentage=g,console.warn(`The firstVisitPercentage option must be a number between 0 and 1. You passed in ${o.firstVisitPercentage}.
|
|
13
|
+
Falling back to default value.`)):(e.firstVisitPercentage=g,console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof o.firstVisitPercentage}.
|
|
14
|
+
Falling back to default value.`))),(o?.returnVisitPercentage||o.returnVisitPercentage===0)&&(typeof o.returnVisitPercentage=="number"?o.returnVisitPercentage>=0&&o.returnVisitPercentage<=1?e.returnVisitPercentage=o.returnVisitPercentage:(e.returnVisitPercentage=y,console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${o.returnVisitPercentage}.
|
|
15
|
+
Falling back to default value.`)):(e.returnVisitPercentage=y,console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof o.returnVisitPercentage}.
|
|
16
|
+
Falling back to default value.`))),e}var P=class{constructor(e){this.options=e}energyPerByteByComponent(e){let n=e/m.GIGABYTE*D;return{consumerDeviceEnergy:n*C,networkEnergy:n*O,productionEnergy:n*S,dataCenterEnergy:n*p}}co2byComponent(e,r=s,n={}){let t=s,a=s,i=s,d=s;if(n?.gridIntensity){let{device:c,network:u,dataCenter:L}=n.gridIntensity;c?.value&&(t=c.value),u?.value&&(a=u.value),L?.value&&(i=L.value)}r===!0&&(i=f);let l={};for(let[c,u]of Object.entries(e))c.startsWith("dataCenterEnergy")?l[c.replace("Energy","CO2")]=u*i:c.startsWith("consumerDeviceEnergy")?l[c.replace("Energy","CO2")]=u*t:c.startsWith("networkEnergy")?l[c.replace("Energy","CO2")]=u*a:l[c.replace("Energy","CO2")]=u*d;return l}perByte(e,r=!1,n=!1,t={}){e<1&&(e=0);let a=this.energyPerByteByComponent(e,t);if(typeof r!="boolean")throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${r}`);let i=this.co2byComponent(a,r,t),l=Object.values(i).reduce((c,u)=>c+u);return n?{...i,total:l}:l}perVisit(e,r=!1,n=!1,t={}){let a=this.energyPerVisitByComponent(e,t);if(typeof r!="boolean")throw new Error(`perVisit expects a boolean for the carbon intensity value. Received: ${r}`);let i=this.co2byComponent(a,r,t),l=Object.values(i).reduce((c,u)=>c+u);return n?{...i,total:l}:l}energyPerByte(e){let r=this.energyPerByteByComponent(e);return Object.values(r).reduce((t,a)=>t+a)}energyPerVisitByComponent(e,r={},n=g,t=y,a=N){r.dataReloadRatio&&(a=r.dataReloadRatio),r.firstVisitPercentage&&(n=r.firstVisitPercentage),r.returnVisitPercentage&&(t=r.returnVisitPercentage);let i=this.energyPerByteByComponent(e),d={},l=Object.values(i);for(let[c,u]of Object.entries(i))d[`${c} - first`]=u*n,d[`${c} - subsequent`]=u*t*a;return d}energyPerVisit(e){let r=0,n=0,t=Object.entries(this.energyPerVisitByComponent(e));for(let[a,i]of t)a.indexOf("first")>0&&(r+=i);for(let[a,i]of t)a.indexOf("subsequent")>0&&(n+=i);return r+n}emissionsPerVisitInGrams(e,r=s){return R(e*r)}annualEnergyInKwh(e,r=1e3){return e*r*12}annualEmissionsInGrams(e,r=1e3){return e*r*12}annualSegmentEnergy(e){return{consumerDeviceEnergy:R(e*C),networkEnergy:R(e*O),dataCenterEnergy:R(e*p),productionEnergy:R(e*S)}}};var _=P;var G=class{constructor(e){if(this.model=new _,e?.model==="1byte")this.model=new V;else if(e?.model==="swd")this.model=new _;else if(e?.model)throw new Error(`"${e.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model.
|
|
17
17
|
See https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);this._segment=e?.results==="segment"}perByte(e,r=!1){return this.model.perByte(e,r,this._segment)}perVisit(e,r=!1){if(this.model?.perVisit)return this.model.perVisit(e,r,this._segment);throw new Error(`The perVisit() method is not supported in the model you are using. Try using perByte() instead.
|
|
18
|
-
See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`)}perByteTrace(e,r=!1,n={}){let t={};return n&&(t=B(n)),{co2:this.model.perByte(e,r,this._segment,t),green:r,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:t?.gridIntensity?.network?.value
|
|
19
|
-
See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`)}perDomain(e,r){let n=[];for(let t of Object.keys(e.domains)){let
|
|
18
|
+
See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`)}perByteTrace(e,r=!1,n={}){let t={};return n&&(t=B(n)),{co2:this.model.perByte(e,r,this._segment,t),green:r,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:t?.gridIntensity?.network?.value??s,dataCenter:r?f:t?.gridIntensity?.dataCenter?.value??s,production:s,device:t?.gridIntensity?.device?.value??s}}}}perVisitTrace(e,r=!1,n={}){if(this.model?.perVisit){let t={};return n&&(t=B(n)),{co2:this.model.perVisit(e,r,this._segment,t),green:r,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:t?.gridIntensity?.network?.value??s,dataCenter:r?f:t?.gridIntensity?.dataCenter?.value??s,production:s,device:t?.gridIntensity?.device?.value??s},dataReloadRatio:t?.dataReloadRatio??.02,firstVisitPercentage:t?.firstVisitPercentage??.75,returnVisitPercentage:t?.returnVisitPercentage??.25}}}else throw new Error(`The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead.
|
|
19
|
+
See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`)}perDomain(e,r){let n=[];for(let t of Object.keys(e.domains)){let a;r&&r.indexOf(t)>-1?a=this.perByte(e.domains[t].transferSize,!0):a=this.perByte(e.domains[t].transferSize),n.push({domain:t,co2:a,transferSize:e.domains[t].transferSize})}return n.sort((t,a)=>a.co2-t.co2),n}perPage(e,r){let n=this.perDomain(e,r),t=0;for(let a of n)t+=a.co2;return t}perContentType(e,r){let n={};for(let a of e.assets){let i=new URL(a.url).domain,d=a.transferSize,l=this.perByte(d,r&&r.indexOf(i)>-1),c=a.type;n[c]||(n[c]={co2:0,transferSize:0}),n[c].co2+=l,n[c].transferSize+=d}let t=[];for(let a of Object.keys(n))t.push({type:a,co2:n[a].co2,transferSize:n[a].transferSize});return t.sort((a,i)=>i.co2-a.co2),t}dirtiestResources(e,r){let n=[];for(let t of e.assets){let a=new URL(t.url).domain,i=t.transferSize,d=this.perByte(i,r&&r.indexOf(a)>-1);n.push({url:t.url,co2:d,transferSize:i})}return n.sort((t,a)=>a.co2-t.co2),n.slice(0,n.length>10?10:n.length)}perParty(e,r){let n=0,t=0,a=e.firstPartyRegEx;for(let i of Object.keys(e.domains))i.match(a)?n+=this.perByte(e.domains[i].transferSize,r&&r.indexOf(i)>-1):t+=this.perByte(e.domains[i].transferSize,r&&r.indexOf(i)>-1);return{firstParty:n,thirdParty:t}}};var h=G;function j(o){return typeof o=="string"?x(o):Z(o)}async function x(o){return(await(await fetch(`https://api.thegreenwebfoundation.org/greencheck/${o}`)).json()).green}async function Z(o){try{let e="https://api.thegreenwebfoundation.org/v2/greencheckmulti",r=JSON.stringify(o),t=await(await fetch(`${e}/${r}`)).json();return $(t)}catch{return[]}}function $(o){return Object.entries(o).filter(([n,t])=>t.green).map(([n,t])=>t.url)}var v={check:j};function z(o){return v.check(o)}var M={check:z};var J={AFG:"414",ALB:"0",DZA:"528",ASM:"753",AND:"188",AGO:"1476",AIA:"753",ATG:"753",ARG:"478",ARM:"390",ABW:"753",AUS:"808",AUT:"242",AZE:"534","AZORES (PORTUGAL)":"753",BHS:"753",BHR:"726",BGD:"528",BRB:"749",BLR:"400",BEL:"252",BLZ:"403",BEN:"745",BMU:"753",BTN:"0",BOL:"604",BES:"753",BIH:"1197",BWA:"1486",BRA:"284",VGB:"753",BRN:"681",BGR:"911",BFA:"753",BDI:"414",KHM:"1046",CMR:"659",CAN:"372",CYM:"753",CPV:"753",CAF:"188",TCD:"753","CHANNEL ISLANDS (U.K)":"753",CHL:"657",CHN:"899",COL:"410",COM:"753",COD:"0",COG:"659",COK:"753",CRI:"108",CIV:"466",HRV:"294",CUB:"559",CUW:"876",CYP:"751",CZE:"902",DNK:"362",DJI:"753",DMA:"753",DOM:"601",ECU:"560",EGY:"554",SLV:"547",GNQ:"632",ERI:"915",EST:"1057",SWZ:"0",ETH:"0",FLK:"753",FRO:"753",FJI:"640",FIN:"267",FRA:"158",GUF:"423",PYF:"753",GAB:"946",GMB:"753",GEO:"289",DEU:"650",GHA:"495",GIB:"779",GRC:"507",GRL:"264",GRD:"753",GLP:"753",GUM:"753",GTM:"798",GIN:"753",GNB:"753",GUY:"847",HTI:"1048",HND:"662",HUN:"296",ISL:"0",IND:"951",IDN:"783",IRN:"592",IRQ:"1080",IRL:"380",IMN:"436",ISR:"394",ITA:"414",JAM:"711",JPN:"471",JOR:"529",KAZ:"797",KEN:"574",KIR:"753",PRK:"754",KOR:"555",XKX:"1145",KWT:"675",KGZ:"217",LAO:"1069",LVA:"240",LBN:"794",LSO:"0",LBR:"677",LBY:"668",LIE:"151",LTU:"211",LUX:"220",MDG:"876","MADEIRA (PORTUGAL)":"663",MWI:"489",MYS:"551",MDV:"753",MLI:"1076",MLT:"520",MHL:"753",MTQ:"753",MRT:"753",MUS:"700",MYT:"753",MEX:"531",FSM:"753",MDA:"541",MCO:"158",MNG:"1366",MNE:"899",MSR:"753",MAR:"729",MOZ:"234",MMR:"719",NAM:"355",NRU:"753",NPL:"0",NLD:"326",NCL:"779",NZL:"246",NIC:"675",NER:"772",NGA:"526",NIU:"753",MKD:"851",MNP:"753",NOR:"47",OMN:"479",PAK:"592",PLW:"753",PSE:"719",PAN:"477",PNG:"597",PRY:"0",PER:"473",PHL:"672",POL:"828",PRT:"389",PRI:"596",QAT:"503",REU:"772",ROU:"489",RUS:"476",RWA:"712",SHN:"753",KNA:"753",LCA:"753",MAF:"753",SPM:"753",VCT:"753",WSM:"753",SMR:"414",STP:"753",SAU:"592",SEN:"870",SRB:"1086",SYC:"753",SLE:"489",SGP:"379",SXM:"753",SVK:"332",SVN:"620",SLB:"753",SOM:"753",ZAF:"1070",SSD:"890",ESP:"402",LKA:"731",SDN:"736",SUR:"1029",SWE:"68",CHE:"48",SYR:"713",TWN:"484",TJK:"255",TZA:"531",THA:"450",TLS:"753",TGO:"859",TON:"753",TTO:"559",TUN:"468",TUR:"376",TKM:"927",TCA:"753",TUV:"753",UGA:"279",UKR:"768",ARE:"556",GBR:"380",USA:"416",URY:"174",UZB:"612",VUT:"753",VEN:"711",VNM:"560",VIR:"650",YEM:"807",ZMB:"416",ZWE:"1575","MEMO: EU 27":"409"},Q="marginal",q="2021";var b={data:J,type:Q,year:q};var X={co2:h,hosting:M,averageIntensity:E,marginalIntensity:b};return Y(ee);})();
|
|
20
20
|
//# sourceMappingURL=index.js.map
|