@tgwf/co2 0.16.1 → 0.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CONTRIBUTING.md +10 -10
  2. package/dist/cjs/1byte.js.map +1 -1
  3. package/dist/cjs/co2.js +38 -13
  4. package/dist/cjs/co2.js.map +2 -2
  5. package/dist/cjs/constants/index.js +4 -1
  6. package/dist/cjs/constants/index.js.map +2 -2
  7. package/dist/cjs/data/average-intensities.min.js +1 -1
  8. package/dist/cjs/data/average-intensities.min.js.map +2 -2
  9. package/dist/cjs/data/marginal-intensities-2021.min.js.map +2 -2
  10. package/dist/cjs/helpers/index.js +78 -38
  11. package/dist/cjs/helpers/index.js.map +2 -2
  12. package/dist/cjs/hosting-api.js +10 -4
  13. package/dist/cjs/hosting-api.js.map +2 -2
  14. package/dist/cjs/hosting-json.js.map +1 -1
  15. package/dist/cjs/hosting-json.node.js +4 -1
  16. package/dist/cjs/hosting-json.node.js.map +2 -2
  17. package/dist/cjs/hosting-node.js +35 -12
  18. package/dist/cjs/hosting-node.js.map +2 -2
  19. package/dist/cjs/hosting.js +4 -1
  20. package/dist/cjs/hosting.js.map +2 -2
  21. package/dist/cjs/index-node.js +4 -1
  22. package/dist/cjs/index-node.js.map +2 -2
  23. package/dist/cjs/index.js +4 -1
  24. package/dist/cjs/index.js.map +2 -2
  25. package/dist/cjs/sustainable-web-design-v3.js +30 -10
  26. package/dist/cjs/sustainable-web-design-v3.js.map +1 -1
  27. package/dist/cjs/sustainable-web-design-v4.js.map +2 -2
  28. package/dist/esm/co2.js +34 -13
  29. package/dist/esm/data/average-intensities.min.js +1 -1
  30. package/dist/esm/helpers/index.js +78 -38
  31. package/dist/esm/hosting-api.js +6 -4
  32. package/dist/esm/hosting-json.js +0 -1
  33. package/dist/esm/hosting.js +0 -1
  34. package/dist/esm/sustainable-web-design-v3.js +30 -11
  35. package/dist/esm/sustainable-web-design-v4.js +0 -1
  36. package/package.json +2 -2
package/dist/esm/co2.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
3
  var __hasOwnProp = Object.prototype.hasOwnProperty;
@@ -46,19 +45,25 @@ class CO2 {
46
45
  this.model = new SustainableWebDesignV4();
47
46
  }
