@tgwf/co2 0.13.2 → 0.13.3
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 +11 -0
- package/dist/cjs/constants/index.js +2 -1
- package/dist/cjs/constants/index.js.map +2 -2
- package/dist/cjs/hosting-api.js +0 -5
- package/dist/cjs/hosting-api.js.map +2 -2
- package/dist/cjs/hosting-json.node.js +0 -2
- package/dist/cjs/hosting-json.node.js.map +2 -2
- package/dist/cjs/hosting-node.js +1 -4
- package/dist/cjs/hosting-node.js.map +2 -2
- package/dist/cjs/hosting.js +1 -3
- package/dist/cjs/hosting.js.map +2 -2
- package/dist/cjs/sustainable-web-design.js +0 -7
- package/dist/cjs/sustainable-web-design.js.map +2 -2
- package/dist/esm/constants/index.js +2 -1
- package/dist/esm/hosting-api.js +0 -2
- package/dist/esm/hosting.js +1 -3
- package/dist/esm/sustainable-web-design.js +0 -4
- package/dist/iife/index.js +16 -16
- package/dist/iife/index.js.map +3 -3
- package/package.json +2 -4
- package/src/constants/index.js +3 -2
- package/src/hosting-api.js +20 -11
- package/src/hosting-json.node.js +36 -3
- package/src/hosting-node.js +27 -8
- package/src/hosting.js +6 -4
- package/src/sustainable-web-design.js +0 -4
package/src/hosting-node.js
CHANGED
|
@@ -10,9 +10,6 @@ This lets us keep the total library small, and dependencies minimal.
|
|
|
10
10
|
|
|
11
11
|
import https from "https";
|
|
12
12
|
|
|
13
|
-
import debugFactory from "debug";
|
|
14
|
-
const log = debugFactory("tgwf:hosting-node");
|
|
15
|
-
|
|
16
13
|
import hostingJSON from "./hosting-json.node.js";
|
|
17
14
|
|
|
18
15
|
/**
|
|
@@ -27,12 +24,11 @@ async function getBody(url) {
|
|
|
27
24
|
// Do async job
|
|
28
25
|
const req = https.get(url, function (res) {
|
|
29
26
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
return reject(
|
|
28
|
+
new Error(
|
|
29
|
+
`Could not get info from: ${url}. Status Code: ${res.statusCode}`
|
|
30
|
+
)
|
|
34
31
|
);
|
|
35
|
-
return reject(new Error(`Status Code: ${res.statusCode}`));
|
|
36
32
|
}
|
|
37
33
|
const data = [];
|
|
38
34
|
|
|
@@ -46,6 +42,13 @@ async function getBody(url) {
|
|
|
46
42
|
});
|
|
47
43
|
}
|
|
48
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Check if a domain is hosted by a green web host.
|
|
47
|
+
* @param {string|array} domain - The domain to check, or an array of domains to be checked.
|
|
48
|
+
* @param {object} db - Optional. A database object to use for lookups.
|
|
49
|
+
* @returns {boolean|array} - A boolean if a string was provided, or an array of booleans if an array of domains was provided.
|
|
50
|
+
*/
|
|
51
|
+
|
|
49
52
|
function check(domain, db) {
|
|
50
53
|
if (db) {
|
|
51
54
|
return hostingJSON.check(domain, db);
|
|
@@ -59,6 +62,11 @@ function check(domain, db) {
|
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Check if a domain is hosted by a green web host by querying the Green Web Foundation API.
|
|
67
|
+
* @param {string} domain - The domain to check.
|
|
68
|
+
* @returns {boolean} - A boolean indicating whether the domain is hosted by a green web host.
|
|
69
|
+
*/
|
|
62
70
|
async function checkAgainstAPI(domain) {
|
|
63
71
|
const res = JSON.parse(
|
|
64
72
|
await getBody(`https://api.thegreenwebfoundation.org/greencheck/${domain}`)
|
|
@@ -66,6 +74,11 @@ async function checkAgainstAPI(domain) {
|
|
|
66
74
|
return res.green;
|
|
67
75
|
}
|
|
68
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Check if an array of domains is hosted by a green web host by querying the Green Web Foundation API.
|
|
79
|
+
* @param {array} domains - An array of domains to check.
|
|
80
|
+
* @returns {array} - An array of domains that are hosted by a green web host.
|
|
81
|
+
*/
|
|
69
82
|
async function checkDomainsAgainstAPI(domains) {
|
|
70
83
|
try {
|
|
71
84
|
const allGreenCheckResults = JSON.parse(
|
|
@@ -81,6 +94,12 @@ async function checkDomainsAgainstAPI(domains) {
|
|
|
81
94
|
}
|
|
82
95
|
}
|
|
83
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Take the result of a pageXray and check the domains in it against the database.
|
|
99
|
+
* @param {object} pageXray - The result of a pageXray.
|
|
100
|
+
* @param {object} db - A database object to use for lookups.
|
|
101
|
+
* @returns {array} - An array indicating whether the domain is hosted by a green web host.
|
|
102
|
+
*/
|
|
84
103
|
async function checkPage(pageXray, db) {
|
|
85
104
|
const domains = Object.keys(pageXray.domains);
|
|
86
105
|
return check(domains, db);
|
package/src/hosting.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import debugFactory from "debug";
|
|
4
|
-
const log = debugFactory("tgwf:hosting");
|
|
5
|
-
|
|
6
3
|
import hostingAPI from "./hosting-api.js";
|
|
7
4
|
|
|
8
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Check if a domain is hosted by a green web host.
|
|
7
|
+
* @param {string|array} domain - The domain to check, or an array of domains to be checked.
|
|
8
|
+
* @returns {boolean|array} - A boolean if a string was provided, or an array of booleans if an array of domains was provided.
|
|
9
|
+
*/
|
|
10
|
+
function check(domain) {
|
|
9
11
|
return hostingAPI.check(domain);
|
|
10
12
|
}
|
|
11
13
|
|
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
* https://sustainablewebdesign.org/calculating-digital-emissions/
|
|
8
8
|
*
|
|
9
9
|
*/
|
|
10
|
-
import debugFactory from "debug";
|
|
11
|
-
const log = debugFactory("tgwf:sustainable-web-design");
|
|
12
10
|
|
|
13
11
|
import {
|
|
14
12
|
fileSize,
|
|
@@ -254,7 +252,6 @@ class SustainableWebDesign {
|
|
|
254
252
|
const energyBycomponent = this.energyPerByteByComponent(bytes);
|
|
255
253
|
const cacheAdjustedSegmentEnergy = {};
|
|
256
254
|
|
|
257
|
-
log({ energyBycomponent });
|
|
258
255
|
const energyValues = Object.values(energyBycomponent);
|
|
259
256
|
|
|
260
257
|
// for this, we want
|
|
@@ -266,7 +263,6 @@ class SustainableWebDesign {
|
|
|
266
263
|
cacheAdjustedSegmentEnergy[`${key} - subsequent`] =
|
|
267
264
|
value * returnView * dataReloadRatio;
|
|
268
265
|
}
|
|
269
|
-
log({ cacheAdjustedSegmentEnergy });
|
|
270
266
|
|
|
271
267
|
return cacheAdjustedSegmentEnergy;
|
|
272
268
|
}
|