@tgwf/co2 0.13.6 → 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 +120 -20
- package/CHANGELOG.md +14 -4
- package/README.md +49 -16
- package/data/output/average-intensities.js +29 -29
- package/data/output/average-intensities.json +30 -30
- 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 +2 -2
- package/dist/cjs/helpers/index.js +6 -6
- package/dist/cjs/helpers/index.js.map +2 -2
- package/dist/cjs/sustainable-web-design.js +3 -0
- package/dist/cjs/sustainable-web-design.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/esm/sustainable-web-design.js +3 -0
- package/dist/iife/index.js +12 -12
- package/dist/iife/index.js.map +2 -2
- package/package.json +5 -5
- package/src/co2.js +9 -9
- package/src/data/average-intensities.min.js +1 -1
- package/src/helpers/index.js +6 -6
- package/src/sustainable-web-design.js +13 -5
package/src/co2.js
CHANGED
|
@@ -122,14 +122,14 @@ class CO2 {
|
|
|
122
122
|
description:
|
|
123
123
|
"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",
|
|
124
124
|
network:
|
|
125
|
-
adjustments?.gridIntensity?.network?.value
|
|
125
|
+
adjustments?.gridIntensity?.network?.value ?? GLOBAL_GRID_INTENSITY,
|
|
126
126
|
dataCenter: green
|
|
127
127
|
? RENEWABLES_GRID_INTENSITY
|
|
128
|
-
: adjustments?.gridIntensity?.dataCenter?.value
|
|
128
|
+
: adjustments?.gridIntensity?.dataCenter?.value ??
|
|
129
129
|
GLOBAL_GRID_INTENSITY,
|
|
130
130
|
production: GLOBAL_GRID_INTENSITY,
|
|
131
131
|
device:
|
|
132
|
-
adjustments?.gridIntensity?.device?.value
|
|
132
|
+
adjustments?.gridIntensity?.device?.value ?? GLOBAL_GRID_INTENSITY,
|
|
133
133
|
},
|
|
134
134
|
},
|
|
135
135
|
};
|
|
@@ -164,20 +164,20 @@ class CO2 {
|
|
|
164
164
|
description:
|
|
165
165
|
"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",
|
|
166
166
|
network:
|
|
167
|
-
adjustments?.gridIntensity?.network?.value
|
|
167
|
+
adjustments?.gridIntensity?.network?.value ??
|
|
168
168
|
GLOBAL_GRID_INTENSITY,
|
|
169
169
|
dataCenter: green
|
|
170
170
|
? RENEWABLES_GRID_INTENSITY
|
|
171
|
-
: adjustments?.gridIntensity?.dataCenter?.value
|
|
171
|
+
: adjustments?.gridIntensity?.dataCenter?.value ??
|
|
172
172
|
GLOBAL_GRID_INTENSITY,
|
|
173
173
|
production: GLOBAL_GRID_INTENSITY,
|
|
174
174
|
device:
|
|
175
|
-
adjustments?.gridIntensity?.device?.value
|
|
175
|
+
adjustments?.gridIntensity?.device?.value ??
|
|
176
176
|
GLOBAL_GRID_INTENSITY,
|
|
177
177
|
},
|
|
178
|
-
dataReloadRatio: adjustments?.dataReloadRatio
|
|
179
|
-
firstVisitPercentage: adjustments?.firstVisitPercentage
|
|
180
|
-
returnVisitPercentage: adjustments?.returnVisitPercentage
|
|
178
|
+
dataReloadRatio: adjustments?.dataReloadRatio ?? 0.02,
|
|
179
|
+
firstVisitPercentage: adjustments?.firstVisitPercentage ?? 0.75,
|
|
180
|
+
returnVisitPercentage: adjustments?.returnVisitPercentage ?? 0.25,
|
|
181
181
|
},
|
|
182
182
|
};
|
|
183
183
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const data = {"AFG":120.48,"AFRICA":
|
|
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":1000,"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}; const type = "average"; export { data, type }; export default { data, type };
|
package/src/helpers/index.js
CHANGED
|
@@ -18,7 +18,7 @@ function parseOptions(options) {
|
|
|
18
18
|
if (options?.gridIntensity) {
|
|
19
19
|
adjustments.gridIntensity = {};
|
|
20
20
|
const { device, dataCenter, network } = options.gridIntensity;
|
|
21
|
-
if (device) {
|
|
21
|
+
if (device || device === 0) {
|
|
22
22
|
if (typeof device === "object") {
|
|
23
23
|
if (!averageIntensity.data[device.country?.toUpperCase()]) {
|
|
24
24
|
console.warn(
|
|
@@ -47,7 +47,7 @@ function parseOptions(options) {
|
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
if (dataCenter) {
|
|
50
|
+
if (dataCenter || dataCenter === 0) {
|
|
51
51
|
if (typeof dataCenter === "object") {
|
|
52
52
|
if (!averageIntensity.data[dataCenter.country?.toUpperCase()]) {
|
|
53
53
|
console.warn(
|
|
@@ -76,7 +76,7 @@ function parseOptions(options) {
|
|
|
76
76
|
);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
if (network) {
|
|
79
|
+
if (network || network === 0) {
|
|
80
80
|
if (typeof network === "object") {
|
|
81
81
|
if (!averageIntensity.data[network.country?.toUpperCase()]) {
|
|
82
82
|
console.warn(
|
|
@@ -107,7 +107,7 @@ function parseOptions(options) {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
if (options?.dataReloadRatio) {
|
|
110
|
+
if (options?.dataReloadRatio || options.dataReloadRatio === 0) {
|
|
111
111
|
if (typeof options.dataReloadRatio === "number") {
|
|
112
112
|
if (options.dataReloadRatio >= 0 && options.dataReloadRatio <= 1) {
|
|
113
113
|
adjustments.dataReloadRatio = options.dataReloadRatio;
|
|
@@ -127,7 +127,7 @@ function parseOptions(options) {
|
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
if (options?.firstVisitPercentage) {
|
|
130
|
+
if (options?.firstVisitPercentage || options.firstVisitPercentage === 0) {
|
|
131
131
|
if (typeof options.firstVisitPercentage === "number") {
|
|
132
132
|
if (
|
|
133
133
|
options.firstVisitPercentage >= 0 &&
|
|
@@ -148,7 +148,7 @@ function parseOptions(options) {
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
if (options?.returnVisitPercentage) {
|
|
151
|
+
if (options?.returnVisitPercentage || options.returnVisitPercentage === 0) {
|
|
152
152
|
if (typeof options.returnVisitPercentage === "number") {
|
|
153
153
|
if (
|
|
154
154
|
options.returnVisitPercentage >= 0 &&
|
|
@@ -114,11 +114,13 @@ class SustainableWebDesign {
|
|
|
114
114
|
* Accept a figure for bytes transferred and return a single figure for CO2
|
|
115
115
|
* emissions. Where information exists about the origin data is being
|
|
116
116
|
* fetched from, a different carbon intensity figure
|
|
117
|
-
* is applied for the
|
|
117
|
+
* is applied for the data centre share of the carbon intensity.
|
|
118
118
|
*
|
|
119
119
|
* @param {number} bytes - the data transferred in bytes
|
|
120
|
-
* @param {
|
|
121
|
-
* @
|
|
120
|
+
* @param {boolean} carbonIntensity - a boolean indicating whether the data center is green or not
|
|
121
|
+
* @param {boolean} segmentResults - a boolean indicating whether to return the results broken down by component
|
|
122
|
+
* @param {object} options - an object containing the grid intensity and first/return visitor values
|
|
123
|
+
* @return {number|object} the total number in grams of CO2 equivalent emissions, or an object containing the breakdown by component
|
|
122
124
|
*/
|
|
123
125
|
perByte(
|
|
124
126
|
bytes,
|
|
@@ -126,6 +128,10 @@ class SustainableWebDesign {
|
|
|
126
128
|
segmentResults = false,
|
|
127
129
|
options = {}
|
|
128
130
|
) {
|
|
131
|
+
if (bytes < 1) {
|
|
132
|
+
bytes = 0;
|
|
133
|
+
}
|
|
134
|
+
|
|
129
135
|
const energyBycomponent = this.energyPerByteByComponent(bytes, options);
|
|
130
136
|
|
|
131
137
|
// otherwise when faced with non numeric values throw an error
|
|
@@ -159,8 +165,10 @@ class SustainableWebDesign {
|
|
|
159
165
|
* emissions. This method applies caching assumptions from the original Sustainable Web Design model.
|
|
160
166
|
*
|
|
161
167
|
* @param {number} bytes - the data transferred in bytes
|
|
162
|
-
* @param {
|
|
163
|
-
* @
|
|
168
|
+
* @param {boolean} carbonIntensity - a boolean indicating whether the data center is green or not
|
|
169
|
+
* @param {boolean} segmentResults - a boolean indicating whether to return the results broken down by component
|
|
170
|
+
* @param {object} options - an object containing the grid intensity and first/return visitor values
|
|
171
|
+
* @return {number|object} the total number in grams of CO2 equivalent emissions, or an object containing the breakdown by component
|
|
164
172
|
*/
|
|
165
173
|
perVisit(
|
|
166
174
|
bytes,
|