48
47
  } else if (options == null ? void 0 : options.model) {
49
- throw new Error(`"${options.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model.
50
- See https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);
48
+ throw new Error(
49
+ `"${options.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model.
50
+ See https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`
51
+ );
51
52
  }
52
53
  if ((options == null ? void 0 : options.rating) && typeof options.rating !== "boolean") {
53
- throw new Error(`The rating option must be a boolean. Please use true or false.
54
- See https://developers.thegreenwebfoundation.org/co2js/options/ to learn more about the options available in CO2.js.`);
54
+ throw new Error(
55
+ `The rating option must be a boolean. Please use true or false.
56
+ See https://developers.thegreenwebfoundation.org/co2js/options/ to learn more about the options available in CO2.js.`
57
+ );
55
58
  }
56
59
  const allowRatings = !!this.model.allowRatings;
57
60
  this._segment = (options == null ? void 0 : options.results) === "segment";
58
61
  this._rating = (options == null ? void 0 : options.rating) === true;
59
62
  if (!allowRatings && this._rating) {
60
- throw new Error(`The rating system is not supported in the model you are using. Try using the Sustainable Web Design model instead.
61
- See https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);
63
+ throw new Error(
64
+ `The rating system is not supported in the model you are using. Try using the Sustainable Web Design model instead.
65
+ See https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`
66
+ );
62
67
  }
63
68
  }
64
69
  perByte(bytes, green = false) {
@@ -69,8 +74,10 @@ See https://developers.thegreenwebfoundation.org/co2js/models/ to learn more abo
69
74
  if ((_a = this.model) == null ? void 0 : _a.perVisit) {
70
75
  return this.model.perVisit(bytes, green, this._segment, this._rating);
71
76
  } else {
72
- throw new Error(`The perVisit() method is not supported in the model you are using. Try using perByte() instead.
73
- See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`);
77
+ throw new Error(
78
+ `The perVisit() method is not supported in the model you are using. Try using perByte() instead.
79
+ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`
80
+ );
74
81
  }
75
82
  }
76
83
  perByteTrace(bytes, green = false, options = {}) {
@@ -86,7 +93,13 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
86
93
  "returnVisitPercentage"
87
94
  ]);
88
95
  return {
89
- co2: this.model.perByte(bytes, green, this._segment, this._rating, adjustments),
96
+ co2: this.model.perByte(
97
+ bytes,
98
+ green,
99
+ this._segment,
100
+ this._rating,
101
+ adjustments
102
+ ),
90
103
  green,
91
104
  variables: __spreadValues({
92
105
  description: "Below are the variables used to calculate this CO2 estimate.",
@@ -103,7 +116,13 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
103
116
  const adjustments = parseOptions(options, this.model.version, green);
104
117
  const _b = adjustments, { gridIntensity } = _b, variables = __objRest(_b, ["gridIntensity"]);
105
118
  return {
106
- co2: this.model.perVisit(bytes, green, this._segment, this._rating, adjustments),
119
+ co2: this.model.perVisit(
120
+ bytes,
121
+ green,
122
+ this._segment,
123
+ this._rating,
124
+ adjustments
125
+ ),
107
126
  green,
108
127
  variables: __spreadValues({
109
128
  description: "Below are the variables used to calculate this CO2 estimate.",
@@ -114,8 +133,10 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
114
133
  }, variables)
115
134
  };
116
135
  } else {
117
- throw new Error(`The perVisitTrace() method is not supported in the model you are using. Try using perByte() instead.
118
- See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`);
136
+ throw new Error(
137
+ `The perVisitTrace() method is not supported in the model you are using. Try using perByte() instead.
138
+ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`
139
+ );
119
140
  }
120
141
  }
121
142
  SustainableWebDesignV3() {
@@ -1,4 +1,4 @@
1
- const data = { "AFG": 132.53, "AFRICA": 547.83, "ALB": 24.29, "DZA": 634.61, "ASM": 611.11, "AGO": 174.73, "ATG": 611.11, "ARG": 353.96, "ARM": 264.54, "ABW": 561.22, "ASEAN": 570.41, "ASIA": 591.13, "AUS": 556.3, "AUT": 110.81, "AZE": 671.39, "BHS": 660.1, "BHR": 904.62, "BGD": 691.41, "BRB": 605.51, "BLR": 441.74, "BEL": 138.11, "BLZ": 225.81, "BEN": 584.07, "BTN": 23.33, "BOL": 531.69, "BIH": 601.29, "BWA": 847.91, "BRA": 96.4, "BRN": 893.91, "BGR": 335.33, "BFA": 467.53, "BDI": 250, "CPV": 558.14, "KHM": 417.71, "CMR": 305.42, "CAN": 165.15, "CYM": 642.86, "CAF": 0, "TCD": 628.57, "CHL": 291.11, "CHN": 583.61, "COL": 259.51, "COM": 642.86, "COG": 700, "COD": 24.46, "COK": 250, "CRI": 53.38, "CIV": 393.89, "HRV": 204.96, "CUB": 637.61, "CYP": 534.32, "CZE": 449.72, "DNK": 151.65, "DJI": 692.31, "DMA": 529.41, "DOM": 580.78, "ECU": 166.91, "EGY": 574.04, "SLV": 224.76, "GNQ": 591.84, "ERI": 631.58, "EST": 416.67, "SWZ": 172.41, "ETH": 24.64, "EU": 243.93, "EUROPE": 302.29, "FLK": 500, "FRO": 404.76, "FJI": 288.46, "FIN": 79.16, "FRA": 56.02, "GUF": 217.82, "PYF": 442.86, "G20": 477.89, "G7": 341.44, "GAB": 491.6, "GMB": 666.67, "GEO": 167.59, "DEU": 381.41, "GHA": 484, "GRC": 336.57, "GRL": 178.57, "GRD": 640, "GLP": 500, "GUM": 622.86, "GTM": 328.27, "GIN": 236.84, "GNB": 625, "GUY": 640.35, "HTI": 567.31, "HND": 282.27, "HKG": 699.5, "HUN": 204.19, "ISL": 27.68, "IND": 713.01, "IDN": 682.43, "IRN": 641.73, "IRQ": 688.81, "IRL": 282.98, "ISR": 582.93, "ITA": 330.72, "JAM": 555.56, "JPN": 493.59, "JOR": 540.92, "KAZ": 821.9, "KEN": 71.2, "KIR": 666.67, "XKX": 894.65, "KWT": 649.16, "KGZ": 147.29, "LAO": 265.51, "LATIN AMERICA AND CARIBBEAN": 256.03, "LVA": 123.99, "LBN": 599.01, "LSO": 20, "LBR": 227.85, "LBY": 818.69, "LTU": 160.07, "LUX": 105.26, "MAC": 448.98, "MDG": 436.44, "MWI": 66.67, "MYS": 607.88, "MDV": 611.77, "MLI": 408, "MLT": 459.14, "MTQ": 523.18, "MRT": 464.71, "MUS": 632.48, "MEX": 492.34, "MIDDLE EAST": 643.04, "MDA": 643.46, "MNG": 775.31, "MNE": 418.09, "MSR": 1e3, "MAR": 624.45, "MOZ": 135.65, "MMR": 436.92, "NAM": 59.26, "NRU": 750, "NPL": 24.44, "NLD": 268.48, "NCL": 660.58, "NZL": 112.76, "NIC": 265.12, "NER": 670.89, "NGA": 523.25, "NORTH AMERICA": 342.95, "PRK": 389.59, "MKD": 556.19, "NOR": 30.05, "OCEANIA": 495.74, "OECD": 341.27, "OMN": 564.55, "PAK": 440.61, "PSE": 516.13, "PAN": 161.68, "PNG": 507.25, "PRY": 24.31, "PER": 266.48, "POL": 661.93, "PRT": 165.55, "PRI": 677.96, "QAT": 602.5, "REU": 572.82, "ROU": 240.58, "RUS": 445.02, "RWA": 316.33, "KNA": 636.36, "LCA": 666.67, "SPM": 600, "VCT": 529.41, "WSM": 473.68, "STP": 642.86, "SAU": 696.31, "SEN": 511.6, "SRB": 647.52, "SYC": 564.52, "SLE": 50, "SGP": 470.78, "SVK": 116.77, "SVN": 231.28, "SLB": 700, "SOM": 578.95, "ZAF": 709.69, "KOR": 432.11, "SSD": 629.03, "ESP": 174.05, "LKA": 509.78, "SDN": 263.16, "SUR": 349.28, "SWE": 40.7, "CHE": 34.68, "SYR": 701.66, "TWN": 644.36, "TJK": 116.86, "TZA": 339.25, "THA": 549.85, "PHL": 610.74, "TGO": 443.18, "TON": 625, "TTO": 681.53, "TUN": 563.96, "TUR": 464.59, "TKM": 1306.03, "TCA": 653.85, "UGA": 44.53, "UKR": 256.21, "ARE": 492.7, "GBR": 228.25, "USA": 369.47, "URY": 128.79, "UZB": 1167.6, "VUT": 571.43, "VEN": 185.8, "VNM": 472.47, "VGB": 647.06, "VIR": 632.35, "WORLD": 481.65, "YEM": 566.1, "ZMB": 111.97, "ZWE": 297.87 };
1
+ const data = { "AFG": 132.53, "AFRICA": 547.83, "ALB": 24.29, "DZA": 634.61, "ASM": 611.11, "AGO": 174.73, "ATG": 611.11, "ARG": 353.96, "ARM": 264.54, "ABW": 561.22, "ASEAN": 570.41, "ASIA": 591.13, "AUS": 556.3, "AUT": 110.78, "AZE": 671.39, "BHS": 660.1, "BHR": 904.62, "BGD": 691.41, "BRB": 605.51, "BLR": 441.74, "BEL": 138.11, "BLZ": 225.81, "BEN": 584.07, "BTN": 23.33, "BOL": 531.69, "BIH": 600.94, "BWA": 847.91, "BRA": 96.4, "BRN": 893.91, "BGR": 335.33, "BFA": 467.53, "BDI": 250, "CPV": 558.14, "KHM": 417.71, "CMR": 305.42, "CAN": 165.15, "CYM": 642.86, "CAF": 0, "TCD": 628.57, "CHL": 291.11, "CHN": 583.61, "COL": 259.51, "COM": 642.86, "COG": 700, "COD": 24.46, "COK": 250, "CRI": 53.38, "CIV": 393.89, "HRV": 204.96, "CUB": 637.61, "CYP": 526.02, "CZE": 449.72, "DNK": 151.65, "DJI": 692.31, "DMA": 529.41, "DOM": 580.78, "ECU": 166.91, "EGY": 574.04, "SLV": 224.76, "GNQ": 591.84, "ERI": 631.58, "EST": 416.67, "SWZ": 172.41, "ETH": 24.64, "EU": 243.89, "EUROPE": 302.27, "FLK": 500, "FRO": 404.76, "FJI": 288.46, "FIN": 79.12, "FRA": 56.02, "GUF": 217.82, "PYF": 442.86, "G20": 477.87, "G7": 341.49, "GAB": 491.6, "GMB": 666.67, "GEO": 167.59, "DEU": 381.41, "GHA": 484, "GRC": 336.57, "GRL": 178.57, "GRD": 640, "GLP": 500, "GUM": 622.86, "GTM": 328.27, "GIN": 236.84, "GNB": 625, "GUY": 640.35, "HTI": 567.31, "HND": 282.27, "HKG": 699.5, "HUN": 204.01, "ISL": 27.68, "IND": 713.01, "IDN": 682.43, "IRN": 641.73, "IRQ": 688.81, "IRL": 282.98, "ISR": 582.93, "ITA": 330.72, "JAM": 555.56, "JPN": 493.59, "JOR": 540.92, "KAZ": 821.9, "KEN": 71.2, "KIR": 666.67, "XKX": 894.65, "KWT": 649.16, "KGZ": 147.29, "LAO": 265.51, "LATIN AMERICA AND CARIBBEAN": 256.03, "LVA": 123.99, "LBN": 599.01, "LSO": 20, "LBR": 227.85, "LBY": 818.69, "LTU": 160.07, "LUX": 105.26, "MAC": 448.98, "MDG": 436.44, "MWI": 66.67, "MYS": 607.88, "MDV": 611.77, "MLI": 408, "MLT": 444.03, "MTQ": 523.18, "MRT": 464.71, "MUS": 632.48, "MEX": 492.34, "MIDDLE EAST": 643.04, "MDA": 643.46, "MNG": 775.31, "MNE": 418.09, "MSR": 1e3, "MAR": 624.45, "MOZ": 135.65, "MMR": 436.92, "NAM": 59.26, "NRU": 750, "NPL": 24.44, "NLD": 268.48, "NCL": 660.58, "NZL": 112.76, "NIC": 265.12, "NER": 670.89, "NGA": 523.25, "NORTH AMERICA": 343.03, "PRK": 389.59, "MKD": 539.55, "NOR": 30.05, "OCEANIA": 495.74, "OECD": 341.31, "OMN": 564.55, "PAK": 440.61, "PSE": 516.13, "PAN": 161.68, "PNG": 507.25, "PRY": 24.31, "PER": 266.48, "POL": 661.93, "PRT": 165.55, "PRI": 677.96, "QAT": 602.5, "REU": 572.82, "ROU": 240.58, "RUS": 445.02, "RWA": 316.33, "KNA": 636.36, "LCA": 666.67, "SPM": 600, "VCT": 529.41, "WSM": 473.68, "STP": 642.86, "SAU": 696.31, "SEN": 511.6, "SRB": 648.2, "SYC": 564.52, "SLE": 50, "SGP": 470.78, "SVK": 116.77, "SVN": 231.28, "SLB": 700, "SOM": 578.95, "ZAF": 709.69, "KOR": 432.11, "SSD": 629.03, "ESP": 174.05, "LKA": 509.78, "SDN": 263.16, "SUR": 349.28, "SWE": 40.7, "CHE": 34.7, "SYR": 701.66, "TWN": 644.36, "TJK": 116.86, "TZA": 339.25, "THA": 549.85, "PHL": 610.74, "TGO": 443.18, "TON": 625, "TTO": 681.53, "TUN": 563.96, "TUR": 464.59, "TKM": 1306.03, "TCA": 653.85, "UGA": 44.53, "UKR": 256.21, "ARE": 492.7, "GBR": 228.25, "USA": 369.53, "URY": 128.79, "UZB": 1167.6, "VUT": 571.43, "VEN": 185.8, "VNM": 472.47, "VGB": 647.06, "VIR": 632.35, "WORLD": 481.63, "YEM": 566.1, "ZMB": 111.97, "ZWE": 297.87 };
2
2
  const type = "average";
3
3
  var average_intensities_min_default = { data, type };
4
4
  export {
@@ -24,16 +24,20 @@ function parseOptions(options = {}, version = 3, green = false) {
24
24
  if (device || device === 0) {
25
25
  if (typeof device === "object") {
26
26
  if (!averageIntensity.data[(_a = device.country) == null ? void 0 : _a.toUpperCase()]) {
27
- console.warn(`"${device.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
27
+ console.warn(
28
+ `"${device.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
28
29
  See https://developers.thegreenwebfoundation.org/co2js/data/ for more information.
29
- Falling back to global average grid intensity.`);
30
+ Falling back to global average grid intensity.`
31
+ );
30
32
  adjustments.gridIntensity["device"] = {
31
33
  value: globalGridIntensity
32
34
  };
33
35
  }
34
36
  adjustments.gridIntensity["device"] = {
35
37
  country: device.country,
36
- value: parseFloat(averageIntensity.data[(_b = device.country) == null ? void 0 : _b.toUpperCase()])
38
+ value: parseFloat(
39
+ averageIntensity.data[(_b = device.country) == null ? void 0 : _b.toUpperCase()]
40
+ )
37
41
  };
38
42
  } else if (typeof device === "number") {
39
43
  adjustments.gridIntensity["device"] = {
@@ -43,23 +47,29 @@ Falling back to global average grid intensity.`);
43
47
  adjustments.gridIntensity["device"] = {
44
48
  value: globalGridIntensity
45
49
  };
46
- console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof device}.
47
- Falling back to global average grid intensity.`);
50
+ console.warn(
51
+ `The device grid intensity must be a number or an object. You passed in a ${typeof device}.
52
+ Falling back to global average grid intensity.`
53
+ );
48
54
  }
49
55
  }
50
56
  if (dataCenter || dataCenter === 0) {
51
57
  if (typeof dataCenter === "object") {
52
58
  if (!averageIntensity.data[(_c = dataCenter.country) == null ? void 0 : _c.toUpperCase()]) {
53
- console.warn(`"${dataCenter.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
59
+ console.warn(
60
+ `"${dataCenter.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
54
61
  See https://developers.thegreenwebfoundation.org/co2js/data/ for more information.
55
- Falling back to global average grid intensity.`);
62
+ Falling back to global average grid intensity.`
63
+ );
56
64
  adjustments.gridIntensity["dataCenter"] = {
57
65
  value: SWDM3_GLOBAL_GRID_INTENSITY
58
66
  };
59
67
  }
60
68
  adjustments.gridIntensity["dataCenter"] = {
61
69
  country: dataCenter.country,
62
- value: parseFloat(averageIntensity.data[(_d = dataCenter.country) == null ? void 0 : _d.toUpperCase()])
70
+ value: parseFloat(
71
+ averageIntensity.data[(_d = dataCenter.country) == null ? void 0 : _d.toUpperCase()]
72
+ )
63
73
  };
64
74
  } else if (typeof dataCenter === "number") {
65
75
  adjustments.gridIntensity["dataCenter"] = {
@@ -69,23 +79,29 @@ Falling back to global average grid intensity.`);
69
79
  adjustments.gridIntensity["dataCenter"] = {
70
80
  value: globalGridIntensity
71
81
  };
