@tgwf/co2 0.11.4 → 0.12.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/.esbuild.esm.js +1 -1
- package/.esbuild.node.js +1 -1
- package/README.md +3 -3
- package/dist/cjs/1byte.js +0 -0
- package/dist/cjs/1byte.js.map +2 -2
- package/dist/cjs/co2.js +67 -4
- package/dist/cjs/co2.js.map +2 -2
- package/dist/cjs/constants/file-size.js +0 -0
- package/dist/cjs/constants/file-size.js.map +0 -0
- package/dist/cjs/constants/index.js +23 -1
- package/dist/cjs/constants/index.js.map +2 -2
- package/dist/cjs/data/average-intensities-2021.min.js +0 -0
- package/dist/cjs/data/average-intensities-2021.min.js.map +0 -0
- package/dist/cjs/data/marginal-intensities-2021.min.js +0 -0
- package/dist/cjs/data/marginal-intensities-2021.min.js.map +0 -0
- package/dist/cjs/helpers/index.js +139 -1
- package/dist/cjs/helpers/index.js.map +2 -2
- package/dist/cjs/hosting-api.js +0 -0
- package/dist/cjs/hosting-api.js.map +0 -0
- package/dist/cjs/hosting-json.node.js +0 -0
- package/dist/cjs/hosting-json.node.js.map +0 -0
- package/dist/cjs/hosting-node.js +0 -0
- package/dist/cjs/hosting-node.js.map +0 -0
- package/dist/cjs/hosting.js +0 -0
- package/dist/cjs/hosting.js.map +0 -0
- package/dist/cjs/index-node.js +0 -0
- package/dist/cjs/index-node.js.map +0 -0
- package/dist/cjs/index.js +0 -0
- package/dist/cjs/index.js.map +0 -0
- package/dist/cjs/package.json +0 -0
- package/dist/cjs/sustainable-web-design.js +67 -49
- package/dist/cjs/sustainable-web-design.js.map +2 -2
- package/dist/esm/1byte.js +0 -0
- package/dist/esm/co2.js +70 -4
- package/dist/esm/constants/file-size.js +0 -0
- package/dist/esm/constants/index.js +23 -1
- package/dist/esm/data/average-intensities-2021.min.js +0 -0
- package/dist/esm/data/marginal-intensities-2021.min.js +0 -0
- package/dist/esm/helpers/index.js +144 -1
- package/dist/esm/hosting-api.js +0 -0
- package/dist/esm/hosting.js +0 -0
- package/dist/esm/index.js +0 -0
- package/dist/esm/package.json +0 -0
- package/dist/esm/sustainable-web-design.js +90 -41
- package/dist/iife/index.js +19 -3
- package/dist/iife/index.js.map +3 -3
- package/package.json +1 -1
- package/src/1byte.js +7 -0
- package/src/co2.js +157 -4
- package/src/constants/index.js +38 -1
- package/src/helpers/index.js +173 -1
- package/src/sustainable-web-design.js +113 -72
- package/dist/cjs/1byte.test.js +0 -27
- package/dist/cjs/1byte.test.js.map +0 -7
- package/dist/cjs/co2.test.js +0 -281
- package/dist/cjs/co2.test.js.map +0 -7
- package/dist/cjs/hosting-api.test.js +0 -47
- package/dist/cjs/hosting-api.test.js.map +0 -7
- package/dist/cjs/hosting-database.node.test.js +0 -36
- package/dist/cjs/hosting-database.node.test.js.map +0 -7
- package/dist/cjs/hosting-json.node.test.js +0 -43
- package/dist/cjs/hosting-json.node.test.js.map +0 -7
- package/dist/cjs/hosting.test.js +0 -67
- package/dist/cjs/hosting.test.js.map +0 -7
- package/dist/cjs/sustainable-web-design.test.js +0 -84
- package/dist/cjs/sustainable-web-design.test.js.map +0 -7
- package/dist/esm/1byte.test.js +0 -11
- package/dist/esm/co2.test.js +0 -265
- package/dist/esm/hosting-api.test.js +0 -31
- package/dist/esm/hosting-database.node.test.js +0 -20
- package/dist/esm/hosting-json.node.test.js +0 -27
- package/dist/esm/hosting.test.js +0 -51
- package/dist/esm/sustainable-web-design.test.js +0 -68
|
@@ -1,18 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
2
21
|
import debugFactory from "debug";
|
|
3
22
|
const log = debugFactory("tgwf:sustainable-web-design");
|
|
4
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
fileSize,
|
|
25
|
+
KWH_PER_GB,
|
|
26
|
+
END_USER_DEVICE_ENERGY,
|
|
27
|
+
NETWORK_ENERGY,
|
|
28
|
+
DATACENTER_ENERGY,
|
|
29
|
+
PRODUCTION_ENERGY,
|
|
30
|
+
GLOBAL_GRID_INTENSITY,
|
|
31
|
+
RENEWABLES_GRID_INTENSITY,
|
|
32
|
+
FIRST_TIME_VIEWING_PERCENTAGE,
|
|
33
|
+
RETURNING_VISITOR_PERCENTAGE,
|
|
34
|
+
PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD
|
|
35
|
+
} from "./constants/index.js";
|
|
5
36
|
import { formatNumber } from "./helpers/index.js";
|
|
6
|
-
const KWH_PER_GB = 0.81;
|
|
7
|
-
const END_USER_DEVICE_ENERGY = 0.52;
|
|
8
|
-
const NETWORK_ENERGY = 0.14;
|
|
9
|
-
const DATACENTER_ENERGY = 0.15;
|
|
10
|
-
const PRODUCTION_ENERGY = 0.19;
|
|
11
|
-
const GLOBAL_INTENSITY = 442;
|
|
12
|
-
const RENEWABLES_INTENSITY = 50;
|
|
13
|
-
const FIRST_TIME_VIEWING_PERCENTAGE = 0.75;
|
|
14
|
-
const RETURNING_VISITOR_PERCENTAGE = 0.25;
|
|
15
|
-
const PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD = 0.02;
|
|
16
37
|
class SustainableWebDesign {
|
|
17
38
|
constructor(options) {
|
|
18
39
|
this.options = options;
|
|
@@ -27,53 +48,81 @@ class SustainableWebDesign {
|
|
|
27
48
|
dataCenterEnergy: energyUsage * DATACENTER_ENERGY
|
|
28
49
|
};
|
|
29
50
|
}
|
|
30
|
-
co2byComponent(
|
|
51
|
+
co2byComponent(energyByComponent, carbonIntensity = GLOBAL_GRID_INTENSITY, options = {}) {
|
|
52
|
+
let deviceCarbonIntensity = GLOBAL_GRID_INTENSITY;
|
|
53
|
+
let networkCarbonIntensity = GLOBAL_GRID_INTENSITY;
|
|
54
|
+
let dataCenterCarbonIntensity = GLOBAL_GRID_INTENSITY;
|
|
55
|
+
let globalEmissions = GLOBAL_GRID_INTENSITY;
|
|
56
|
+
if (options == null ? void 0 : options.gridIntensity) {
|
|
57
|
+
const { device, network, dataCenter } = options.gridIntensity;
|
|
58
|
+
if (device == null ? void 0 : device.value) {
|
|
59
|
+
deviceCarbonIntensity = device.value;
|
|
60
|
+
}
|
|
61
|
+
if (network == null ? void 0 : network.value) {
|
|
62
|
+
networkCarbonIntensity = network.value;
|
|
63
|
+
}
|
|
64
|
+
if (dataCenter == null ? void 0 : dataCenter.value) {
|
|
65
|
+
dataCenterCarbonIntensity = dataCenter.value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (carbonIntensity === true) {
|
|
69
|
+
dataCenterCarbonIntensity = RENEWABLES_GRID_INTENSITY;
|
|
70
|
+
}
|
|
31
71
|
const returnCO2ByComponent = {};
|
|
32
|
-
for (const [key, value] of Object.entries(
|
|
72
|
+
for (const [key, value] of Object.entries(energyByComponent)) {
|
|
33
73
|
if (key.startsWith("dataCenterEnergy")) {
|
|
34
|
-
returnCO2ByComponent[key] = value *
|
|
74
|
+
returnCO2ByComponent[key.replace("Energy", "CO2")] = value * dataCenterCarbonIntensity;
|
|
75
|
+
} else if (key.startsWith("consumerDeviceEnergy")) {
|
|
76
|
+
returnCO2ByComponent[key.replace("Energy", "CO2")] = value * deviceCarbonIntensity;
|
|
77
|
+
} else if (key.startsWith("networkEnergy")) {
|
|
78
|
+
returnCO2ByComponent[key.replace("Energy", "CO2")] = value * networkCarbonIntensity;
|
|
35
79
|
} else {
|
|
36
|
-
returnCO2ByComponent[key] = value *
|
|
80
|
+
returnCO2ByComponent[key.replace("Energy", "CO2")] = value * globalEmissions;
|
|
37
81
|
}
|
|
38
82
|
}
|
|
39
83
|
return returnCO2ByComponent;
|
|
40
84
|
}
|
|
41
|
-
perByte(bytes, carbonIntensity =
|
|
42
|
-
const energyBycomponent = this.energyPerByteByComponent(bytes);
|
|
43
|
-
if (
|
|
44
|
-
|
|
85
|
+
perByte(bytes, carbonIntensity = false, segmentResults = false, options = {}) {
|
|
86
|
+
const energyBycomponent = this.energyPerByteByComponent(bytes, options);
|
|
87
|
+
if (typeof carbonIntensity !== "boolean") {
|
|
88
|
+
throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${carbonIntensity}`);
|
|
45
89
|
}
|
|
46
|
-
|
|
47
|
-
carbonIntensity = RENEWABLES_INTENSITY;
|
|
48
|
-
}
|
|
49
|
-
if (typeof carbonIntensity !== "number") {
|
|
50
|
-
throw new Error(`perByte expects a numeric value or boolean for the carbon intensity value. Received: ${carbonIntensity}`);
|
|
51
|
-
}
|
|
52
|
-
const co2ValuesbyComponent = this.co2byComponent(energyBycomponent, carbonIntensity);
|
|
90
|
+
const co2ValuesbyComponent = this.co2byComponent(energyBycomponent, carbonIntensity, options);
|
|
53
91
|
const co2Values = Object.values(co2ValuesbyComponent);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const energyBycomponent = this.energyPerVisitByComponent(bytes);
|
|
58
|
-
if (Boolean(carbonIntensity) === false) {
|
|
59
|
-
carbonIntensity = GLOBAL_INTENSITY;
|
|
60
|
-
}
|
|
61
|
-
if (carbonIntensity === true) {
|
|
62
|
-
carbonIntensity = RENEWABLES_INTENSITY;
|
|
92
|
+
const co2ValuesSum = co2Values.reduce((prevValue, currentValue) => prevValue + currentValue);
|
|
93
|
+
if (segmentResults) {
|
|
94
|
+
return __spreadProps(__spreadValues({}, co2ValuesbyComponent), { total: co2ValuesSum });
|
|
63
95
|
}
|
|
64
|
-
|
|
65
|
-
|
|
96
|
+
return co2ValuesSum;
|
|
97
|
+
}
|
|
98
|
+
perVisit(bytes, carbonIntensity = false, segmentResults = false, options = {}) {
|
|
99
|
+
const energyBycomponent = this.energyPerVisitByComponent(bytes, options);
|
|
100
|
+
if (typeof carbonIntensity !== "boolean") {
|
|
101
|
+
throw new Error(`perVisit expects a boolean for the carbon intensity value. Received: ${carbonIntensity}`);
|
|
66
102
|
}
|
|
67
|
-
const co2ValuesbyComponent = this.co2byComponent(energyBycomponent, carbonIntensity);
|
|
103
|
+
const co2ValuesbyComponent = this.co2byComponent(energyBycomponent, carbonIntensity, options);
|
|
68
104
|
const co2Values = Object.values(co2ValuesbyComponent);
|
|
69
|
-
|
|
105
|
+
const co2ValuesSum = co2Values.reduce((prevValue, currentValue) => prevValue + currentValue);
|
|
106
|
+
if (segmentResults) {
|
|
107
|
+
return __spreadProps(__spreadValues({}, co2ValuesbyComponent), { total: co2ValuesSum });
|
|
108
|
+
}
|
|
109
|
+
return co2ValuesSum;
|
|
70
110
|
}
|
|
71
111
|
energyPerByte(bytes) {
|
|
72
112
|
const energyByComponent = this.energyPerByteByComponent(bytes);
|
|
73
113
|
const energyValues = Object.values(energyByComponent);
|
|
74
114
|
return energyValues.reduce((prevValue, currentValue) => prevValue + currentValue);
|
|
75
115
|
}
|
|
76
|
-
energyPerVisitByComponent(bytes, firstView = FIRST_TIME_VIEWING_PERCENTAGE, returnView = RETURNING_VISITOR_PERCENTAGE, dataReloadRatio = PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD) {
|
|
116
|
+
energyPerVisitByComponent(bytes, options = {}, firstView = FIRST_TIME_VIEWING_PERCENTAGE, returnView = RETURNING_VISITOR_PERCENTAGE, dataReloadRatio = PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD) {
|
|
117
|
+
if (options.dataReloadRatio) {
|
|
118
|
+
dataReloadRatio = options.dataReloadRatio;
|
|
119
|
+
}
|
|
120
|
+
if (options.firstVisitPercentage) {
|
|
121
|
+
firstView = options.firstVisitPercentage;
|
|
122
|
+
}
|
|
123
|
+
if (options.returnVisitPercentage) {
|
|
124
|
+
returnView = options.returnVisitPercentage;
|
|
125
|
+
}
|
|
77
126
|
const energyBycomponent = this.energyPerByteByComponent(bytes);
|
|
78
127
|
const cacheAdjustedSegmentEnergy = {};
|
|
79
128
|
log({ energyBycomponent });
|
|
@@ -101,7 +150,7 @@ class SustainableWebDesign {
|
|
|
101
150
|
}
|
|
102
151
|
return firstVisits + subsequentVisits;
|
|
103
152
|
}
|
|
104
|
-
emissionsPerVisitInGrams(energyPerVisit, carbonintensity =
|
|
153
|
+
emissionsPerVisitInGrams(energyPerVisit, carbonintensity = GLOBAL_GRID_INTENSITY) {
|
|
105
154
|
return formatNumber(energyPerVisit * carbonintensity);
|
|
106
155
|
}
|
|
107
156
|
annualEnergyInKwh(energyPerVisit, monthlyVisitors = 1e3) {
|
package/dist/iife/index.js
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
var co2=(()=>{var
|
|
2
|
-
See https://developers.thegreenwebfoundation.org/co2js/
|
|
3
|
-
|
|
1
|
+
var co2=(()=>{var Re=Object.create;var L=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var ge=Object.getOwnPropertyNames;var _e=Object.getPrototypeOf,Ne=Object.prototype.hasOwnProperty;var V=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ye=(r,e)=>{for(var t in e)L(r,t,{get:e[t],enumerable:!0})},ee=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ge(e))!Ne.call(r,n)&&n!==t&&L(r,n,{get:()=>e[n],enumerable:!(o=Ie(e,n))||o.enumerable});return r};var w=(r,e,t)=>(t=r!=null?Re(_e(r)):{},ee(e||!r||!r.__esModule?L(t,"default",{value:r,enumerable:!0}):t,r)),me=r=>ee(L({},"__esModule",{value:!0}),r);var ne=V((Je,re)=>{var y=1e3,m=y*60,p=m*60,N=p*24,pe=N*7,Te=N*365.25;re.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return he(r);if(t==="number"&&isFinite(r))return e.long?Ae(r):Oe(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function he(r){if(r=String(r),!(r.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(!!e){var t=parseFloat(e[1]),o=(e[2]||"ms").toLowerCase();switch(o){case"years":case"year":case"yrs":case"yr":case"y":return t*Te;case"weeks":case"week":case"w":return t*pe;case"days":case"day":case"d":return t*N;case"hours":case"hour":case"hrs":case"hr":case"h":return t*p;case"minutes":case"minute":case"mins":case"min":case"m":return t*m;case"seconds":case"second":case"secs":case"sec":case"s":return t*y;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function Oe(r){var e=Math.abs(r);return e>=N?Math.round(r/N)+"d":e>=p?Math.round(r/p)+"h":e>=m?Math.round(r/m)+"m":e>=y?Math.round(r/y)+"s":r+"ms"}function Ae(r){var e=Math.abs(r);return e>=N?P(r,e,N,"day"):e>=p?P(r,e,p,"hour"):e>=m?P(r,e,m,"minute"):e>=y?P(r,e,y,"second"):r+" ms"}function P(r,e,t,o){var n=e>=t*1.5;return Math.round(r/t)+" "+o+(n?"s":"")}});var se=V((qe,oe)=>{function Se(r){t.debug=t,t.default=t,t.coerce=f,t.disable=i,t.enable=n,t.enabled=a,t.humanize=ne(),t.destroy=l,Object.keys(r).forEach(s=>{t[s]=r[s]}),t.names=[],t.skips=[],t.formatters={};function e(s){let c=0;for(let d=0;d<s.length;d++)c=(c<<5)-c+s.charCodeAt(d),c|=0;return t.colors[Math.abs(c)%t.colors.length]}t.selectColor=e;function t(s){let c,d=null,b,Q;function I(...R){if(!I.enabled)return;let _=I,G=Number(new Date),Ee=G-(c||G);_.diff=Ee,_.prev=c,_.curr=G,c=G,R[0]=t.coerce(R[0]),typeof R[0]!="string"&&R.unshift("%O");let F=0;R[0]=R[0].replace(/%([a-zA-Z%])/g,(D,fe)=>{if(D==="%%")return"%";F++;let X=t.formatters[fe];if(typeof X=="function"){let Ce=R[F];D=X.call(_,Ce),R.splice(F,1),F--}return D}),t.formatArgs.call(_,R),(_.log||t.log).apply(_,R)}return I.namespace=s,I.useColors=t.useColors(),I.color=t.selectColor(s),I.extend=o,I.destroy=t.destroy,Object.defineProperty(I,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(b!==t.namespaces&&(b=t.namespaces,Q=t.enabled(s)),Q),set:R=>{d=R}}),typeof t.init=="function"&&t.init(I),I}function o(s,c){let d=t(this.namespace+(typeof c>"u"?":":c)+s);return d.log=this.log,d}function n(s){t.save(s),t.namespaces=s,t.names=[],t.skips=[];let c,d=(typeof s=="string"?s:"").split(/[\s,]+/),b=d.length;for(c=0;c<b;c++)!d[c]||(s=d[c].replace(/\*/g,".*?"),s[0]==="-"?t.skips.push(new RegExp("^"+s.slice(1)+"$")):t.names.push(new RegExp("^"+s+"$")))}function i(){let s=[...t.names.map(E),...t.skips.map(E).map(c=>"-"+c)].join(",");return t.enable(""),s}function a(s){if(s[s.length-1]==="*")return!0;let c,d;for(c=0,d=t.skips.length;c<d;c++)if(t.skips[c].test(s))return!1;for(c=0,d=t.names.length;c<d;c++)if(t.names[c].test(s))return!0;return!1}function E(s){return s.toString().substring(2,s.toString().length-2).replace(/\.\*\?$/,"*")}function f(s){return s instanceof Error?s.stack||s.message:s}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.enable(t.load()),t}oe.exports=Se});var B=V((C,v)=>{C.formatArgs=Ge;C.save=Fe;C.load=Le;C.useColors=be;C.storage=Pe();C.destroy=(()=>{let r=!1;return()=>{r||(r=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();C.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function be(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Ge(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+v.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,o=0;r[0].replace(/%[a-zA-Z%]/g,n=>{n!=="%%"&&(t++,n==="%c"&&(o=t))}),r.splice(o,0,e)}C.log=console.debug||console.log||(()=>{});function Fe(r){try{r?C.storage.setItem("debug",r):C.storage.removeItem("debug")}catch{}}function Le(){let r;try{r=C.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function Pe(){try{return localStorage}catch{}}v.exports=se()(C);var{formatters:ve}=v.exports;ve.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var je={};ye(je,{averageIntensity:()=>g,co2:()=>z,default:()=>xe,hosting:()=>J,marginalIntensity:()=>q});var M=4883333333333333e-25;var U=class{constructor(e){this.options=e,this.KWH_PER_BYTE_FOR_NETWORK=M}perByte(e,t){if(e<1)return 0;if(t){let n=e*72e-12*0,i=e*M*475;return n+i}let o=72e-12+M;return e*o*519}};var te=U;var ce=w(B());var Y={GIGABYTE:1e9};var ie=.81,W=.52,K=.14,k=.15,H=.19,u=442,h=50,O=.75,A=.25,S=.02;var T=r=>parseFloat(r.toFixed(2));function x(r){if(typeof r!="object")throw new Error("Options must be an object");let e={};if(r?.gridIntensity){e.gridIntensity={};let{device:t,dataCenter:o,network:n}=r.gridIntensity;t&&(typeof t=="object"?(g.data[t.country?.toUpperCase()]||(console.warn(`"${t.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
2
|
+
See https://developers.thegreenwebfoundation.org/co2js/data/ for more information.
|
|
3
|
+
Falling back to global average grid intensity.`),e.gridIntensity.device={value:u}),e.gridIntensity.device={country:t.country,value:parseFloat(g.data[t.country?.toUpperCase()])}):typeof t=="number"?e.gridIntensity.device={value:t}:(e.gridIntensity.device={value:u},console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof t}.
|
|
4
|
+
Falling back to global average grid intensity.`))),o&&(typeof o=="object"?(g.data[o.country?.toUpperCase()]||(console.warn(`"${o.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
5
|
+
See https://developers.thegreenwebfoundation.org/co2js/data/ for more information.
|
|
6
|
+
Falling back to global average grid intensity.`),e.gridIntensity.dataCenter={value:u}),e.gridIntensity.dataCenter={country:o.country,value:parseFloat(g.data[o.country?.toUpperCase()])}):typeof o=="number"?e.gridIntensity.dataCenter={value:o}:(e.gridIntensity.dataCenter={value:u},console.warn(`The data center grid intensity must be a number or an object. You passed in a ${typeof o}.
|
|
7
|
+
Falling back to global average grid intensity.`))),n&&(typeof n=="object"?(g.data[n.country?.toUpperCase()]||(console.warn(`"${n.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
8
|
+
See https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity.
|
|
9
|
+
Falling back to global average grid intensity.`),e.gridIntensity.network={value:u}),e.gridIntensity.network={country:n.country,value:parseFloat(g.data[n.country?.toUpperCase()])}):typeof n=="number"?e.gridIntensity.network={value:n}:(e.gridIntensity.network={value:u},console.warn(`The network grid intensity must be a number or an object. You passed in a ${typeof n}.
|
|
10
|
+
Falling back to global average grid intensity.`)))}return r?.dataReloadRatio&&(typeof r.dataReloadRatio=="number"?r.dataReloadRatio>=0&&r.dataReloadRatio<=1?e.dataReloadRatio=r.dataReloadRatio:(e.dataReloadRatio=S,console.warn(`The dataReloadRatio option must be a number between 0 and 1. You passed in ${r.dataReloadRatio}.
|
|
11
|
+
Falling back to default value.`)):(e.dataReloadRatio=S,console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof r.dataReloadRatio}.
|
|
12
|
+
Falling back to default value.`))),r?.firstVisitPercentage&&(typeof r.firstVisitPercentage=="number"?r.firstVisitPercentage>=0&&r.firstVisitPercentage<=1?e.firstVisitPercentage=r.firstVisitPercentage:(e.firstVisitPercentage=O,console.warn(`The firstVisitPercentage option must be a number between 0 and 1. You passed in ${r.firstVisitPercentage}.
|
|
13
|
+
Falling back to default value.`)):(e.firstVisitPercentage=O,console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof r.firstVisitPercentage}.
|
|
14
|
+
Falling back to default value.`))),r?.returnVisitPercentage&&(typeof r.returnVisitPercentage=="number"?r.returnVisitPercentage>=0&&r.returnVisitPercentage<=1?e.returnVisitPercentage=r.returnVisitPercentage:(e.returnVisitPercentage=A,console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${r.returnVisitPercentage}.
|
|
15
|
+
Falling back to default value.`)):(e.returnVisitPercentage=A,console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof r.returnVisitPercentage}.
|
|
16
|
+
Falling back to default value.`))),e}var ae=(0,ce.default)("tgwf:sustainable-web-design"),j=class{constructor(e){this.options=e}energyPerByteByComponent(e){let o=e/Y.GIGABYTE*ie;return{consumerDeviceEnergy:o*W,networkEnergy:o*K,productionEnergy:o*H,dataCenterEnergy:o*k}}co2byComponent(e,t=u,o={}){let n=u,i=u,a=u,E=u;if(o?.gridIntensity){let{device:l,network:s,dataCenter:c}=o.gridIntensity;l?.value&&(n=l.value),s?.value&&(i=s.value),c?.value&&(a=c.value)}t===!0&&(a=h);let f={};for(let[l,s]of Object.entries(e))l.startsWith("dataCenterEnergy")?f[l.replace("Energy","CO2")]=s*a:l.startsWith("consumerDeviceEnergy")?f[l.replace("Energy","CO2")]=s*n:l.startsWith("networkEnergy")?f[l.replace("Energy","CO2")]=s*i:f[l.replace("Energy","CO2")]=s*E;return f}perByte(e,t=!1,o=!1,n={}){let i=this.energyPerByteByComponent(e,n);if(typeof t!="boolean")throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${t}`);let a=this.co2byComponent(i,t,n),f=Object.values(a).reduce((l,s)=>l+s);return o?{...a,total:f}:f}perVisit(e,t=!1,o=!1,n={}){let i=this.energyPerVisitByComponent(e,n);if(typeof t!="boolean")throw new Error(`perVisit expects a boolean for the carbon intensity value. Received: ${t}`);let a=this.co2byComponent(i,t,n),f=Object.values(a).reduce((l,s)=>l+s);return o?{...a,total:f}:f}energyPerByte(e){let t=this.energyPerByteByComponent(e);return Object.values(t).reduce((n,i)=>n+i)}energyPerVisitByComponent(e,t={},o=O,n=A,i=S){t.dataReloadRatio&&(i=t.dataReloadRatio),t.firstVisitPercentage&&(o=t.firstVisitPercentage),t.returnVisitPercentage&&(n=t.returnVisitPercentage);let a=this.energyPerByteByComponent(e),E={};ae({energyBycomponent:a});let f=Object.values(a);for(let[l,s]of Object.entries(a))E[`${l} - first`]=s*o,E[`${l} - subsequent`]=s*n*i;return ae({cacheAdjustedSegmentEnergy:E}),E}energyPerVisit(e){let t=0,o=0,n=Object.entries(this.energyPerVisitByComponent(e));for(let[i,a]of n)i.indexOf("first")>0&&(t+=a);for(let[i,a]of n)i.indexOf("subsequent")>0&&(o+=a);return t+o}emissionsPerVisitInGrams(e,t=u){return T(e*t)}annualEnergyInKwh(e,t=1e3){return e*t*12}annualEmissionsInGrams(e,t=1e3){return e*t*12}annualSegmentEnergy(e){return{consumerDeviceEnergy:T(e*W),networkEnergy:T(e*K),dataCenterEnergy:T(e*k),productionEnergy:T(e*H)}}};var $=j;var Z=class{constructor(e){if(this.model=new $,e?.model==="1byte")this.model=new te;else if(e?.model==="swd")this.model=new $;else if(e?.model)throw new Error(`"${e.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model.
|
|
17
|
+
See https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);e?.results==="segment"?this.model.results={segment:!0}:this.model.results={segment:!1}}perByte(e,t=!1){return this.model.perByte(e,t,this.model.results.segment)}perVisit(e,t=!1){if(this.model?.perVisit)return this.model.perVisit(e,t,this.model.results.segment);throw new Error(`The perVisit() method is not supported in the model you are using. Try using perByte() instead.
|
|
18
|
+
See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`)}perByteTrace(e,t=!1,o={}){let n={};return o&&(n=x(o)),{co2:this.model.perByte(e,t,this.model.results.segment,n),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:n?.gridIntensity?.network?.value||u,dataCenter:t?h:n?.gridIntensity?.dataCenter?.value||u,production:u,device:n?.gridIntensity?.device?.value||u}}}}perVisitTrace(e,t=!1,o={}){if(this.model?.perVisit){let n={};return o&&(n=x(o)),{co2:this.model.perVisit(e,t,this.model.results.segment,n),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:n?.gridIntensity?.network?.value||u,dataCenter:t?h:n?.gridIntensity?.dataCenter?.value||u,production:u,device:n?.gridIntensity?.device?.value||u},dataReloadRatio:n?.dataReloadRatio||.02,firstVisitPercentage:n?.firstVisitPercentage||.75,returnVisitPercentage:n?.returnVisitPercentage||.25}}}else throw new Error(`The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead.
|
|
19
|
+
See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`)}perDomain(e,t){let o=[];for(let n of Object.keys(e.domains)){let i;t&&t.indexOf(n)>-1?i=this.perByte(e.domains[n].transferSize,!0):i=this.perByte(e.domains[n].transferSize),o.push({domain:n,co2:i,transferSize:e.domains[n].transferSize})}return o.sort((n,i)=>i.co2-n.co2),o}perPage(e,t){let o=this.perDomain(e,t),n=0;for(let i of o)n+=i.co2;return n}perContentType(e,t){let o={};for(let i of e.assets){let a=new URL(i.url).domain,E=i.transferSize,f=this.perByte(E,t&&t.indexOf(a)>-1),l=i.type;o[l]||(o[l]={co2:0,transferSize:0}),o[l].co2+=f,o[l].transferSize+=E}let n=[];for(let i of Object.keys(o))n.push({type:i,co2:o[i].co2,transferSize:o[i].transferSize});return n.sort((i,a)=>a.co2-i.co2),n}dirtiestResources(e,t){let o=[];for(let n of e.assets){let i=new URL(n.url).domain,a=n.transferSize,E=this.perByte(a,t&&t.indexOf(i)>-1);o.push({url:n.url,co2:E,transferSize:a})}return o.sort((n,i)=>i.co2-n.co2),o.slice(0,o.length>10?10:o.length)}perParty(e,t){let o=0,n=0,i=e.firstPartyRegEx;for(let a of Object.keys(e.domains))a.match(i)?o+=this.perByte(e.domains[a].transferSize,t&&t.indexOf(a)>-1):n+=this.perByte(e.domains[a].transferSize,t&&t.indexOf(a)>-1);return{firstParty:o,thirdParty:n}}};var z=Z;var de=w(B());var le=w(B()),Rt=(0,le.default)("tgwf:hostingAPI");function Be(r){return typeof r=="string"?De(r):Ve(r)}async function De(r){return(await(await fetch(`https://api.thegreenwebfoundation.org/greencheck/${r}`)).json()).green}async function Ve(r){try{let e="https://api.thegreenwebfoundation.org/v2/greencheckmulti",t=JSON.stringify(r),n=await(await fetch(`${e}/${t}`)).json();return we(n)}catch{return[]}}function we(r){return Object.entries(r).filter(([o,n])=>n.green).map(([o,n])=>n.url)}var ue={check:Be};var gt=(0,de.default)("tgwf:hosting");function Me(r,e){return ue.check(r)}var J={check:Me};var Ue={AFRICA:"489.26",ARG:"365.292",ARM:"206.522",ASIA:"543.57",AUS:"526.876",AUT:"145.083",AZE:"536.585",BGD:"559.606",BLR:"472.727",BEL:"156.063",BOL:"311.475",BIH:"470.982",BRA:"144.677",BGR:"364.136",BDI:"275.862",CAN:"123.859",CHL:"395.565",CHN:"549.288",CRI:"30.903",HRV:"212.161",CYP:"601.19",CZE:"401.272",DNK:"240.419",ECU:"132.964",EGY:"470.879",SLV:"180.87",EST:"488.529",EU:"261.43",EUROPE:"277.64",FIN:"152.651",FRA:"67.781",G20:"445.9",G7:"338.04",GEO:"105.685",DEU:"363.982",GRC:"363.388",HUN:"236.271",IND:"632.656",IRL:"361.274",ITA:"340.937",JPN:"460.647",KAZ:"656.097",KEN:"104.0","LATIN AMERICA AND CARIBBEAN":"261.51",LVA:"226.351",LTU:"247.475",LUX:"183.824",MLT:"452.055",MEX:"391.582",MDA:"642.512",MNG:"725.26",MNE:"335.958",NLD:"386.189","NORTH AMERICA":"345.38",MKD:"444.191",NOR:"26.131",OCEANIA:"479.98",OECD:"338.24",PAK:"363.065",PER:"241.492",PHL:"579.689",POL:"657.138",PRT:"222.632",ROU:"255.718",RUS:"355.431",SAU:"568.967",SEN:"540.098",SRB:"549.083",SGP:"488.21",SVK:"173.854",SVN:"241.956",ZAF:"706.991",KOR:"442.389",ESP:"193.737",SWE:"43.9",CHE:"58.952",TWN:"565.629",TJK:"72.823",THA:"503.034",TUN:"470.848",TUR:"432.293",UKR:"240.28",GBR:"268.255",USA:"378.625",VNM:"491.192",WORLD:"442.37"},Ye="average",We="2021";var g={data:Ue,type:Ye,year:We};var Ke={AFG:"414",ALB:"0",DZA:"528",ASM:"753",AND:"188",AGO:"1476",AIA:"753",ATG:"753",ARG:"478",ARM:"390",ABW:"753",AUS:"808",AUT:"242",AZE:"534","AZORES (PORTUGAL)":"753",BHS:"753",BHR:"726",BGD:"528",BRB:"749",BLR:"400",BEL:"252",BLZ:"403",BEN:"745",BMU:"753",BTN:"0",BOL:"604",BES:"753",BIH:"1197",BWA:"1486",BRA:"284",VGB:"753",BRN:"681",BGR:"911",BFA:"753",BDI:"414",KHM:"1046",CMR:"659",CAN:"372",CYM:"753",CPV:"753",CAF:"188",TCD:"753","CHANNEL ISLANDS (U.K)":"753",CHL:"657",CHN:"899",COL:"410",COM:"753",COD:"0",COG:"659",COK:"753",CRI:"108",CIV:"466",HRV:"294",CUB:"559",CUW:"876",CYP:"751",CZE:"902",DNK:"362",DJI:"753",DMA:"753",DOM:"601",ECU:"560",EGY:"554",SLV:"547",GNQ:"632",ERI:"915",EST:"1057",SWZ:"0",ETH:"0",FLK:"753",FRO:"753",FJI:"640",FIN:"267",FRA:"158",GUF:"423",PYF:"753",GAB:"946",GMB:"753",GEO:"289",DEU:"650",GHA:"495",GIB:"779",GRC:"507",GRL:"264",GRD:"753",GLP:"753",GUM:"753",GTM:"798",GIN:"753",GNB:"753",GUY:"847",HTI:"1048",HND:"662",HUN:"296",ISL:"0",IND:"951",IDN:"783",IRN:"592",IRQ:"1080",IRL:"380",IMN:"436",ISR:"394",ITA:"414",JAM:"711",JPN:"471",JOR:"529",KAZ:"797",KEN:"574",KIR:"753",PRK:"754",KOR:"555",XKX:"1145",KWT:"675",KGZ:"217",LAO:"1069",LVA:"240",LBN:"794",LSO:"0",LBR:"677",LBY:"668",LIE:"151",LTU:"211",LUX:"220",MDG:"876","MADEIRA (PORTUGAL)":"663",MWI:"489",MYS:"551",MDV:"753",MLI:"1076",MLT:"520",MHL:"753",MTQ:"753",MRT:"753",MUS:"700",MYT:"753",MEX:"531",FSM:"753",MDA:"541",MCO:"158",MNG:"1366",MNE:"899",MSR:"753",MAR:"729",MOZ:"234",MMR:"719",NAM:"355",NRU:"753",NPL:"0",NLD:"326",NCL:"779",NZL:"246",NIC:"675",NER:"772",NGA:"526",NIU:"753",MKD:"851",MNP:"753",NOR:"47",OMN:"479",PAK:"592",PLW:"753",PSE:"719",PAN:"477",PNG:"597",PRY:"0",PER:"473",PHL:"672",POL:"828",PRT:"389",PRI:"596",QAT:"503",REU:"772",ROU:"489",RUS:"476",RWA:"712",SHN:"753",KNA:"753",LCA:"753",MAF:"753",SPM:"753",VCT:"753",WSM:"753",SMR:"414",STP:"753",SAU:"592",SEN:"870",SRB:"1086",SYC:"753",SLE:"489",SGP:"379",SXM:"753",SVK:"332",SVN:"620",SLB:"753",SOM:"753",ZAF:"1070",SSD:"890",ESP:"402",LKA:"731",SDN:"736",SUR:"1029",SWE:"68",CHE:"48",SYR:"713",TWN:"484",TJK:"255",TZA:"531",THA:"450",TLS:"753",TGO:"859",TON:"753",TTO:"559",TUN:"468",TUR:"376",TKM:"927",TCA:"753",TUV:"753",UGA:"279",UKR:"768",ARE:"556",GBR:"380",USA:"416",URY:"174",UZB:"612",VUT:"753",VEN:"711",VNM:"560",VIR:"650",YEM:"807",ZMB:"416",ZWE:"1575","MEMO: EU 27":"409"},ke="marginal",He="2021";var q={data:Ke,type:ke,year:He};var xe={co2:z,hosting:J,averageIntensity:g,marginalIntensity:q};return me(je);})();
|
|
4
20
|
//# sourceMappingURL=index.js.map
|