@tgwf/co2 0.14.0 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +183 -44
- package/README.md +70 -16
- package/dist/cjs/co2.js +14 -22
- package/dist/cjs/co2.js.map +2 -2
- 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 +10 -6
- 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/cjs/sustainable-web-design.js +9 -6
- package/dist/cjs/sustainable-web-design.js.map +2 -2
- package/dist/esm/co2.js +16 -24
- package/dist/esm/data/average-intensities.min.js +1 -1
- package/dist/esm/helpers/index.js +10 -6
- package/dist/esm/hosting-api.js +12 -7
- package/dist/esm/hosting.js +2 -2
- package/dist/esm/sustainable-web-design.js +9 -6
- package/package.json +11 -7
- package/.all-contributorsrc +0 -39
- package/.esbuild.browser.js +0 -11
- package/.esbuild.esm.js +0 -25
- package/.esbuild.node.js +0 -16
- package/.eslintignore +0 -1
- package/.gitpod.yml +0 -8
- package/data/output/average-intensities.js +0 -226
- package/data/output/average-intensities.json +0 -1328
- package/data/output/marginal-intensities-2021.js +0 -238
- package/data/output/marginal-intensities-2021.json +0 -2801
- package/dist/iife/index.js +0 -20
- package/dist/iife/index.js.map +0 -7
- package/fixup +0 -19
- package/index.d.ts +0 -2
- package/src/1byte.js +0 -77
- package/src/co2.js +0 -311
- package/src/constants/file-size.js +0 -5
- package/src/constants/index.js +0 -39
- package/src/data/average-intensities.min.js +0 -1
- package/src/data/marginal-intensities-2021.min.js +0 -1
- package/src/helpers/index.js +0 -175
- package/src/hosting-api.js +0 -64
- package/src/hosting-json.node.js +0 -107
- package/src/hosting-node.js +0 -113
- package/src/hosting.js +0 -16
- package/src/index-node.js +0 -5
- package/src/index.js +0 -7
- package/src/sustainable-web-design.js +0 -329
package/dist/esm/co2.js
CHANGED
|
@@ -17,73 +17,65 @@ class CO2 {
|
|
|
17
17
|
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.
|
|
18
18
|
See https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
this.model.results = {
|
|
22
|
-
segment: true
|
|
23
|
-
};
|
|
24
|
-
} else {
|
|
25
|
-
this.model.results = {
|
|
26
|
-
segment: false
|
|
27
|
-
};
|
|
28
|
-
}
|
|
20
|
+
this._segment = (options == null ? void 0 : options.results) === "segment";
|
|
29
21
|
}
|
|
30
22
|
perByte(bytes, green = false) {
|
|
31
|
-
return this.model.perByte(bytes, green, this.
|
|
23
|
+
return this.model.perByte(bytes, green, this._segment);
|
|
32
24
|
}
|
|
33
25
|
perVisit(bytes, green = false) {
|
|
34
26
|
var _a;
|
|
35
27
|
if ((_a = this.model) == null ? void 0 : _a.perVisit) {
|
|
36
|
-
return this.model.perVisit(bytes, green, this.
|
|
28
|
+
return this.model.perVisit(bytes, green, this._segment);
|
|
37
29
|
} else {
|
|
38
30
|
throw new Error(`The perVisit() method is not supported in the model you are using. Try using perByte() instead.
|
|
39
31
|
See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`);
|
|
40
32
|
}
|
|
41
33
|
}
|
|
42
34
|
perByteTrace(bytes, green = false, options = {}) {
|
|
43
|
-
var _a, _b, _c, _d, _e, _f;
|
|
35
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
44
36
|
let adjustments = {};
|
|
45
37
|
if (options) {
|
|
46
38
|
adjustments = parseOptions(options);
|
|
47
39
|
}
|
|
48
40
|
return {
|
|
49
|
-
co2: this.model.perByte(bytes, green, this.
|
|
41
|
+
co2: this.model.perByte(bytes, green, this._segment, adjustments),
|
|
50
42
|
green,
|
|
51
43
|
variables: {
|
|
52
44
|
description: "Below are the variables used to calculate this CO2 estimate.",
|
|
53
45
|
bytes,
|
|
54
46
|
gridIntensity: {
|
|
55
47
|
description: "The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",
|
|
56
|
-
network: ((_b = (_a = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _a.network) == null ? void 0 : _b.value)
|
|
57
|
-
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,
|
|
58
50
|
production: GLOBAL_GRID_INTENSITY,
|
|
59
|
-
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
|
|
60
52
|
}
|
|
61
53
|
}
|
|
62
54
|
};
|
|
63
55
|
}
|
|
64
56
|
perVisitTrace(bytes, green = false, options = {}) {
|
|
65
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
57
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
66
58
|
if ((_a = this.model) == null ? void 0 : _a.perVisit) {
|
|
67
59
|
let adjustments = {};
|
|
68
60
|
if (options) {
|
|
69
61
|
adjustments = parseOptions(options);
|
|
70
62
|
}
|
|
71
63
|
return {
|
|
72
|
-
co2: this.model.perVisit(bytes, green, this.
|
|
64
|
+
co2: this.model.perVisit(bytes, green, this._segment, adjustments),
|
|
73
65
|
green,
|
|
74
66
|
variables: {
|
|
75
67
|
description: "Below are the variables used to calculate this CO2 estimate.",
|
|
76
68
|
bytes,
|
|
77
69
|
gridIntensity: {
|
|
78
70
|
description: "The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",
|
|
79
|
-
network: ((_c = (_b = adjustments == null ? void 0 : adjustments.gridIntensity) == null ? void 0 : _b.network) == null ? void 0 : _c.value)
|
|
80
|
-
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,
|
|
81
73
|
production: GLOBAL_GRID_INTENSITY,
|
|
82
|
-
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
|
|
83
75
|
},
|
|
84
|
-
dataReloadRatio: (adjustments == null ? void 0 : adjustments.dataReloadRatio)
|
|
85
|
-
firstVisitPercentage: (adjustments == null ? void 0 : adjustments.firstVisitPercentage)
|
|
86
|
-
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
|
|
87
79
|
}
|
|
88
80
|
};
|
|
89
81
|
} else {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const data = { "AFG": 120.
|
|
1
|
+
const data = { "AFG": 120.48, "AFRICA": 484.7, "ALB": 23.44, "DZA": 485.49, "ASM": 687.5, "AGO": 195.98, "ATG": 657.14, "ARG": 344.31, "ARM": 222.68, "ABW": 591.4, "ASEAN": 508.2, "ASIA": 534.89, "AUS": 501.7, "AUT": 158.22, "AZE": 469.58, "BHS": 698.11, "BHR": 494.02, "BGD": 574.28, "BRB": 644.86, "BLR": 425.9, "BEL": 167.11, "BLZ": 484.38, "BEN": 666.67, "BTN": 24.44, "BOL": 335.4, "BIH": 553.47, "BWA": 794.52, "BRA": 102.04, "BRN": 493.59, "BGR": 399.72, "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": 163.99, "COM": 714.29, "COG": 395.52, "COD": 25.36, "COK": 400, "CRI": 37.21, "CIV": 410.75, "HRV": 246.29, "CUB": 654.68, "CYP": 589.35, "CZE": 414.8, "DNK": 180.42, "DJI": 666.67, "DMA": 529.41, "DOM": 549.8, "ECU": 183.63, "EGY": 469.63, "SLV": 194.23, "GNQ": 492.96, "ERI": 688.89, "EST": 460.26, "SWZ": 189.19, "ETH": 25.19, "EU": 276.63, "EUROPE": 297.05, "FLK": 500, "FRO": 428.57, "FJI": 289.47, "FIN": 131.71, "FRA": 84.88, "GUF": 254.72, "PYF": 471.43, "G20": 442.57, "G7": 344.31, "GAB": 397.38, "GMB": 700, "GEO": 134.83, "DEU": 385.39, "GHA": 361.2, "GRC": 344.41, "GRL": 133.33, "GRD": 714.29, "GLP": 623.53, "GUM": 670.33, "GTM": 304.71, "GIN": 208.63, "GNB": 750, "GUY": 642.28, "HTI": 606.06, "HND": 373.96, "HKG": 609.93, "HUN": 222.1, "ISL": 28.56, "IND": 633.4, "IDN": 619.03, "IRN": 487.86, "IRQ": 531.36, "IRL": 346.43, "ISR": 537.57, "ITA": 372.63, "JAM": 537.93, "JPN": 494.86, "JOR": 391.13, "KAZ": 635.57, "KEN": 101.13, "KIR": 666.67, "XKX": 767, "KWT": 574.56, "KGZ": 104.43, "LAO": 242.18, "LATIN AMERICA AND CARIBBEAN": 237.91, "LVA": 183.43, "LBN": 663.1, "LSO": 20, "LBR": 304.35, "LBY": 558.85, "LTU": 195.7, "LUX": 162.6, "MAC": 491.53, "MDG": 483.25, "MWI": 133.8, "MYS": 543.87, "MDV": 651.52, "MLI": 463.13, "MLT": 433.48, "MTQ": 698.63, "MRT": 526.6, "MUS": 611.11, "MEX": 423.81, "MIDDLE EAST": 519.92, "MDA": 666.67, "MNG": 749.66, "MNE": 392.75, "MSR": 1e3, "MAR": 630.75, "MOZ": 126.63, "MMR": 330.8, "NAM": 63.69, "NRU": 750, "NPL": 24.51, "NLD": 354.31, "NCL": 610.12, "NZL": 105.22, "NIC": 354.21, "NER": 622.22, "NGA": 368.11, "NORTH AMERICA": 336.68, "PRK": 102.42, "MKD": 543.71, "NOR": 28.93, "OCEANIA": 450.73, "OECD": 341.08, "OMN": 488.27, "PAK": 344.16, "PSE": 465.12, "PAN": 152.68, "PNG": 526.75, "PRY": 25.49, "PER": 256.51, "POL": 633.23, "PRT": 234.61, "PRI": 612.39, "QAT": 490.28, "REU": 519.03, "ROU": 264.24, "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": 582.13, "SYC": 615.39, "SLE": 47.62, "SGP": 488.78, "SVK": 140.14, "SVN": 237.38, "SLB": 727.27, "SOM": 634.15, "ZAF": 708.21, "KOR": 437.6, "SSD": 684.21, "ESP": 217.42, "LKA": 501.53, "SDN": 288.13, "SUR": 356.44, "SWE": 45.12, "CHE": 41.28, "SYR": 541.17, "TWN": 560.98, "TJK": 83.63, "TZA": 366.75, "THA": 501.57, "PHL": 594.45, "TGO": 460.32, "TON": 625, "TTO": 491.41, "TUN": 469.43, "TUR": 413.6, "TKM": 490.19, "TCA": 703.7, "UGA": 52.27, "UKR": 232.74, "ARE": 407.98, "GBR": 261.16, "USA": 368.1, "URY": 150.13, "UZB": 505.41, "VUT": 571.43, "VEN": 212.48, "VNM": 386.49, "VGB": 714.29, "VIR": 685.71, "WORLD": 437.66, "YEM": 559.66, "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;
|
|
@@ -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.2"} ${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
|
@@ -53,13 +53,13 @@ class SustainableWebDesign {
|
|
|
53
53
|
let globalEmissions = GLOBAL_GRID_INTENSITY;
|
|
54
54
|
if (options == null ? void 0 : options.gridIntensity) {
|
|
55
55
|
const { device, network, dataCenter } = options.gridIntensity;
|
|
56
|
-
if (device == null ? void 0 : device.value) {
|
|
56
|
+
if ((device == null ? void 0 : device.value) || (device == null ? void 0 : device.value) === 0) {
|
|
57
57
|
deviceCarbonIntensity = device.value;
|
|
58
58
|
}
|
|
59
|
-
if (network == null ? void 0 : network.value) {
|
|
59
|
+
if ((network == null ? void 0 : network.value) || (network == null ? void 0 : network.value) === 0) {
|
|
60
60
|
networkCarbonIntensity = network.value;
|
|
61
61
|
}
|
|
62
|
-
if (dataCenter == null ? void 0 : dataCenter.value) {
|
|
62
|
+
if ((dataCenter == null ? void 0 : dataCenter.value) || (dataCenter == null ? void 0 : dataCenter.value) === 0) {
|
|
63
63
|
dataCenterCarbonIntensity = dataCenter.value;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -81,6 +81,9 @@ class SustainableWebDesign {
|
|
|
81
81
|
return returnCO2ByComponent;
|
|
82
82
|
}
|
|
83
83
|
perByte(bytes, carbonIntensity = false, segmentResults = false, options = {}) {
|
|
84
|
+
if (bytes < 1) {
|
|
85
|
+
bytes = 0;
|
|
86
|
+
}
|
|
84
87
|
const energyBycomponent = this.energyPerByteByComponent(bytes, options);
|
|
85
88
|
if (typeof carbonIntensity !== "boolean") {
|
|
86
89
|
throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${carbonIntensity}`);
|
|
@@ -112,13 +115,13 @@ class SustainableWebDesign {
|
|
|
112
115
|
return energyValues.reduce((prevValue, currentValue) => prevValue + currentValue);
|
|
113
116
|
}
|
|
114
117
|
energyPerVisitByComponent(bytes, options = {}, firstView = FIRST_TIME_VIEWING_PERCENTAGE, returnView = RETURNING_VISITOR_PERCENTAGE, dataReloadRatio = PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD) {
|
|
115
|
-
if (options.dataReloadRatio) {
|
|
118
|
+
if (options.dataReloadRatio || options.dataReloadRatio === 0) {
|
|
116
119
|
dataReloadRatio = options.dataReloadRatio;
|
|
117
120
|
}
|
|
118
|
-
if (options.firstVisitPercentage) {
|
|
121
|
+
if (options.firstVisitPercentage || options.firstVisitPercentage === 0) {
|
|
119
122
|
firstView = options.firstVisitPercentage;
|
|
120
123
|
}
|
|
121
|
-
if (options.returnVisitPercentage) {
|
|
124
|
+
if (options.returnVisitPercentage || options.returnVisitPercentage === 0) {
|
|
122
125
|
returnView = options.returnVisitPercentage;
|
|
123
126
|
}
|
|
124
127
|
const energyBycomponent = this.energyPerByteByComponent(bytes);
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tgwf/co2",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.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",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=14.0.0"
|
|
9
|
+
},
|
|
7
10
|
"exports": {
|
|
8
11
|
".": {
|
|
9
12
|
"import": "./dist/esm/index.js",
|
|
@@ -26,7 +29,8 @@
|
|
|
26
29
|
"intensity-data:average": "node data/functions/generate_average_co2.js",
|
|
27
30
|
"intensity-data:marginal": "node data/functions/generate_marginal_co2.js",
|
|
28
31
|
"intensity-data": "npm run intensity-data:average && npm run intensity-data:marginal && npm run format-data",
|
|
29
|
-
"format-data": "cd data && prettier --write '**/*.{js,json}'"
|
|
32
|
+
"format-data": "cd data && prettier --write '**/*.{js,json}'",
|
|
33
|
+
"version": "npm run build"
|
|
30
34
|
},
|
|
31
35
|
"keywords": [
|
|
32
36
|
"sustainability",
|
|
@@ -41,16 +45,17 @@
|
|
|
41
45
|
"license": "Apache-2.0",
|
|
42
46
|
"devDependencies": {
|
|
43
47
|
"@tgwf/url2green": "^0.4.0",
|
|
48
|
+
"all-contributors-cli": "^6.26.1",
|
|
49
|
+
"esbuild": "^0.14.47",
|
|
50
|
+
"esbuild-jest": "^0.5.0",
|
|
51
|
+
"esbuild-plugin-glob": "^1.1.2",
|
|
44
52
|
"eslint": "^8.15.0",
|
|
45
53
|
"eslint-config-prettier": "^8.5.0",
|
|
46
54
|
"eslint-plugin-jest": "^26.1.5",
|
|
47
55
|
"eslint-plugin-prettier": "^4.0.0",
|
|
48
|
-
"esbuild": "^0.14.47",
|
|
49
|
-
"esbuild-jest": "^0.5.0",
|
|
50
|
-
"esbuild-plugin-glob": "^1.1.2",
|
|
51
56
|
"jest": "^28.1.0",
|
|
52
57
|
"nock": "^13.2.4",
|
|
53
|
-
"np": "^
|
|
58
|
+
"np": "^8.0.4",
|
|
54
59
|
"pagexray": "^4.4.2",
|
|
55
60
|
"prettier": "^2.6.2"
|
|
56
61
|
},
|
|
@@ -67,7 +72,6 @@
|
|
|
67
72
|
"publishConfig": {
|
|
68
73
|
"access": "public"
|
|
69
74
|
},
|
|
70
|
-
"dependencies": {},
|
|
71
75
|
"repository": {
|
|
72
76
|
"type": "git",
|
|
73
77
|
"url": "https://github.com/thegreenwebfoundation/co2.js.git"
|
package/.all-contributorsrc
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"files": [
|
|
3
|
-
"README.md"
|
|
4
|
-
],
|
|
5
|
-
"imageSize": 100,
|
|
6
|
-
"commit": false,
|
|
7
|
-
"contributors": [
|
|
8
|
-
{
|
|
9
|
-
"login": "JamieBeevor",
|
|
10
|
-
"name": "JamieB",
|
|
11
|
-
"avatar_url": "https://avatars1.githubusercontent.com/u/26165947?v=4",
|
|
12
|
-
"profile": "https://greengumption.co.uk",
|
|
13
|
-
"contributions": [
|
|
14
|
-
"ideas",
|
|
15
|
-
"question",
|
|
16
|
-
"review"
|
|
17
|
-
]
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
"login": "soulgalore",
|
|
21
|
-
"name": "Peter Hedenskog",
|
|
22
|
-
"avatar_url": "https://avatars2.githubusercontent.com/u/540757?v=4",
|
|
23
|
-
"profile": "https://www.peterhedenskog.com",
|
|
24
|
-
"contributions": [
|
|
25
|
-
"code",
|
|
26
|
-
"ideas",
|
|
27
|
-
"review",
|
|
28
|
-
"infra",
|
|
29
|
-
"docs"
|
|
30
|
-
]
|
|
31
|
-
}
|
|
32
|
-
],
|
|
33
|
-
"contributorsPerLine": 7,
|
|
34
|
-
"projectName": "co2.js",
|
|
35
|
-
"projectOwner": "thegreenwebfoundation",
|
|
36
|
-
"repoType": "github",
|
|
37
|
-
"repoHost": "https://github.com",
|
|
38
|
-
"skipCi": true
|
|
39
|
-
}
|
package/.esbuild.browser.js
DELETED
package/.esbuild.esm.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const esbuild = require('esbuild')
|
|
2
|
-
// tiny glob is a dependency of `esbuild-plugin-glob`.
|
|
3
|
-
// For this build however we need to filter out some extra files
|
|
4
|
-
// that are used for nodejs, but not in browsers, so we use the
|
|
5
|
-
// library directly instead of using `esbuild-plugin-glob` as a plugin
|
|
6
|
-
const glob = require('tiny-glob');
|
|
7
|
-
|
|
8
|
-
async function main() {
|
|
9
|
-
const results = await glob('src/**/!(*.test.js|test-constants.js|!(*.js))')
|
|
10
|
-
// we remove node specific files here, with the assumption that
|
|
11
|
-
// the common use case is bundling into browser based web apps
|
|
12
|
-
const justBrowserCompatibleFiles = results.filter(filepath => !filepath.endsWith('node.js'))
|
|
13
|
-
|
|
14
|
-
esbuild.build({
|
|
15
|
-
entryPoints: justBrowserCompatibleFiles,
|
|
16
|
-
bundle: false,
|
|
17
|
-
minify: false,
|
|
18
|
-
sourcemap: false,
|
|
19
|
-
target: ['chrome58', 'firefox57', 'safari11', 'edge18', 'esnext'],
|
|
20
|
-
outdir: 'dist/esm',
|
|
21
|
-
outExtension: { '.js': '.js' },
|
|
22
|
-
format: 'esm'
|
|
23
|
-
})
|
|
24
|
-
}
|
|
25
|
-
main()
|
package/.esbuild.node.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const { globPlugin } = require('esbuild-plugin-glob');
|
|
2
|
-
|
|
3
|
-
function main() {
|
|
4
|
-
require('esbuild').build({
|
|
5
|
-
entryPoints: ['src/**/!(*.test.js|test-constants.js|!(*.js))'],
|
|
6
|
-
bundle: false,
|
|
7
|
-
minify: false,
|
|
8
|
-
sourcemap: true,
|
|
9
|
-
target: ['node14'],
|
|
10
|
-
outdir: 'dist/cjs/',
|
|
11
|
-
outExtension: { '.js': '.js' },
|
|
12
|
-
format: 'cjs',
|
|
13
|
-
plugins: [globPlugin()]
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
main()
|
package/.eslintignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
*.min.js
|