72
- console.warn(`The data center grid intensity must be a number or an object. You passed in a ${typeof dataCenter}.
73
- Falling back to global average grid intensity.`);
82
+ console.warn(
83
+ `The data center grid intensity must be a number or an object. You passed in a ${typeof dataCenter}.
84
+ Falling back to global average grid intensity.`
85
+ );
74
86
  }
75
87
  }
76
88
  if (network || network === 0) {
77
89
  if (typeof network === "object") {
78
90
  if (!averageIntensity.data[(_e = network.country) == null ? void 0 : _e.toUpperCase()]) {
79
- console.warn(`"${network.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
91
+ console.warn(
92
+ `"${network.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
80
93
  See https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity.
81
- Falling back to global average grid intensity.`);
94
+ Falling back to global average grid intensity.`
95
+ );
82
96
  adjustments.gridIntensity["network"] = {
83
97
  value: globalGridIntensity
84
98
  };
85
99
  }
86
100
  adjustments.gridIntensity["network"] = {
87
101
  country: network.country,
88
- value: parseFloat(averageIntensity.data[(_f = network.country) == null ? void 0 : _f.toUpperCase()])
102
+ value: parseFloat(
103
+ averageIntensity.data[(_f = network.country) == null ? void 0 : _f.toUpperCase()]
104
+ )
89
105
  };
90
106
  } else if (typeof network === "number") {
91
107
  adjustments.gridIntensity["network"] = {
@@ -95,8 +111,10 @@ Falling back to global average grid intensity.`);
95
111
  adjustments.gridIntensity["network"] = {
96
112
  value: globalGridIntensity
97
113
  };
98
- console.warn(`The network grid intensity must be a number or an object. You passed in a ${typeof network}.
99
- Falling back to global average grid intensity.`);
114
+ console.warn(
115
+ `The network grid intensity must be a number or an object. You passed in a ${typeof network}.
116
+ Falling back to global average grid intensity.`
117
+ );
100
118
  }
101
119
  }
102
120
  } else {
@@ -112,18 +130,24 @@ Falling back to global average grid intensity.`);
112
130
  adjustments.dataReloadRatio = options.dataReloadRatio;
113
131
  } else {
114
132
  adjustments.dataReloadRatio = version === 3 ? PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD : 0;
115
- console.warn(`The dataReloadRatio option must be a number between 0 and 1. You passed in ${options.dataReloadRatio}.
116
- Falling back to default value.`);
133
+ console.warn(
134
+ `The dataReloadRatio option must be a number between 0 and 1. You passed in ${options.dataReloadRatio}.
135
+ Falling back to default value.`
136
+ );
117
137
  }
118
138
  } else {
119
139
  adjustments.dataReloadRatio = version === 3 ? PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD : 0;
120
- console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof options.dataReloadRatio}.
121
- Falling back to default value.`);
140
+ console.warn(
141
+ `The dataReloadRatio option must be a number. You passed in a ${typeof options.dataReloadRatio}.
142
+ Falling back to default value.`
143
+ );
122
144
  }
123
145
  } else {
124
146
  adjustments.dataReloadRatio = version === 3 ? PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD : 0;
125
- console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof options.dataReloadRatio}.
126
- Falling back to default value.`);
147
+ console.warn(
148
+ `The dataReloadRatio option must be a number. You passed in a ${typeof options.dataReloadRatio}.
149
+ Falling back to default value.`
150
+ );
127
151
  }
