@tgwf/co2 0.12.2 → 0.13.0
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/README.md +3 -4
- package/data/output/average-intensities.js +226 -0
- package/data/output/average-intensities.json +1328 -0
- package/data/output/marginal-intensities-2021.json +466 -0
- package/dist/cjs/1byte.js.map +1 -1
- package/dist/cjs/co2.js +13 -44
- package/dist/cjs/co2.js.map +2 -2
- package/dist/cjs/constants/index.js +1 -4
- package/dist/cjs/constants/index.js.map +2 -2
- package/dist/cjs/data/average-intensities.min.js +28 -0
- package/dist/cjs/data/average-intensities.min.js.map +7 -0
- package/dist/cjs/helpers/index.js +27 -57
- package/dist/cjs/helpers/index.js.map +1 -1
- package/dist/cjs/hosting-api.js +2 -7
- package/dist/cjs/hosting-api.js.map +2 -2
- package/dist/cjs/hosting-json.node.js +1 -4
- package/dist/cjs/hosting-json.node.js.map +2 -2
- package/dist/cjs/hosting-node.js +4 -19
- package/dist/cjs/hosting-node.js.map +2 -2
- package/dist/cjs/hosting.js +1 -4
- package/dist/cjs/hosting.js.map +2 -2
- package/dist/cjs/index-node.js +1 -4
- package/dist/cjs/index-node.js.map +2 -2
- package/dist/cjs/index.js +4 -7
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/sustainable-web-design.js +9 -32
- package/dist/cjs/sustainable-web-design.js.map +2 -2
- package/dist/esm/co2.js +13 -40
- package/dist/esm/data/average-intensities.min.js +8 -0
- package/dist/esm/helpers/index.js +27 -57
- package/dist/esm/hosting-api.js +2 -3
- package/dist/esm/hosting.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/sustainable-web-design.js +9 -28
- package/dist/iife/index.js +7 -7
- package/dist/iife/index.js.map +4 -4
- package/package.json +2 -2
- package/src/data/average-intensities.min.js +1 -0
- package/src/index.js +1 -1
- package/data/output/average-intensities-2021.js +0 -5
- package/data/output/average-intensities-2021.json +0 -1
- package/dist/cjs/data/average-intensities-2021.min.js +0 -30
- package/dist/cjs/data/average-intensities-2021.min.js.map +0 -7
- package/dist/esm/data/average-intensities-2021.min.js +0 -10
- package/src/data/average-intensities-2021.min.js +0 -1
package/dist/cjs/1byte.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/1byte.js"],
|
|
4
4
|
"sourcesContent": ["// Use the 1byte model for now from the Shift Project, and assume a US grid mix figure they use of around 519 g co2 for the time being. It's lower for Europe, and in particular, France, but for v1, we don't include this\nconst CO2_PER_KWH_IN_DC_GREY = 519;\n\n// this figure is from the IEA's 2018 report for a global average:\nconst CO2_PER_KWH_NETWORK_GREY = 475;\n\n// TODO - these figures need to be updated, as the figures for green\n// shouldn't really be zero now we know that carbon intensity figures\n// for renewables still usually include the life cycle emissions\nconst CO2_PER_KWH_IN_DC_GREEN = 0;\n\n// the 1 byte model gives figures for energy usage for:\n\n// datacentres\n// networks\n// the device used to access a site/app\n\n// The device usage figure combines figures for:\n// 1. the usage for devices (which is small proportion of the energy use)\n// 2. the *making* the device, which is comparatively high.\n\nconst KWH_PER_BYTE_IN_DC = 7.2e-11;\n\n// this is probably best left as something users can define, or\n// a weighted average based on total usage.\n// Using a simple mean for now, as while web traffic to end users might trend\n// towards wifi and mobile,\n// Web traffic between servers is likely wired networks\n\nconst FIXED_NETWORK_WIRED = 4.29e-10;\nconst FIXED_NETWORK_WIFI = 1.52e-10;\nconst FOUR_G_MOBILE = 8.84e-10;\n\n// Pull requests gratefully accepted\nconst KWH_PER_BYTE_FOR_NETWORK =\n (FIXED_NETWORK_WIRED + FIXED_NETWORK_WIFI + FOUR_G_MOBILE) / 3;\n\nconst KWH_PER_BYTE_FOR_DEVICES = 1.3e-10;\n\nclass OneByte {\n constructor(options) {\n this.options = options;\n\n this.KWH_PER_BYTE_FOR_NETWORK = KWH_PER_BYTE_FOR_NETWORK;\n }\n\n /**\n * Calculates the carbon footprint of a website using the OneByte model\n * @param {number} bytes - The number of bytes to calculate the carbon footprint for\n * @param {boolean} green - Whether the energy is green or not\n * @returns {number} The carbon footprint in grams of CO2\n */\n\n perByte(bytes, green) {\n if (bytes < 1) {\n return 0;\n }\n\n if (green) {\n // if we have a green datacentre, use the lower figure for renewable energy\n const Co2ForDC = bytes * KWH_PER_BYTE_IN_DC * CO2_PER_KWH_IN_DC_GREEN;\n\n // but for the worest of the internet, we can't easily check, so assume\n // grey for now\n const Co2forNetwork =\n bytes * KWH_PER_BYTE_FOR_NETWORK * CO2_PER_KWH_NETWORK_GREY;\n\n return Co2ForDC + Co2forNetwork;\n }\n\n const KwHPerByte = KWH_PER_BYTE_IN_DC + KWH_PER_BYTE_FOR_NETWORK;\n return bytes * KwHPerByte * CO2_PER_KWH_IN_DC_GREY;\n }\n}\n\nexport { OneByte };\nexport default OneByte;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,MAAM,yBAAyB;AAG/B,MAAM,2BAA2B;AAKjC,MAAM,0BAA0B;AAYhC,MAAM,qBAAqB;AAQ3B,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB;AAC3B,MAAM,gBAAgB;AAGtB,MAAM,
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,MAAM,yBAAyB;AAG/B,MAAM,2BAA2B;AAKjC,MAAM,0BAA0B;AAYhC,MAAM,qBAAqB;AAQ3B,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB;AAC3B,MAAM,gBAAgB;AAGtB,MAAM,2BACH,uBAAsB,qBAAqB,iBAAiB;AAE/D,MAAM,2BAA2B;AAEjC,MAAM,QAAQ;AAAA,EACZ,YAAY,SAAS;AACnB,SAAK,UAAU;AAEf,SAAK,2BAA2B;AAAA,EAClC;AAAA,EASA,QAAQ,OAAO,OAAO;AACpB,QAAI,QAAQ,GAAG;AACb,aAAO;AAAA,IACT;AAEA,QAAI,OAAO;AAET,YAAM,WAAW,QAAQ,qBAAqB;AAI9C,YAAM,gBACJ,QAAQ,2BAA2B;AAErC,aAAO,WAAW;AAAA,IACpB;AAEA,UAAM,aAAa,qBAAqB;AACxC,WAAO,QAAQ,aAAa;AAAA,EAC9B;AACF;AAGA,IAAO,eAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/co2.js
CHANGED
|
@@ -17,10 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
24
21
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
22
|
var co2_exports = {};
|
|
26
23
|
__export(co2_exports, {
|
|
@@ -40,10 +37,8 @@ class CO2 {
|
|
|
40
37
|
} else if ((options == null ? void 0 : options.model) === "swd") {
|
|
41
38
|
this.model = new import_sustainable_web_design.default();
|
|
42
39
|
} else if (options == null ? void 0 : options.model) {
|
|
43
|
-
throw new Error(
|
|
44
|
-
|
|
45
|
-
See https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`
|
|
46
|
-
);
|
|
40
|
+
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.
|
|
41
|
+
See https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);
|
|
47
42
|
}
|
|
48
43
|
if ((options == null ? void 0 : options.results) === "segment") {
|
|
49
44
|
this.model.results = {
|
|
@@ -63,10 +58,8 @@ See https://developers.thegreenwebfoundation.org/co2js/models/ to learn more abo
|
|
|
63
58
|
if ((_a = this.model) == null ? void 0 : _a.perVisit) {
|
|
64
59
|
return this.model.perVisit(bytes, green, this.model.results.segment);
|
|
65
60
|
} else {
|
|
66
|
-
throw new Error(
|
|
67
|
-
|
|
68
|
-
See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`
|
|
69
|
-
);
|
|
61
|
+
throw new Error(`The perVisit() method is not supported in the model you are using. Try using perByte() instead.
|
|
62
|
+
See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`);
|
|
70
63
|
}
|
|
71
64
|
}
|
|
72
65
|
perByteTrace(bytes, green = false, options = {}) {
|
|
@@ -76,12 +69,7 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
|
|
|
76
69
|
adjustments = (0, import_helpers.parseOptions)(options);
|
|
77
70
|
}
|
|
78
71
|
return {
|
|
79
|
-
co2: this.model.perByte(
|
|
80
|
-
bytes,
|
|
81
|
-
green,
|
|
82
|
-
this.model.results.segment,
|
|
83
|
-
adjustments
|
|
84
|
-
),
|
|
72
|
+
co2: this.model.perByte(bytes, green, this.model.results.segment, adjustments),
|
|
85
73
|
green,
|
|
86
74
|
variables: {
|
|
87
75
|
description: "Below are the variables used to calculate this CO2 estimate.",
|
|
@@ -104,12 +92,7 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
|
|
|
104
92
|
adjustments = (0, import_helpers.parseOptions)(options);
|
|
105
93
|
}
|
|
106
94
|
return {
|
|
107
|
-
co2: this.model.perVisit(
|
|
108
|
-
bytes,
|
|
109
|
-
green,
|
|
110
|
-
this.model.results.segment,
|
|
111
|
-
adjustments
|
|
112
|
-
),
|
|
95
|
+
co2: this.model.perVisit(bytes, green, this.model.results.segment, adjustments),
|
|
113
96
|
green,
|
|
114
97
|
variables: {
|
|
115
98
|
description: "Below are the variables used to calculate this CO2 estimate.",
|
|
@@ -127,10 +110,8 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
|
|
|
127
110
|
}
|
|
128
111
|
};
|
|
129
112
|
} else {
|
|
130
|
-
throw new Error(
|
|
131
|
-
|
|
132
|
-
See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`
|
|
133
|
-
);
|
|
113
|
+
throw new Error(`The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead.
|
|
114
|
+
See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`);
|
|
134
115
|
}
|
|
135
116
|
}
|
|
136
117
|
perDomain(pageXray, greenDomains) {
|
|
@@ -164,10 +145,7 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
|
|
|
164
145
|
for (let asset of pageXray.assets) {
|
|
165
146
|
const domain = new URL(asset.url).domain;
|
|
166
147
|
const transferSize = asset.transferSize;
|
|
167
|
-
const co2ForTransfer = this.perByte(
|
|
168
|
-
transferSize,
|
|
169
|
-
greenDomains && greenDomains.indexOf(domain) > -1
|
|
170
|
-
);
|
|
148
|
+
const co2ForTransfer = this.perByte(transferSize, greenDomains && greenDomains.indexOf(domain) > -1);
|
|
171
149
|
const contentType = asset.type;
|
|
172
150
|
if (!co2PerContentType[contentType]) {
|
|
173
151
|
co2PerContentType[contentType] = { co2: 0, transferSize: 0 };
|
|
@@ -191,10 +169,7 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
|
|
|
191
169
|
for (let asset of pageXray.assets) {
|
|
192
170
|
const domain = new URL(asset.url).domain;
|
|
193
171
|
const transferSize = asset.transferSize;
|
|
194
|
-
const co2ForTransfer = this.perByte(
|
|
195
|
-
transferSize,
|
|
196
|
-
greenDomains && greenDomains.indexOf(domain) > -1
|
|
197
|
-
);
|
|
172
|
+
const co2ForTransfer = this.perByte(transferSize, greenDomains && greenDomains.indexOf(domain) > -1);
|
|
198
173
|
allAssets.push({ url: asset.url, co2: co2ForTransfer, transferSize });
|
|
199
174
|
}
|
|
200
175
|
allAssets.sort((a, b) => b.co2 - a.co2);
|
|
@@ -206,15 +181,9 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
|
|
|
206
181
|
const firstPartyRegEx = pageXray.firstPartyRegEx;
|
|
207
182
|
for (let d of Object.keys(pageXray.domains)) {
|
|
208
183
|
if (!d.match(firstPartyRegEx)) {
|
|
209
|
-
thirdParty += this.perByte(
|
|
210
|
-
pageXray.domains[d].transferSize,
|
|
211
|
-
greenDomains && greenDomains.indexOf(d) > -1
|
|
212
|
-
);
|
|
184
|
+
thirdParty += this.perByte(pageXray.domains[d].transferSize, greenDomains && greenDomains.indexOf(d) > -1);
|
|
213
185
|
} else {
|
|
214
|
-
firstParty += this.perByte(
|
|
215
|
-
pageXray.domains[d].transferSize,
|
|
216
|
-
greenDomains && greenDomains.indexOf(d) > -1
|
|
217
|
-
);
|
|
186
|
+
firstParty += this.perByte(pageXray.domains[d].transferSize, greenDomains && greenDomains.indexOf(d) > -1);
|
|
218
187
|
}
|
|
219
188
|
}
|
|
220
189
|
return { firstParty, thirdParty };
|
package/dist/cjs/co2.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/co2.js"],
|
|
4
4
|
"sourcesContent": ["\"use strict\";\n\n/**\n * @typedef {Object} CO2EstimateTraceResultPerByte\n * @property {number} co2 - The CO2 estimate in grams/kilowatt-hour\n * @property {boolean} green - Whether the domain is green or not\n * @property {TraceResultVariables} variables - The variables used to calculate the CO2 estimate\n */\n\n/**\n * @typedef {Object} CO2EstimateTraceResultPerVisit\n * @property {number} co2 - The CO2 estimate in grams/kilowatt-hour\n * @property {boolean} green - Whether the domain is green or not\n * @property {TraceResultVariables} variables - The variables used to calculate the CO2 estimate\n */\n\n/**\n * @typedef {Object} TraceResultVariablesPerByte\n * @property {GridIntensityVariables} gridIntensity - The grid intensity related variables\n */\n/**\n * @typedef {Object} TraceResultVariablesPerVisit\n * @property {GridIntensityVariables} gridIntensity - The grid intensity related variables\n * @property {number} dataReloadRatio - What percentage of a page is reloaded on each subsequent page view\n * @property {number} firstVisitPercentage - What percentage of visits are loading this page for subsequent times\n * @property {number} returnVisitPercentage - What percentage of visits are loading this page for the second or more time\n */\n\n/**\n * @typedef {Object} GridIntensityVariables\n * @property {string} description - The description of the variables\n * @property {number} network - The network grid intensity set by the user or the default\n * @property {number} dataCenter - The data center grid intensity set by the user or the default\n * @property {number} device - The device grid intensity set by the user or the default\n * @property {number} production - The production grid intensity set by the user or the default\n */\n\nimport OneByte from \"./1byte.js\";\nimport SustainableWebDesign from \"./sustainable-web-design.js\";\n\nimport {\n GLOBAL_GRID_INTENSITY,\n RENEWABLES_GRID_INTENSITY,\n} from \"./constants/index.js\";\nimport { parseOptions } from \"./helpers/index.js\";\n\nclass CO2 {\n constructor(options) {\n this.model = new SustainableWebDesign();\n // Using optional chaining allows an empty object to be passed\n // in without breaking the code.\n if (options?.model === \"1byte\") {\n this.model = new OneByte();\n } else if (options?.model === \"swd\") {\n this.model = new SustainableWebDesign();\n } else if (options?.model) {\n throw new Error(\n `\"${options.model}\" is not a valid model. Please use \"1byte\" for the OneByte model, and \"swd\" for the Sustainable Web Design model.\\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`\n );\n }\n\n if (options?.results === \"segment\") {\n this.model.results = {\n segment: true,\n };\n } else {\n this.model.results = {\n segment: false,\n };\n }\n }\n\n /**\n * Accept a figure in bytes for data transfer, and a boolean for whether\n * the domain shows as 'green', and return a CO2 figure for energy used to shift the corresponding\n * the data transfer.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @return {number} the amount of CO2 in grammes\n */\n perByte(bytes, green = false) {\n return this.model.perByte(bytes, green, this.model.results.segment);\n }\n\n /**\n * Accept a figure in bytes for data transfer, and a boolean for whether\n * the domain shows as 'green', and return a CO2 figure for energy used to shift the corresponding\n * the data transfer.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @return {number} the amount of CO2 in grammes\n */\n perVisit(bytes, green = false) {\n if (this.model?.perVisit) {\n return this.model.perVisit(bytes, green, this.model.results.segment);\n } else {\n throw new Error(\n `The perVisit() method is not supported in the model you are using. Try using perByte() instead.\\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`\n );\n }\n }\n\n /**\n * Accept a figure in bytes for data transfer, a boolean for whether\n * the domain shows as 'green', and an options object.\n * Returns an object containing CO2 figure, green boolean, and object of the variables used in calculating the CO2 figure.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @param {Object} options\n * @return {CO2EstimateTraceResultPerByte} the amount of CO2 in grammes\n */\n perByteTrace(bytes, green = false, options = {}) {\n let adjustments = {};\n if (options) {\n // If there are options, parse them and add them to the model.\n adjustments = parseOptions(options);\n }\n return {\n co2: this.model.perByte(\n bytes,\n green,\n this.model.results.segment,\n adjustments\n ),\n green,\n variables: {\n description:\n \"Below are the variables used to calculate this CO2 estimate.\",\n bytes,\n gridIntensity: {\n description:\n \"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.\",\n network:\n adjustments?.gridIntensity?.network?.value || GLOBAL_GRID_INTENSITY,\n dataCenter: green\n ? RENEWABLES_GRID_INTENSITY\n : adjustments?.gridIntensity?.dataCenter?.value ||\n GLOBAL_GRID_INTENSITY,\n production: GLOBAL_GRID_INTENSITY,\n device:\n adjustments?.gridIntensity?.device?.value || GLOBAL_GRID_INTENSITY,\n },\n },\n };\n }\n\n /**\n * Accept a figure in bytes for data transfer, a boolean for whether\n * the domain shows as 'green', and an options object.\n * Returns an object containing CO2 figure, green boolean, and object of the variables used in calculating the CO2 figure.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @param {Object} options\n * @return {CO2EstimateTraceResultPerVisit} the amount of CO2 in grammes\n */\n perVisitTrace(bytes, green = false, options = {}) {\n if (this.model?.perVisit) {\n let adjustments = {};\n if (options) {\n // If there are options, parse them and add them to the model.\n adjustments = parseOptions(options);\n }\n\n return {\n co2: this.model.perVisit(\n bytes,\n green,\n this.model.results.segment,\n adjustments\n ),\n green,\n variables: {\n description:\n \"Below are the variables used to calculate this CO2 estimate.\",\n bytes,\n gridIntensity: {\n description:\n \"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.\",\n network:\n adjustments?.gridIntensity?.network?.value ||\n GLOBAL_GRID_INTENSITY,\n dataCenter: green\n ? RENEWABLES_GRID_INTENSITY\n : adjustments?.gridIntensity?.dataCenter?.value ||\n GLOBAL_GRID_INTENSITY,\n production: GLOBAL_GRID_INTENSITY,\n device:\n adjustments?.gridIntensity?.device?.value ||\n GLOBAL_GRID_INTENSITY,\n },\n dataReloadRatio: adjustments?.dataReloadRatio || 0.02,\n firstVisitPercentage: adjustments?.firstVisitPercentage || 0.75,\n returnVisitPercentage: adjustments?.returnVisitPercentage || 0.25,\n },\n };\n } else {\n throw new Error(\n `The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead.\\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`\n );\n }\n }\n\n perDomain(pageXray, greenDomains) {\n const co2PerDomain = [];\n for (let domain of Object.keys(pageXray.domains)) {\n let co2;\n if (greenDomains && greenDomains.indexOf(domain) > -1) {\n co2 = this.perByte(pageXray.domains[domain].transferSize, true);\n } else {\n co2 = this.perByte(pageXray.domains[domain].transferSize);\n }\n co2PerDomain.push({\n domain,\n co2,\n transferSize: pageXray.domains[domain].transferSize,\n });\n }\n co2PerDomain.sort((a, b) => b.co2 - a.co2);\n\n return co2PerDomain;\n }\n\n perPage(pageXray, green) {\n // Accept an xray object, and if we receive a boolean as the second\n // argument, we assume every request we make is sent to a server\n // running on renwewable power.\n\n // if we receive an array of domains, return a number accounting the\n // reduced CO2 from green hosted domains\n\n const domainCO2 = this.perDomain(pageXray, green);\n let totalCO2 = 0;\n for (let domain of domainCO2) {\n totalCO2 += domain.co2;\n }\n return totalCO2;\n }\n\n perContentType(pageXray, greenDomains) {\n const co2PerContentType = {};\n for (let asset of pageXray.assets) {\n const domain = new URL(asset.url).domain;\n const transferSize = asset.transferSize;\n const co2ForTransfer = this.perByte(\n transferSize,\n greenDomains && greenDomains.indexOf(domain) > -1\n );\n const contentType = asset.type;\n if (!co2PerContentType[contentType]) {\n co2PerContentType[contentType] = { co2: 0, transferSize: 0 };\n }\n co2PerContentType[contentType].co2 += co2ForTransfer;\n co2PerContentType[contentType].transferSize += transferSize;\n }\n // restructure and sort\n const all = [];\n for (let type of Object.keys(co2PerContentType)) {\n all.push({\n type,\n co2: co2PerContentType[type].co2,\n transferSize: co2PerContentType[type].transferSize,\n });\n }\n all.sort((a, b) => b.co2 - a.co2);\n return all;\n }\n\n dirtiestResources(pageXray, greenDomains) {\n const allAssets = [];\n for (let asset of pageXray.assets) {\n const domain = new URL(asset.url).domain;\n const transferSize = asset.transferSize;\n const co2ForTransfer = this.perByte(\n transferSize,\n greenDomains && greenDomains.indexOf(domain) > -1\n );\n allAssets.push({ url: asset.url, co2: co2ForTransfer, transferSize });\n }\n allAssets.sort((a, b) => b.co2 - a.co2);\n\n return allAssets.slice(0, allAssets.length > 10 ? 10 : allAssets.length);\n }\n\n perParty(pageXray, greenDomains) {\n let firstParty = 0;\n let thirdParty = 0;\n // calculate co2 per first/third party\n const firstPartyRegEx = pageXray.firstPartyRegEx;\n for (let d of Object.keys(pageXray.domains)) {\n if (!d.match(firstPartyRegEx)) {\n thirdParty += this.perByte(\n pageXray.domains[d].transferSize,\n greenDomains && greenDomains.indexOf(d) > -1\n );\n } else {\n firstParty += this.perByte(\n pageXray.domains[d].transferSize,\n greenDomains && greenDomains.indexOf(d) > -1\n );\n }\n }\n return { firstParty, thirdParty };\n }\n}\n\nexport { CO2 };\nexport default CO2;\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;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ACnB,aAAS,SAAS,SAAS,QAAQ;AACjC,YAAM,SAAS,IAAI,IAAI,MAAM,GAAG,EAAE;AAClC,YAAM,eAAe,MAAM;AAC3B,YAAM,iBAAiB,KAAK,QAC1B,cACA,gBAAgB,aAAa,QAAQ,MAAM,IAAI,EACjD;AACA,gBAAU,KAAK,EAAE,KAAK,MAAM,KAAK,KAAK,gBAAgB,aAAa,CAAC;AAAA,IACtE;AACA,cAAU,KAAK,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG;AAEtC,WAAO,UAAU,MAAM,GAAG,UAAU,SAAS,KAAK,KAAK,UAAU,MAAM;AAAA,EACzE;AAAA,EAEA,SAAS,UAAU,cAAc;AAC/B,QAAI,aAAa;AACjB,QAAI,aAAa;AAEjB,UAAM,kBAAkB,SAAS;AACjC,aAAS,KAAK,OAAO,KAAK,SAAS,OAAO,GAAG;AAC3C,UAAI,CAAC,EAAE,MAAM,eAAe,GAAG;AAC7B,sBAAc,KAAK,QACjB,SAAS,QAAQ,GAAG,cACpB,gBAAgB,aAAa,QAAQ,CAAC,IAAI,EAC5C;AAAA,MACF,OAAO;AACL,sBAAc,KAAK,QACjB,SAAS,QAAQ,GAAG,cACpB,gBAAgB,aAAa,QAAQ,CAAC,IAAI,EAC5C;AAAA,MACF;AAAA,IACF;AACA,WAAO,EAAE,YAAY,WAAW;AAAA,EAClC;AACF;AAGA,IAAO,cAAQ;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -16,10 +16,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
23
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
21
|
var constants_exports = {};
|
|
25
22
|
__export(constants_exports, {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/constants/index.js"],
|
|
4
4
|
"sourcesContent": ["import fileSize from \"./file-size.js\";\n\n// SUSTAINABLE WEB DESIGN CONSTANTS\n// this refers to the estimated total energy use for the internet around 2000 TWh,\n// divided by the total transfer it enables around 2500 exabytes\nconst KWH_PER_GB = 0.81;\n\n// these constants outline how the energy is attributed to\n// different parts of the system in the SWD model\nconst END_USER_DEVICE_ENERGY = 0.52;\nconst NETWORK_ENERGY = 0.14;\nconst DATACENTER_ENERGY = 0.15;\nconst PRODUCTION_ENERGY = 0.19;\n\n// These carbon intensity figures https://ember-climate.org/data/data-explorer\n// - Global carbon intensity for 2021\nconst GLOBAL_GRID_INTENSITY = 442;\nconst RENEWABLES_GRID_INTENSITY = 50;\n\n// Taken from: https://gitlab.com/wholegrain/carbon-api-2-0/-/blob/master/includes/carbonapi.php\n\nconst FIRST_TIME_VIEWING_PERCENTAGE = 0.75;\nconst RETURNING_VISITOR_PERCENTAGE = 0.25;\nconst PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD = 0.02;\n\nexport {\n fileSize,\n KWH_PER_GB,\n END_USER_DEVICE_ENERGY,\n NETWORK_ENERGY,\n DATACENTER_ENERGY,\n PRODUCTION_ENERGY,\n GLOBAL_GRID_INTENSITY,\n RENEWABLES_GRID_INTENSITY,\n FIRST_TIME_VIEWING_PERCENTAGE,\n RETURNING_VISITOR_PERCENTAGE,\n PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD,\n};\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAqB;AAKrB,MAAM,aAAa;AAInB,MAAM,yBAAyB;AAC/B,MAAM,iBAAiB;AACvB,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB;AAI1B,MAAM,wBAAwB;AAC9B,MAAM,4BAA4B;AAIlC,MAAM,gCAAgC;AACtC,MAAM,+BAA+B;AACrC,MAAM,+CAA+C;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var average_intensities_min_exports = {};
|
|
19
|
+
__export(average_intensities_min_exports, {
|
|
20
|
+
data: () => data,
|
|
21
|
+
default: () => average_intensities_min_default,
|
|
22
|
+
type: () => type
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(average_intensities_min_exports);
|
|
25
|
+
const data = { "AFG": 120.482, "Africa": 483.78, "ALB": 23.438, "DZA": 488.393, "ASM": 687.5, "AGO": 168.594, "ATG": 657.143, "ARG": 337.533, "ARM": 222.678, "ABW": 591.398, "Asia": 531.78, "AUS": 503.179, "AUT": 157.52, "AZE": 532.902, "BHS": 698.113, "BHR": 489.924, "BGD": 581.485, "BRB": 644.86, "BLR": 415.774, "BEL": 165.363, "BLZ": 484.375, "BEN": 666.667, "BTN": 24.444, "BOL": 319.432, "BIH": 516.626, "BWA": 794.521, "BRA": 102.411, "BRN": 658.849, "BGR": 399.565, "BFA": 611.429, "BDI": 250, "CPV": 600, "KHM": 399.31, "CMR": 278.261, "CAN": 125.55, "CYM": 684.932, "CAF": 0, "TCD": 677.419, "CHL": 333.173, "CHN": 530.214, "COL": 169.309, "COM": 714.286, "COG": 398.01, "COD": 25.362, "COK": 400, "CRI": 37.213, "CIV": 390.71, "HRV": 246.459, "CUB": 574.684, "CYP": 589.354, "CZE": 415.345, "DNK": 180.709, "DJI": 666.667, "DMA": 529.412, "DOM": 540.387, "ECU": 169.384, "EGY": 485.367, "SLV": 194.226, "GNQ": 492.958, "ERI": 688.889, "EST": 464.029, "SWZ": 189.189, "ETH": 25.187, "EU": 277.35, "Europe": 298.01, "FLK": 500, "FRO": 428.571, "FJI": 292.035, "FIN": 130.977, "FRA": 84.817, "GUF": 254.717, "PYF": 471.429, "G20": 440.39, "G7": 341.23, "GAB": 397.38, "GMB": 700, "GEO": 134.831, "DEU": 385.467, "GHA": 362.942, "GRC": 343.822, "GRL": 133.333, "GRD": 714.286, "GLP": 611.765, "GUM": 670.33, "GTM": 313.019, "GIN": 208.633, "GNB": 750, "GUY": 634.146, "HTI": 606.061, "HND": 374.269, "HKG": 684.823, "HUN": 222.973, "ISL": 28.557, "IND": 632.406, "IDN": 623.281, "IRN": 493.595, "IRQ": 500.206, "IRL": 345.347, "ISR": 550.493, "ITA": 371.692, "JAM": 524.138, "JPN": 483.039, "JOR": 399.909, "KAZ": 635.574, "KEN": 99.919, "KIR": 666.667, "XKX": 766.605, "KWT": 489.61, "KGZ": 104.354, "LAO": 242.182, "Latin America and Caribbean": 238.27, "LVA": 181.818, "LBN": 545.941, "LSO": 20, "LBR": 304.348, "LBY": 496.565, "LTU": 194.245, "LUX": 168.142, "MAC": 491.525, "MDG": 483.254, "MWI": 133.803, "MYS": 543.737, "MDV": 651.515, "MLI": 466.077, "MLT": 442.478, "MTQ": 698.63, "MRT": 526.596, "MUS": 611.111, "MEX": 421.402, "Middle East": 514.89, "MDA": 685.874, "MNG": 749.656, "MNE": 399.381, "MSR": 1e3, "MAR": 610.412, "MOZ": 125.063, "MMR": 348.837, "NAM": 63.694, "NRU": 750, "NPL": 24.51, "NLD": 354.988, "NCL": 610.119, "NZL": 98.639, "NIC": 354.212, "NER": 622.222, "NGA": 368.421, "North America": 336.4, "PRK": 157.785, "MKD": 529.328, "NOR": 28.818, "Oceania": 446.65, "OECD": 338.75, "OMN": 488.272, "PAK": 343.366, "PSE": 465.116, "PAN": 193.923, "PNG": 526.749, "PRY": 25.487, "PER": 254.521, "POL": 634.579, "PRT": 234.029, "PRI": 681.469, "QAT": 489.867, "REU": 519.031, "ROU": 264.121, "RUS": 367.189, "RWA": 294.118, "KNA": 681.818, "LCA": 685.714, "SPM": 800, "VCT": 500, "WSM": 470.588, "STP": 600, "SAU": 571.336, "SEN": 502.674, "SRB": 569.375, "SYC": 615.385, "SLE": 47.619, "SGP": 489.234, "SVK": 140.666, "SVN": 237.378, "SLB": 727.273, "SOM": 634.146, "ZAF": 709.002, "KOR": 435.689, "SSD": 684.211, "ESP": 217.373, "LKA": 479.829, "SDN": 242.917, "SUR": 356.436, "SWE": 45.084, "CHE": 45.622, "SYR": 540.573, "TWN": 561.431, "TJK": 84.136, "TZA": 361.077, "THA": 503.07, "PHL": 582.365, "TGO": 507.937, "TON": 625, "TTO": 520.046, "TUN": 469.428, "TUR": 413.628, "TKM": 544.393, "TCA": 703.704, "UGA": 52.273, "UKR": 206.539, "ARE": 461.845, "GBR": 257.379, "USA": 367.768, "URY": 116.168, "UZB": 506.164, "VUT": 571.429, "VEN": 189.446, "VNM": 376.828, "VGB": 714.286, "VIR": 685.714, "World": 435.99, "YEM": 528.409, "ZMB": 84.698, "ZWE": 393.035 };
|
|
26
|
+
const type = "average";
|
|
27
|
+
var average_intensities_min_default = { data, type };
|
|
28
|
+
//# sourceMappingURL=average-intensities.min.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/data/average-intensities.min.js"],
|
|
4
|
+
"sourcesContent": ["const data = {\"AFG\":120.482,\"Africa\":483.78,\"ALB\":23.438,\"DZA\":488.393,\"ASM\":687.5,\"AGO\":168.594,\"ATG\":657.143,\"ARG\":337.533,\"ARM\":222.678,\"ABW\":591.398,\"Asia\":531.78,\"AUS\":503.179,\"AUT\":157.52,\"AZE\":532.902,\"BHS\":698.113,\"BHR\":489.924,\"BGD\":581.485,\"BRB\":644.86,\"BLR\":415.774,\"BEL\":165.363,\"BLZ\":484.375,\"BEN\":666.667,\"BTN\":24.444,\"BOL\":319.432,\"BIH\":516.626,\"BWA\":794.521,\"BRA\":102.411,\"BRN\":658.849,\"BGR\":399.565,\"BFA\":611.429,\"BDI\":250,\"CPV\":600,\"KHM\":399.31,\"CMR\":278.261,\"CAN\":125.55,\"CYM\":684.932,\"CAF\":0,\"TCD\":677.419,\"CHL\":333.173,\"CHN\":530.214,\"COL\":169.309,\"COM\":714.286,\"COG\":398.01,\"COD\":25.362,\"COK\":400,\"CRI\":37.213,\"CIV\":390.71,\"HRV\":246.459,\"CUB\":574.684,\"CYP\":589.354,\"CZE\":415.345,\"DNK\":180.709,\"DJI\":666.667,\"DMA\":529.412,\"DOM\":540.387,\"ECU\":169.384,\"EGY\":485.367,\"SLV\":194.226,\"GNQ\":492.958,\"ERI\":688.889,\"EST\":464.029,\"SWZ\":189.189,\"ETH\":25.187,\"EU\":277.35,\"Europe\":298.01,\"FLK\":500,\"FRO\":428.571,\"FJI\":292.035,\"FIN\":130.977,\"FRA\":84.817,\"GUF\":254.717,\"PYF\":471.429,\"G20\":440.39,\"G7\":341.23,\"GAB\":397.38,\"GMB\":700,\"GEO\":134.831,\"DEU\":385.467,\"GHA\":362.942,\"GRC\":343.822,\"GRL\":133.333,\"GRD\":714.286,\"GLP\":611.765,\"GUM\":670.33,\"GTM\":313.019,\"GIN\":208.633,\"GNB\":750,\"GUY\":634.146,\"HTI\":606.061,\"HND\":374.269,\"HKG\":684.823,\"HUN\":222.973,\"ISL\":28.557,\"IND\":632.406,\"IDN\":623.281,\"IRN\":493.595,\"IRQ\":500.206,\"IRL\":345.347,\"ISR\":550.493,\"ITA\":371.692,\"JAM\":524.138,\"JPN\":483.039,\"JOR\":399.909,\"KAZ\":635.574,\"KEN\":99.919,\"KIR\":666.667,\"XKX\":766.605,\"KWT\":489.61,\"KGZ\":104.354,\"LAO\":242.182,\"Latin America and Caribbean\":238.27,\"LVA\":181.818,\"LBN\":545.941,\"LSO\":20,\"LBR\":304.348,\"LBY\":496.565,\"LTU\":194.245,\"LUX\":168.142,\"MAC\":491.525,\"MDG\":483.254,\"MWI\":133.803,\"MYS\":543.737,\"MDV\":651.515,\"MLI\":466.077,\"MLT\":442.478,\"MTQ\":698.63,\"MRT\":526.596,\"MUS\":611.111,\"MEX\":421.402,\"Middle East\":514.89,\"MDA\":685.874,\"MNG\":749.656,\"MNE\":399.381,\"MSR\":1000,\"MAR\":610.412,\"MOZ\":125.063,\"MMR\":348.837,\"NAM\":63.694,\"NRU\":750,\"NPL\":24.51,\"NLD\":354.988,\"NCL\":610.119,\"NZL\":98.639,\"NIC\":354.212,\"NER\":622.222,\"NGA\":368.421,\"North America\":336.4,\"PRK\":157.785,\"MKD\":529.328,\"NOR\":28.818,\"Oceania\":446.65,\"OECD\":338.75,\"OMN\":488.272,\"PAK\":343.366,\"PSE\":465.116,\"PAN\":193.923,\"PNG\":526.749,\"PRY\":25.487,\"PER\":254.521,\"POL\":634.579,\"PRT\":234.029,\"PRI\":681.469,\"QAT\":489.867,\"REU\":519.031,\"ROU\":264.121,\"RUS\":367.189,\"RWA\":294.118,\"KNA\":681.818,\"LCA\":685.714,\"SPM\":800,\"VCT\":500,\"WSM\":470.588,\"STP\":600,\"SAU\":571.336,\"SEN\":502.674,\"SRB\":569.375,\"SYC\":615.385,\"SLE\":47.619,\"SGP\":489.234,\"SVK\":140.666,\"SVN\":237.378,\"SLB\":727.273,\"SOM\":634.146,\"ZAF\":709.002,\"KOR\":435.689,\"SSD\":684.211,\"ESP\":217.373,\"LKA\":479.829,\"SDN\":242.917,\"SUR\":356.436,\"SWE\":45.084,\"CHE\":45.622,\"SYR\":540.573,\"TWN\":561.431,\"TJK\":84.136,\"TZA\":361.077,\"THA\":503.07,\"PHL\":582.365,\"TGO\":507.937,\"TON\":625,\"TTO\":520.046,\"TUN\":469.428,\"TUR\":413.628,\"TKM\":544.393,\"TCA\":703.704,\"UGA\":52.273,\"UKR\":206.539,\"ARE\":461.845,\"GBR\":257.379,\"USA\":367.768,\"URY\":116.168,\"UZB\":506.164,\"VUT\":571.429,\"VEN\":189.446,\"VNM\":376.828,\"VGB\":714.286,\"VIR\":685.714,\"World\":435.99,\"YEM\":528.409,\"ZMB\":84.698,\"ZWE\":393.035}; const type = \"average\"; export { data, type }; export default { data, type };"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,OAAO,EAAC,OAAM,SAAQ,UAAS,QAAO,OAAM,QAAO,OAAM,SAAQ,OAAM,OAAM,OAAM,SAAQ,OAAM,SAAQ,OAAM,SAAQ,OAAM,SAAQ,OAAM,SAAQ,QAAO,QAAO,OAAM,SAAQ,OAAM,QAAO,OAAM,SAAQ,OAAM,SAAQ,OAAM,SAAQ,OAAM,SAAQ,OAAM,QAAO,OAAM,SAAQ,OAAM,SAAQ,OAAM,SAAQ,OAAM,SAAQ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AAM,SAAQ,OAAM,SAAQ,OAAM,SAAQ,OAAM,SAAQ,OAAM,SAAQ,SAAQ,QAAO,OAAM,SAAQ,OAAM,QAAO,OAAM,QAAO;AAAG,MAAM,OAAO;AAAkC,IAAO,kCAAQ,EAAE,MAAM,KAAK;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -36,20 +36,16 @@ function parseOptions(options) {
|
|
|
36
36
|
if (device) {
|
|
37
37
|
if (typeof device === "object") {
|
|
38
38
|
if (!import__.averageIntensity.data[(_a = device.country) == null ? void 0 : _a.toUpperCase()]) {
|
|
39
|
-
console.warn(
|
|
40
|
-
`"${device.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
39
|
+
console.warn(`"${device.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
41
40
|
See https://developers.thegreenwebfoundation.org/co2js/data/ for more information.
|
|
42
|
-
Falling back to global average grid intensity.`
|
|
43
|
-
);
|
|
41
|
+
Falling back to global average grid intensity.`);
|
|
44
42
|
adjustments.gridIntensity["device"] = {
|
|
45
43
|
value: import_constants.GLOBAL_GRID_INTENSITY
|
|
46
44
|
};
|
|
47
45
|
}
|
|
48
46
|
adjustments.gridIntensity["device"] = {
|
|
49
47
|
country: device.country,
|
|
50
|
-
value: parseFloat(
|
|
51
|
-
import__.averageIntensity.data[(_b = device.country) == null ? void 0 : _b.toUpperCase()]
|
|
52
|
-
)
|
|
48
|
+
value: parseFloat(import__.averageIntensity.data[(_b = device.country) == null ? void 0 : _b.toUpperCase()])
|
|
53
49
|
};
|
|
54
50
|
} else if (typeof device === "number") {
|
|
55
51
|
adjustments.gridIntensity["device"] = {
|
|
@@ -59,29 +55,23 @@ Falling back to global average grid intensity.`
|
|
|
59
55
|
adjustments.gridIntensity["device"] = {
|
|
60
56
|
value: import_constants.GLOBAL_GRID_INTENSITY
|
|
61
57
|
};
|
|
62
|
-
console.warn(
|
|
63
|
-
|
|
64
|
-
Falling back to global average grid intensity.`
|
|
65
|
-
);
|
|
58
|
+
console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof device}.
|
|
59
|
+
Falling back to global average grid intensity.`);
|
|
66
60
|
}
|
|
67
61
|
}
|
|
68
62
|
if (dataCenter) {
|
|
69
63
|
if (typeof dataCenter === "object") {
|
|
70
64
|
if (!import__.averageIntensity.data[(_c = dataCenter.country) == null ? void 0 : _c.toUpperCase()]) {
|
|
71
|
-
console.warn(
|
|
72
|
-
`"${dataCenter.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
65
|
+
console.warn(`"${dataCenter.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
73
66
|
See https://developers.thegreenwebfoundation.org/co2js/data/ for more information.
|
|
74
|
-
Falling back to global average grid intensity.`
|
|
75
|
-
);
|
|
67
|
+
Falling back to global average grid intensity.`);
|
|
76
68
|
adjustments.gridIntensity["dataCenter"] = {
|
|
77
69
|
value: import_constants.GLOBAL_GRID_INTENSITY
|
|
78
70
|
};
|
|
79
71
|
}
|
|
80
72
|
adjustments.gridIntensity["dataCenter"] = {
|
|
81
73
|
country: dataCenter.country,
|
|
82
|
-
value: parseFloat(
|
|
83
|
-
import__.averageIntensity.data[(_d = dataCenter.country) == null ? void 0 : _d.toUpperCase()]
|
|
84
|
-
)
|
|
74
|
+
value: parseFloat(import__.averageIntensity.data[(_d = dataCenter.country) == null ? void 0 : _d.toUpperCase()])
|
|
85
75
|
};
|
|
86
76
|
} else if (typeof dataCenter === "number") {
|
|
87
77
|
adjustments.gridIntensity["dataCenter"] = {
|
|
@@ -91,29 +81,23 @@ Falling back to global average grid intensity.`
|
|
|
91
81
|
adjustments.gridIntensity["dataCenter"] = {
|
|
92
82
|
value: import_constants.GLOBAL_GRID_INTENSITY
|
|
93
83
|
};
|
|
94
|
-
console.warn(
|
|
95
|
-
|
|
96
|
-
Falling back to global average grid intensity.`
|
|
97
|
-
);
|
|
84
|
+
console.warn(`The data center grid intensity must be a number or an object. You passed in a ${typeof dataCenter}.
|
|
85
|
+
Falling back to global average grid intensity.`);
|
|
98
86
|
}
|
|
99
87
|
}
|
|
100
88
|
if (network) {
|
|
101
89
|
if (typeof network === "object") {
|
|
102
90
|
if (!import__.averageIntensity.data[(_e = network.country) == null ? void 0 : _e.toUpperCase()]) {
|
|
103
|
-
console.warn(
|
|
104
|
-
`"${network.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
91
|
+
console.warn(`"${network.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
105
92
|
See https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity.
|
|
106
|
-
Falling back to global average grid intensity.`
|
|
107
|
-
);
|
|
93
|
+
Falling back to global average grid intensity.`);
|
|
108
94
|
adjustments.gridIntensity["network"] = {
|
|
109
95
|
value: import_constants.GLOBAL_GRID_INTENSITY
|
|
110
96
|
};
|
|
111
97
|
}
|
|
112
98
|
adjustments.gridIntensity["network"] = {
|
|
113
99
|
country: network.country,
|
|
114
|
-
value: parseFloat(
|
|
115
|
-
import__.averageIntensity.data[(_f = network.country) == null ? void 0 : _f.toUpperCase()]
|
|
116
|
-
)
|
|
100
|
+
value: parseFloat(import__.averageIntensity.data[(_f = network.country) == null ? void 0 : _f.toUpperCase()])
|
|
117
101
|
};
|
|
118
102
|
} else if (typeof network === "number") {
|
|
119
103
|
adjustments.gridIntensity["network"] = {
|
|
@@ -123,10 +107,8 @@ Falling back to global average grid intensity.`
|
|
|
123
107
|
adjustments.gridIntensity["network"] = {
|
|
124
108
|
value: import_constants.GLOBAL_GRID_INTENSITY
|
|
125
109
|
};
|
|
126
|
-
console.warn(
|
|
127
|
-
|
|
128
|
-
Falling back to global average grid intensity.`
|
|
129
|
-
);
|
|
110
|
+
console.warn(`The network grid intensity must be a number or an object. You passed in a ${typeof network}.
|
|
111
|
+
Falling back to global average grid intensity.`);
|
|
130
112
|
}
|
|
131
113
|
}
|
|
132
114
|
}
|
|
@@ -136,17 +118,13 @@ Falling back to global average grid intensity.`
|
|
|
136
118
|
adjustments.dataReloadRatio = options.dataReloadRatio;
|
|
137
119
|
} else {
|
|
138
120
|
adjustments.dataReloadRatio = import_constants.PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD;
|
|
139
|
-
console.warn(
|
|
140
|
-
|
|
141
|
-
Falling back to default value.`
|
|
142
|
-
);
|
|
121
|
+
console.warn(`The dataReloadRatio option must be a number between 0 and 1. You passed in ${options.dataReloadRatio}.
|
|
122
|
+
Falling back to default value.`);
|
|
143
123
|
}
|
|
144
124
|
} else {
|
|
145
125
|
adjustments.dataReloadRatio = import_constants.PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD;
|
|
146
|
-
console.warn(
|
|
147
|
-
|
|
148
|
-
Falling back to default value.`
|
|
149
|
-
);
|
|
126
|
+
console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof options.dataReloadRatio}.
|
|
127
|
+
Falling back to default value.`);
|
|
150
128
|
}
|
|
151
129
|
}
|
|
152
130
|
if (options == null ? void 0 : options.firstVisitPercentage) {
|
|
@@ -155,17 +133,13 @@ Falling back to default value.`
|
|
|
155
133
|
adjustments.firstVisitPercentage = options.firstVisitPercentage;
|
|
156
134
|
} else {
|
|
157
135
|
adjustments.firstVisitPercentage = import_constants.FIRST_TIME_VIEWING_PERCENTAGE;
|
|
158
|
-
console.warn(
|
|
159
|
-
|
|
160
|
-
Falling back to default value.`
|
|
161
|
-
);
|
|
136
|
+
console.warn(`The firstVisitPercentage option must be a number between 0 and 1. You passed in ${options.firstVisitPercentage}.
|
|
137
|
+
Falling back to default value.`);
|
|
162
138
|
}
|
|
163
139
|
} else {
|
|
164
140
|
adjustments.firstVisitPercentage = import_constants.FIRST_TIME_VIEWING_PERCENTAGE;
|
|
165
|
-
console.warn(
|
|
166
|
-
|
|
167
|
-
Falling back to default value.`
|
|
168
|
-
);
|
|
141
|
+
console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof options.firstVisitPercentage}.
|
|
142
|
+
Falling back to default value.`);
|
|
169
143
|
}
|
|
170
144
|
}
|
|
171
145
|
if (options == null ? void 0 : options.returnVisitPercentage) {
|
|
@@ -174,17 +148,13 @@ Falling back to default value.`
|
|
|
174
148
|
adjustments.returnVisitPercentage = options.returnVisitPercentage;
|
|
175
149
|
} else {
|
|
176
150
|
adjustments.returnVisitPercentage = import_constants.RETURNING_VISITOR_PERCENTAGE;
|
|
177
|
-
console.warn(
|
|
178
|
-
|
|
179
|
-
Falling back to default value.`
|
|
180
|
-
);
|
|
151
|
+
console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}.
|
|
152
|
+
Falling back to default value.`);
|
|
181
153
|
}
|
|
182
154
|
} else {
|
|
183
155
|
adjustments.returnVisitPercentage = import_constants.RETURNING_VISITOR_PERCENTAGE;
|
|
184
|
-
console.warn(
|
|
185
|
-
|
|
186
|
-
Falling back to default value.`
|
|
187
|
-
);
|
|
156
|
+
console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}.
|
|
157
|
+
Falling back to default value.`);
|
|
188
158
|
}
|
|
189
159
|
}
|
|
190
160
|
return adjustments;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/index.js"],
|
|
4
4
|
"sourcesContent": ["import { averageIntensity } from \"../index.js\";\nimport {\n GLOBAL_GRID_INTENSITY,\n PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD,\n FIRST_TIME_VIEWING_PERCENTAGE,\n RETURNING_VISITOR_PERCENTAGE,\n} from \"../constants/index.js\";\nconst formatNumber = (num) => parseFloat(num.toFixed(2));\n\nfunction parseOptions(options) {\n // CHeck that it is an object\n if (typeof options !== \"object\") {\n throw new Error(\"Options must be an object\");\n }\n\n const adjustments = {};\n\n if (options?.gridIntensity) {\n adjustments.gridIntensity = {};\n const { device, dataCenter, network } = options.gridIntensity;\n if (device) {\n if (typeof device === \"object\") {\n if (!averageIntensity.data[device.country?.toUpperCase()]) {\n console.warn(\n `\"${device.country}\" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \\nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \\nFalling back to global average grid intensity.`\n );\n adjustments.gridIntensity[\"device\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n }\n adjustments.gridIntensity[\"device\"] = {\n country: device.country,\n value: parseFloat(\n averageIntensity.data[device.country?.toUpperCase()]\n ),\n };\n } else if (typeof device === \"number\") {\n adjustments.gridIntensity[\"device\"] = {\n value: device,\n };\n } else {\n adjustments.gridIntensity[\"device\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n console.warn(\n `The device grid intensity must be a number or an object. You passed in a ${typeof device}. \\nFalling back to global average grid intensity.`\n );\n }\n }\n if (dataCenter) {\n if (typeof dataCenter === \"object\") {\n if (!averageIntensity.data[dataCenter.country?.toUpperCase()]) {\n console.warn(\n `\"${dataCenter.country}\" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \\nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \\nFalling back to global average grid intensity.`\n );\n adjustments.gridIntensity[\"dataCenter\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n }\n adjustments.gridIntensity[\"dataCenter\"] = {\n country: dataCenter.country,\n value: parseFloat(\n averageIntensity.data[dataCenter.country?.toUpperCase()]\n ),\n };\n } else if (typeof dataCenter === \"number\") {\n adjustments.gridIntensity[\"dataCenter\"] = {\n value: dataCenter,\n };\n } else {\n adjustments.gridIntensity[\"dataCenter\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n console.warn(\n `The data center grid intensity must be a number or an object. You passed in a ${typeof dataCenter}. \\nFalling back to global average grid intensity.`\n );\n }\n }\n if (network) {\n if (typeof network === \"object\") {\n if (!averageIntensity.data[network.country?.toUpperCase()]) {\n console.warn(\n `\"${network.country}\" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \\nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity. \\nFalling back to global average grid intensity.`\n );\n adjustments.gridIntensity[\"network\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n }\n adjustments.gridIntensity[\"network\"] = {\n country: network.country,\n value: parseFloat(\n averageIntensity.data[network.country?.toUpperCase()]\n ),\n };\n } else if (typeof network === \"number\") {\n adjustments.gridIntensity[\"network\"] = {\n value: network,\n };\n } else {\n adjustments.gridIntensity[\"network\"] = {\n value: GLOBAL_GRID_INTENSITY,\n };\n console.warn(\n `The network grid intensity must be a number or an object. You passed in a ${typeof network}. \\nFalling back to global average grid intensity.`\n );\n }\n }\n }\n\n if (options?.dataReloadRatio) {\n if (typeof options.dataReloadRatio === \"number\") {\n if (options.dataReloadRatio >= 0 && options.dataReloadRatio <= 1) {\n adjustments.dataReloadRatio = options.dataReloadRatio;\n } else {\n adjustments.dataReloadRatio =\n PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD;\n console.warn(\n `The dataReloadRatio option must be a number between 0 and 1. You passed in ${options.dataReloadRatio}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.dataReloadRatio =\n PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD;\n console.warn(\n `The dataReloadRatio option must be a number. You passed in a ${typeof options.dataReloadRatio}. \\nFalling back to default value.`\n );\n }\n }\n\n if (options?.firstVisitPercentage) {\n if (typeof options.firstVisitPercentage === \"number\") {\n if (\n options.firstVisitPercentage >= 0 &&\n options.firstVisitPercentage <= 1\n ) {\n adjustments.firstVisitPercentage = options.firstVisitPercentage;\n } else {\n adjustments.firstVisitPercentage = FIRST_TIME_VIEWING_PERCENTAGE;\n console.warn(\n `The firstVisitPercentage option must be a number between 0 and 1. You passed in ${options.firstVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.firstVisitPercentage = FIRST_TIME_VIEWING_PERCENTAGE;\n console.warn(\n `The firstVisitPercentage option must be a number. You passed in a ${typeof options.firstVisitPercentage}. \\nFalling back to default value.`\n );\n }\n }\n\n if (options?.returnVisitPercentage) {\n if (typeof options.returnVisitPercentage === \"number\") {\n if (\n options.returnVisitPercentage >= 0 &&\n options.returnVisitPercentage <= 1\n ) {\n adjustments.returnVisitPercentage = options.returnVisitPercentage;\n } else {\n adjustments.returnVisitPercentage = RETURNING_VISITOR_PERCENTAGE;\n console.warn(\n `The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.returnVisitPercentage = RETURNING_VISITOR_PERCENTAGE;\n console.warn(\n `The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}. \\nFalling back to default value.`\n );\n }\n }\n\n return adjustments;\n}\n\nexport { formatNumber, parseOptions };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAAiC;AACjC,uBAKO;AACP,MAAM,eAAe,CAAC,QAAQ,WAAW,IAAI,QAAQ,CAAC,CAAC;AAEvD,
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAAiC;AACjC,uBAKO;AACP,MAAM,eAAe,CAAC,QAAQ,WAAW,IAAI,QAAQ,CAAC,CAAC;AAEvD,sBAAsB,SAAS;AAT/B;AAWE,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC7C;AAEA,QAAM,cAAc,CAAC;AAErB,MAAI,mCAAS,eAAe;AAC1B,gBAAY,gBAAgB,CAAC;AAC7B,UAAM,EAAE,QAAQ,YAAY,YAAY,QAAQ;AAChD,QAAI,QAAQ;AACV,UAAI,OAAO,WAAW,UAAU;AAC9B,YAAI,CAAC,0BAAiB,KAAK,aAAO,YAAP,mBAAgB,gBAAgB;AACzD,kBAAQ,KACN,IAAI,OAAO;AAAA;AAAA,+CAC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9C,OAAO;AACL,oBAAY,wBAAwB;AACpC,gBAAQ,KACN,oFAAoF,QAAQ;AAAA,+BAC9F;AAAA,MACF;AAAA,IACF,OAAO;AACL,kBAAY,wBAAwB;AACpC,cAAQ,KACN,sEAAsE,OAAO,QAAQ;AAAA,+BACvF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/hosting-api.js
CHANGED
|
@@ -17,10 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
24
21
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
22
|
var hosting_api_exports = {};
|
|
26
23
|
__export(hosting_api_exports, {
|
|
@@ -37,9 +34,7 @@ function check(domain) {
|
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
36
|
async function checkAgainstAPI(domain) {
|
|
40
|
-
const req = await fetch(
|
|
41
|
-
`https://api.thegreenwebfoundation.org/greencheck/${domain}`
|
|
42
|
-
);
|
|
37
|
+
const req = await fetch(`https://api.thegreenwebfoundation.org/greencheck/${domain}`);
|
|
43
38
|
const res = await req.json();
|
|
44
39
|
return res.green;
|
|
45
40
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hosting-api.js"],
|
|
4
4
|
"sourcesContent": ["\"use strict\";\n\nimport debugFactory from \"debug\";\nconst log = debugFactory(\"tgwf:hostingAPI\");\n\nfunction check(domain) {\n // is it a single domain or an array of them?\n if (typeof domain === \"string\") {\n return checkAgainstAPI(domain);\n } else {\n return checkDomainsAgainstAPI(domain);\n }\n}\n\nasync function checkAgainstAPI(domain) {\n const req = await fetch(\n `https://api.thegreenwebfoundation.org/greencheck/${domain}`\n );\n const res = await req.json();\n return res.green;\n}\n\nasync function checkDomainsAgainstAPI(domains) {\n try {\n const apiPath = \"https://api.thegreenwebfoundation.org/v2/greencheckmulti\";\n const domainsString = JSON.stringify(domains);\n\n const req = await fetch(`${apiPath}/${domainsString}`);\n\n // sanity check API result. Is this the library or\n // the actual API request that's the problem?\n // Is nock mocking node-native fetch API calls properly?\n // Commented out the logs for now, as they cause an error to be thrown when using the library.\n // log(`${apiPath}/${domainsString}`);\n // log({ req });\n // const textResult = await req.text();\n // log({ textResult });\n\n const allGreenCheckResults = await req.json();\n\n return greenDomainsFromResults(allGreenCheckResults);\n } catch (e) {\n return [];\n }\n}\n\nfunction greenDomainsFromResults(greenResults) {\n const entries = Object.entries(greenResults);\n const greenEntries = entries.filter(([key, val]) => val.green);\n return greenEntries.map(([key, val]) => val.url);\n}\n\nexport default {\n check,\n};\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAyB;AACzB,MAAM,MAAM,0BAAa,iBAAiB;AAE1C,eAAe,QAAQ;AAErB,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,gBAAgB,MAAM;AAAA,EAC/B,OAAO;AACL,WAAO,uBAAuB,MAAM;AAAA,EACtC;AACF;AAEA,+BAA+B,QAAQ;AACrC,QAAM,MAAM,MAAM,MAChB,oDAAoD,QACtD;AACA,QAAM,MAAM,MAAM,IAAI,KAAK;AAC3B,SAAO,IAAI;AACb;AAEA,sCAAsC,SAAS;AAC7C,MAAI;AACF,UAAM,UAAU;AAChB,UAAM,gBAAgB,KAAK,UAAU,OAAO;AAE5C,UAAM,MAAM,MAAM,MAAM,GAAG,WAAW,eAAe;AAWrD,UAAM,uBAAuB,MAAM,IAAI,KAAK;AAE5C,WAAO,wBAAwB,oBAAoB;AAAA,EACrD,SAAS,GAAP;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAEA,iCAAiC,cAAc;AAC7C,QAAM,UAAU,OAAO,QAAQ,YAAY;AAC3C,QAAM,eAAe,QAAQ,OAAO,CAAC,CAAC,KAAK,SAAS,IAAI,KAAK;AAC7D,SAAO,aAAa,IAAI,CAAC,CAAC,KAAK,SAAS,IAAI,GAAG;AACjD;AAEA,IAAO,sBAAQ;AAAA,EACb;AACF;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -13,10 +13,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
13
13
|
}
|
|
14
14
|
return to;
|
|
15
15
|
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
18
|
-
mod
|
|
19
|
-
));
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
17
|
var import_fs = __toESM(require("fs"));
|
|
21
18
|
var import_zlib = __toESM(require("zlib"));
|
|
22
19
|
var import_util = require("util");
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hosting-json.node.js"],
|
|
4
4
|
"sourcesContent": ["\"use strict\";\n\nimport fs from \"fs\";\nimport zlib from \"zlib\";\nimport { promisify } from \"util\";\n\nconst readFile = promisify(fs.readFile);\nconst gunzip = promisify(zlib.gunzip);\n\nimport debugFactory from \"debug\";\nconst log = debugFactory(\"tgwf:hostingCache\");\n\nasync function streamToString(stream) {\n return new Promise((resolve, reject) => {\n const chunks = [];\n stream.on(\"error\", reject);\n stream.on(\"data\", (chunk) => chunks.push(chunk));\n stream.on(\"end\", () => resolve(Buffer.concat(chunks)));\n });\n}\n\nasync function getGzippedFileAsJson(jsonPath) {\n const readStream = fs.createReadStream(jsonPath);\n const text = await streamToString(readStream);\n const unzipped = await gunzip(text);\n return unzipped.toString();\n}\n\nasync function loadJSON(jsonPath) {\n const jsonBuffer = jsonPath.endsWith(\".gz\")\n ? await getGzippedFileAsJson(jsonPath)\n : await readFile(jsonPath);\n return JSON.parse(jsonBuffer);\n}\n\nasync function check(domain, db) {\n // is it a single domain or an array of them?\n if (typeof domain === \"string\") {\n return checkInJSON(domain, db);\n } else {\n return checkDomainsInJSON(domain, db);\n }\n}\n\nfunction checkInJSON(domain, db) {\n if (db.indexOf(domain) > -1) {\n return true;\n }\n return false;\n}\n\nfunction greenDomainsFromResults(greenResults) {\n const entries = Object.entries(greenResults);\n const greenEntries = entries.filter(([key, val]) => val.green);\n\n return greenEntries.map(([key, val]) => val.url);\n}\n\nfunction checkDomainsInJSON(domains, db) {\n let greenDomains = [];\n\n for (let domain of domains) {\n if (db.indexOf(domain) > -1) {\n greenDomains.push(domain);\n }\n }\n return greenDomains;\n}\n\nmodule.exports = {\n check,\n loadJSON,\n greenDomainsFromResults,\n};\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAEA,gBAAe;AACf,kBAAiB;AACjB,kBAA0B;AAK1B,mBAAyB;AAHzB,MAAM,WAAW,2BAAU,kBAAG,QAAQ;AACtC,MAAM,SAAS,2BAAU,oBAAK,MAAM;AAGpC,MAAM,MAAM,0BAAa,mBAAmB;AAE5C,8BAA8B,QAAQ;AACpC,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,SAA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names": []
|
|
7
7
|
}
|
package/dist/cjs/hosting-node.js
CHANGED
|
@@ -16,10 +16,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
23
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
21
|
var hosting_node_exports = {};
|
|
25
22
|
__export(hosting_node_exports, {
|
|
@@ -34,11 +31,7 @@ async function getBody(url) {
|
|
|
34
31
|
return new Promise(function(resolve, reject) {
|
|
35
32
|
const req = import_https.default.get(url, function(res) {
|
|
36
33
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
37
|
-
log(
|
|
38
|
-
"Could not get info from the Green Web Foundation API, %s for %s",
|
|
39
|
-
res.statusCode,
|
|
40
|
-
url
|
|
41
|
-
);
|
|
34
|
+
log("Could not get info from the Green Web Foundation API, %s for %s", res.statusCode, url);
|
|
42
35
|
return reject(new Error(`Status Code: ${res.statusCode}`));
|
|
43
36
|
}
|
|
44
37
|
const data = [];
|
|
@@ -61,20 +54,12 @@ function check(domain, db) {
|
|
|
61
54
|
}
|
|
62
55
|
}
|
|
63
56
|
async function checkAgainstAPI(domain) {
|
|
64
|
-
const res = JSON.parse(
|
|
65
|
-
await getBody(`https://api.thegreenwebfoundation.org/greencheck/${domain}`)
|
|
66
|
-
);
|
|
57
|
+
const res = JSON.parse(await getBody(`https://api.thegreenwebfoundation.org/greencheck/${domain}`));
|
|
67
58
|
return res.green;
|
|
68
59
|
}
|
|
69
60
|
async function checkDomainsAgainstAPI(domains) {
|
|
70
61
|
try {
|
|
71
|
-
const allGreenCheckResults = JSON.parse(
|
|
72
|
-
await getBody(
|
|
73
|
-
`https://api.thegreenwebfoundation.org/v2/greencheckmulti/${JSON.stringify(
|
|
74
|
-
domains
|
|
75
|
-
)}`
|
|
76
|
-
)
|
|
77
|
-
);
|
|
62
|
+
const allGreenCheckResults = JSON.parse(await getBody(`https://api.thegreenwebfoundation.org/v2/greencheckmulti/${JSON.stringify(domains)}`));
|
|
78
63
|
return import_hosting_json_node.default.greenDomainsFromResults(allGreenCheckResults);
|
|
79
64
|
} catch (e) {
|
|
80
65
|
return [];
|