128
152
  if ((options == null ? void 0 : options.firstVisitPercentage) || options.firstVisitPercentage === 0) {
129
153
  if (typeof options.firstVisitPercentage === "number") {
@@ -131,18 +155,24 @@ Falling back to default value.`);
131
155
  adjustments.firstVisitPercentage = options.firstVisitPercentage;
132
156
  } else {
133
157
  adjustments.firstVisitPercentage = version === 3 ? FIRST_TIME_VIEWING_PERCENTAGE : 1;
134
- console.warn(`The firstVisitPercentage option must be a number between 0 and 1. You passed in ${options.firstVisitPercentage}.
135
- Falling back to default value.`);
158
+ console.warn(
159
+ `The firstVisitPercentage option must be a number between 0 and 1. You passed in ${options.firstVisitPercentage}.
160
+ Falling back to default value.`
161
+ );
136
162
  }
137
163
  } else {
138
164
  adjustments.firstVisitPercentage = version === 3 ? FIRST_TIME_VIEWING_PERCENTAGE : 1;
139
- console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof options.firstVisitPercentage}.
140
- Falling back to default value.`);
165
+ console.warn(
166
+ `The firstVisitPercentage option must be a number. You passed in a ${typeof options.firstVisitPercentage}.
167
+ Falling back to default value.`
168
+ );
141
169
  }
142
170
  } else {
143
171
  adjustments.firstVisitPercentage = version === 3 ? FIRST_TIME_VIEWING_PERCENTAGE : 1;
144
- console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof options.firstVisitPercentage}.
145
- Falling back to default value.`);
172
+ console.warn(
173
+ `The firstVisitPercentage option must be a number. You passed in a ${typeof options.firstVisitPercentage}.
174
+ Falling back to default value.`
175
+ );
146
176
  }
147
177
  if ((options == null ? void 0 : options.returnVisitPercentage) || options.returnVisitPercentage === 0) {
148
178
  if (typeof options.returnVisitPercentage === "number") {
@@ -150,18 +180,24 @@ Falling back to default value.`);
150
180
  adjustments.returnVisitPercentage = options.returnVisitPercentage;
151
181
  } else {
152
182
  adjustments.returnVisitPercentage = version === 3 ? RETURNING_VISITOR_PERCENTAGE : 0;
153
- console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}.
154
- Falling back to default value.`);
183
+ console.warn(
184
+ `The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}.
185
+ Falling back to default value.`
186
+ );
155
187
  }
156
188
  } else {
157
189
  adjustments.returnVisitPercentage = version === 3 ? RETURNING_VISITOR_PERCENTAGE : 0;
158
- console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}.
159
- Falling back to default value.`);
190
+ console.warn(
191
+ `The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}.
192
+ Falling back to default value.`
193
+ );
160
194
  }
161
195
  } else {
162
196
  adjustments.returnVisitPercentage = version === 3 ? RETURNING_VISITOR_PERCENTAGE : 0;
163
- console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}.
164
- Falling back to default value.`);
197
+ console.warn(
198
+ `The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}.
199
+ Falling back to default value.`
200
+ );
165
201
  }
166
202
  if ((options == null ? void 0 : options.greenHostingFactor) || options.greenHostingFactor === 0 && version === 4) {
167
203
  if (typeof options.greenHostingFactor === "number") {
@@ -169,13 +205,17 @@ Falling back to default value.`);
169
205
  adjustments.greenHostingFactor = options.greenHostingFactor;
170
206
  } else {
171
207
  adjustments.greenHostingFactor = 0;
172
- console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}.
173
- Falling back to default value.`);
208
+ console.warn(
209
+ `The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}.
210
+ Falling back to default value.`
211
+ );
174
212
  }
175
213
  } else {
176
214
  adjustments.greenHostingFactor = 0;
177
- console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}.
178
- Falling back to default value.`);
215
+ console.warn(
216
+ `The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}.
217
+ Falling back to default value.`
218
+ );
179
219
  }
180
220
  } else if (version === 4) {
181
221
  adjustments.greenHostingFactor = 0;
@@ -186,7 +226,7 @@ Falling back to default value.`);
186
226
  return adjustments;
187
227
  }
188
228
  function getApiRequestHeaders(comment = "") {
189
- return { "User-Agent": `co2js/${"0.16.1"} ${comment}` };
229
+ return { "User-Agent": `co2js/${"0.16.2"} ${comment}` };
190
230
  }
191
231
  function outputRating(co2e, swdmVersion) {
192
232
  let {
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  import { getApiRequestHeaders } from "./helpers/index.js";
3
2
  import hostingJSON from "./hosting-json.js";
4
3
  function check(domain, optionsOrAgentId) {
@@ -13,9 +12,12 @@ function check(domain, optionsOrAgentId) {
13
12
  }
14
13
  }
15
14
  async function checkAgainstAPI(domain, options = {}) {
16
- const req = await fetch(`https://api.thegreenwebfoundation.org/greencheck/${domain}`, {
17
- headers: getApiRequestHeaders(options.userAgentIdentifier)
18
- });
15
+ const req = await fetch(
16
+ `https://api.thegreenwebfoundation.org/greencheck/${domain}`,
17
+ {
18
+ headers: getApiRequestHeaders(options.userAgentIdentifier)
19
+ }
20
+ );
19
21
  if (options == null ? void 0 : options.db) {
20
22
  return hostingJSON.check(domain, options.db);
21
23
  }
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __getOwnPropNames = Object.getOwnPropertyNames;
3
2
  var __commonJS = (cb, mod) => function __require() {
4
3
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  import hostingAPI from "./hosting-api.js";
3
2
  function check(domain, optionsOrAgentId) {
4
3
  return hostingAPI.check(domain, optionsOrAgentId);
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __defProp = Object.defineProperty;
3
2
  var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -88,11 +87,19 @@ class SustainableWebDesign {
88
87
  }
89
88
  const energyBycomponent = this.energyPerByteByComponent(bytes, options);
90
89
  if (typeof carbonIntensity !== "boolean") {
91
- throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${carbonIntensity}`);
92
- }
93
- const co2ValuesbyComponent = this.co2byComponent(energyBycomponent, carbonIntensity, options);
90
+ throw new Error(
91
+ `perByte expects a boolean for the carbon intensity value. Received: ${carbonIntensity}`
92
+ );
93
+ }
94
+ const co2ValuesbyComponent = this.co2byComponent(
95
+ energyBycomponent,
96
+ carbonIntensity,
97
+ options
98
+ );
94
99
  const co2Values = Object.values(co2ValuesbyComponent);
95
- const co2ValuesSum = co2Values.reduce((prevValue, currentValue) => prevValue + currentValue);
100
+ const co2ValuesSum = co2Values.reduce(
101
+ (prevValue, currentValue) => prevValue + currentValue
102
+ );
96
103
  let rating = null;
97
104
  if (ratingResults) {
98
105
  rating = this.ratingScale(co2ValuesSum);
@@ -114,11 +121,19 @@ class SustainableWebDesign {
114
121
  perVisit(bytes, carbonIntensity = false, segmentResults = false, ratingResults = false, options = {}) {
115
122
  const energyBycomponent = this.energyPerVisitByComponent(bytes, options);
116
123
  if (typeof carbonIntensity !== "boolean") {
117
- throw new Error(`perVisit expects a boolean for the carbon intensity value. Received: ${carbonIntensity}`);
118
- }
119
- const co2ValuesbyComponent = this.co2byComponent(energyBycomponent, carbonIntensity, options);
124
+ throw new Error(
125
+ `perVisit expects a boolean for the carbon intensity value. Received: ${carbonIntensity}`
126
+ );
127
+ }
128
+ const co2ValuesbyComponent = this.co2byComponent(
129
+ energyBycomponent,
130
+ carbonIntensity,
131
+ options
132
+ );
120
133
  const co2Values = Object.values(co2ValuesbyComponent);
121
- const co2ValuesSum = co2Values.reduce((prevValue, currentValue) => prevValue + currentValue);
134
+ const co2ValuesSum = co2Values.reduce(
135
+ (prevValue, currentValue) => prevValue + currentValue
136
+ );
122
137
  let rating = null;
123
138
  if (ratingResults) {
124
139
  rating = this.ratingScale(co2ValuesSum);
@@ -140,7 +155,9 @@ class SustainableWebDesign {
140
155
  energyPerByte(bytes) {
141
156
  const energyByComponent = this.energyPerByteByComponent(bytes);
142
157
  const energyValues = Object.values(energyByComponent);
143
- return energyValues.reduce((prevValue, currentValue) => prevValue + currentValue);
158
+ return energyValues.reduce(
159
+ (prevValue, currentValue) => prevValue + currentValue
160
+ );
144
161
  }
145
162
  energyPerVisitByComponent(bytes, options = {}, firstView = FIRST_TIME_VIEWING_PERCENTAGE, returnView = RETURNING_VISITOR_PERCENTAGE, dataReloadRatio = PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD) {
146
163
  if (options.dataReloadRatio || options.dataReloadRatio === 0) {
@@ -164,7 +181,9 @@ class SustainableWebDesign {
164
181
  energyPerVisit(bytes) {
165
182
  let firstVisits = 0;
166
183
  let subsequentVisits = 0;
167
- const energyBycomponent = Object.entries(this.energyPerVisitByComponent(bytes));
184
+ const energyBycomponent = Object.entries(
185
+ this.energyPerVisitByComponent(bytes)
186
+ );
168
187
  for (const [key, val] of energyBycomponent) {
169
188
  if (key.indexOf("first") > 0) {
170
189
  firstVisits += val;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __defProp = Object.defineProperty;
3
2
  var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tgwf/co2",
3
- "version": "0.16.1",
3
+ "version": "0.16.2",
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",
@@ -44,7 +44,7 @@
44
44
  "author": "Chris Adams",
45
45
  "license": "Apache-2.0",
46
46
  "devDependencies": {
47
- "@tgwf/url2green": "^0.4.0",
47
+ "@tgwf/url2green": "^0.4.1",
48
48
  "all-contributors-cli": "^6.26.1",
49
49
  "esbuild": "^0.14.47",
50
50
  "esbuild-jest": "^0.5.0",