@tgwf/co2 0.12.1 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/output/average-intensities-2021.js +3 -90
- package/data/output/average-intensities-2021.json +1 -776
- package/dist/cjs/1byte.js.map +1 -1
- package/dist/cjs/co2.js +44 -13
- package/dist/cjs/co2.js.map +2 -2
- package/dist/cjs/constants/index.js +4 -1
- package/dist/cjs/constants/index.js.map +2 -2
- package/dist/cjs/data/average-intensities-2021.min.js +1 -1
- package/dist/cjs/data/average-intensities-2021.min.js.map +2 -2
- package/dist/cjs/helpers/index.js +57 -27
- package/dist/cjs/helpers/index.js.map +1 -1
- package/dist/cjs/hosting-api.js +7 -2
- package/dist/cjs/hosting-api.js.map +2 -2
- package/dist/cjs/hosting-json.node.js +4 -1
- package/dist/cjs/hosting-json.node.js.map +2 -2
- package/dist/cjs/hosting-node.js +19 -4
- package/dist/cjs/hosting-node.js.map +2 -2
- package/dist/cjs/hosting.js +4 -1
- package/dist/cjs/hosting.js.map +2 -2
- package/dist/cjs/index-node.js +4 -1
- package/dist/cjs/index-node.js.map +2 -2
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/sustainable-web-design.js +32 -9
- package/dist/cjs/sustainable-web-design.js.map +2 -2
- package/dist/esm/co2.js +40 -13
- package/dist/esm/data/average-intensities-2021.min.js +1 -1
- package/dist/esm/helpers/index.js +57 -27
- package/dist/esm/hosting-api.js +3 -2
- package/dist/esm/hosting.js +0 -1
- package/dist/esm/sustainable-web-design.js +28 -9
- package/dist/iife/index.js +15 -15
- package/dist/iife/index.js.map +3 -3
- package/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/data/average-intensities-2021.min.js +1 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -85,11 +84,19 @@ class SustainableWebDesign {
|
|
|
85
84
|
perByte(bytes, carbonIntensity = false, segmentResults = false, options = {}) {
|
|
86
85
|
const energyBycomponent = this.energyPerByteByComponent(bytes, options);
|
|
87
86
|
if (typeof carbonIntensity !== "boolean") {
|
|
88
|
-
throw new Error(
|
|
87
|
+
throw new Error(
|
|
88
|
+
`perByte expects a boolean for the carbon intensity value. Received: ${carbonIntensity}`
|
|
89
|
+
);
|
|
89
90
|
}
|
|
90
|
-
const co2ValuesbyComponent = this.co2byComponent(
|
|
91
|
+
const co2ValuesbyComponent = this.co2byComponent(
|
|
92
|
+
energyBycomponent,
|
|
93
|
+
carbonIntensity,
|
|
94
|
+
options
|
|
95
|
+
);
|
|
91
96
|
const co2Values = Object.values(co2ValuesbyComponent);
|
|
92
|
-
const co2ValuesSum = co2Values.reduce(
|
|
97
|
+
const co2ValuesSum = co2Values.reduce(
|
|
98
|
+
(prevValue, currentValue) => prevValue + currentValue
|
|
99
|
+
);
|
|
93
100
|
if (segmentResults) {
|
|
94
101
|
return __spreadProps(__spreadValues({}, co2ValuesbyComponent), { total: co2ValuesSum });
|
|
95
102
|
}
|
|
@@ -98,11 +105,19 @@ class SustainableWebDesign {
|
|
|
98
105
|
perVisit(bytes, carbonIntensity = false, segmentResults = false, options = {}) {
|
|
99
106
|
const energyBycomponent = this.energyPerVisitByComponent(bytes, options);
|
|
100
107
|
if (typeof carbonIntensity !== "boolean") {
|
|
101
|
-
throw new Error(
|
|
108
|
+
throw new Error(
|
|
109
|
+
`perVisit expects a boolean for the carbon intensity value. Received: ${carbonIntensity}`
|
|
110
|
+
);
|
|
102
111
|
}
|
|
103
|
-
const co2ValuesbyComponent = this.co2byComponent(
|
|
112
|
+
const co2ValuesbyComponent = this.co2byComponent(
|
|
113
|
+
energyBycomponent,
|
|
114
|
+
carbonIntensity,
|
|
115
|
+
options
|
|
116
|
+
);
|
|
104
117
|
const co2Values = Object.values(co2ValuesbyComponent);
|
|
105
|
-
const co2ValuesSum = co2Values.reduce(
|
|
118
|
+
const co2ValuesSum = co2Values.reduce(
|
|
119
|
+
(prevValue, currentValue) => prevValue + currentValue
|
|
120
|
+
);
|
|
106
121
|
if (segmentResults) {
|
|
107
122
|
return __spreadProps(__spreadValues({}, co2ValuesbyComponent), { total: co2ValuesSum });
|
|
108
123
|
}
|
|
@@ -111,7 +126,9 @@ class SustainableWebDesign {
|
|
|
111
126
|
energyPerByte(bytes) {
|
|
112
127
|
const energyByComponent = this.energyPerByteByComponent(bytes);
|
|
113
128
|
const energyValues = Object.values(energyByComponent);
|
|
114
|
-
return energyValues.reduce(
|
|
129
|
+
return energyValues.reduce(
|
|
130
|
+
(prevValue, currentValue) => prevValue + currentValue
|
|
131
|
+
);
|
|
115
132
|
}
|
|
116
133
|
energyPerVisitByComponent(bytes, options = {}, firstView = FIRST_TIME_VIEWING_PERCENTAGE, returnView = RETURNING_VISITOR_PERCENTAGE, dataReloadRatio = PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD) {
|
|
117
134
|
if (options.dataReloadRatio) {
|
|
@@ -137,7 +154,9 @@ class SustainableWebDesign {
|
|
|
137
154
|
energyPerVisit(bytes) {
|
|
138
155
|
let firstVisits = 0;
|
|
139
156
|
let subsequentVisits = 0;
|
|
140
|
-
const energyBycomponent = Object.entries(
|
|
157
|
+
const energyBycomponent = Object.entries(
|
|
158
|
+
this.energyPerVisitByComponent(bytes)
|
|
159
|
+
);
|
|
141
160
|
for (const [key, val] of energyBycomponent) {
|
|
142
161
|
if (key.indexOf("first") > 0) {
|
|
143
162
|
firstVisits += val;
|
package/dist/iife/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
var co2=(()=>{var Ee=Object.create;var
|
|
1
|
+
var co2=(()=>{var Ee=Object.create;var G=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var me=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty;var L=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Ne=(r,e)=>{for(var t in e)G(r,t,{get:e[t],enumerable:!0})},ee=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ye(e))!pe.call(r,n)&&n!==t&&G(r,n,{get:()=>e[n],enumerable:!(o=Re(e,n))||o.enumerable});return r};var D=(r,e,t)=>(t=r!=null?Ee(me(r)):{},ee(e||!r||!r.__esModule?G(t,"default",{value:r,enumerable:!0}):t,r)),he=r=>ee(G({},"__esModule",{value:!0}),r);var ne=L((Je,re)=>{var N=1e3,h=N*60,I=h*60,p=I*24,Ie=p*7,Ae=p*365.25;re.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return Te(r);if(t==="number"&&isFinite(r))return e.long?Oe(r):be(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function Te(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*Ae;case"weeks":case"week":case"w":return t*Ie;case"days":case"day":case"d":return t*p;case"hours":case"hour":case"hrs":case"hr":case"h":return t*I;case"minutes":case"minute":case"mins":case"min":case"m":return t*h;case"seconds":case"second":case"secs":case"sec":case"s":return t*N;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function be(r){var e=Math.abs(r);return e>=p?Math.round(r/p)+"d":e>=I?Math.round(r/I)+"h":e>=h?Math.round(r/h)+"m":e>=N?Math.round(r/N)+"s":r+"ms"}function Oe(r){var e=Math.abs(r);return e>=p?_(r,e,p,"day"):e>=I?_(r,e,I,"hour"):e>=h?_(r,e,h,"minute"):e>=N?_(r,e,N,"second"):r+" ms"}function _(r,e,t,o){var n=e>=t*1.5;return Math.round(r/t)+" "+o+(n?"s":"")}});var se=L((Qe,oe)=>{function Se(r){t.debug=t,t.default=t,t.coerce=C,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,F,q;function R(...E){if(!R.enabled)return;let m=R,B=Number(new Date),fe=B-(c||B);m.diff=fe,m.prev=c,m.curr=B,c=B,E[0]=t.coerce(E[0]),typeof E[0]!="string"&&E.unshift("%O");let P=0;E[0]=E[0].replace(/%([a-zA-Z%])/g,(M,Ce)=>{if(M==="%%")return"%";P++;let X=t.formatters[Ce];if(typeof X=="function"){let ge=E[P];M=X.call(m,ge),E.splice(P,1),P--}return M}),t.formatArgs.call(m,E),(m.log||t.log).apply(m,E)}return R.namespace=s,R.useColors=t.useColors(),R.color=t.selectColor(s),R.extend=o,R.destroy=t.destroy,Object.defineProperty(R,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(F!==t.namespaces&&(F=t.namespaces,q=t.enabled(s)),q),set:E=>{d=E}}),typeof t.init=="function"&&t.init(R),R}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,]+/),F=d.length;for(c=0;c<F;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(f),...t.skips.map(f).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 f(s){return s.toString().substring(2,s.toString().length-2).replace(/\.\*\?$/,"*")}function C(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 w=L((g,v)=>{g.formatArgs=Be;g.save=Pe;g.load=Ge;g.useColors=Fe;g.storage=_e();g.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`."))}})();g.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 Fe(){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 Be(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)}g.log=console.debug||console.log||(()=>{});function Pe(r){try{r?g.storage.setItem("debug",r):g.storage.removeItem("debug")}catch{}}function Ge(){let r;try{r=g.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function _e(){try{return localStorage}catch{}}v.exports=se()(g);var{formatters:ve}=v.exports;ve.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var je={};Ne(je,{averageIntensity:()=>y,co2:()=>z,default:()=>xe,hosting:()=>J,marginalIntensity:()=>Q});var V=4883333333333333e-25;var U=class{constructor(e){this.options=e,this.KWH_PER_BYTE_FOR_NETWORK=V}perByte(e,t){if(e<1)return 0;if(t){let n=e*72e-12*0,i=e*V*475;return n+i}let o=72e-12+V;return e*o*519}};var te=U;var ce=D(w());var K={GIGABYTE:1e9};var ie=.81,W=.52,Y=.14,k=.15,H=.19,u=442,T=50,b=.75,O=.25,S=.02;var A=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"?(y.data[t.country?.toUpperCase()]||(console.warn(`"${t.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
2
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(
|
|
4
|
-
Falling back to global average grid intensity.`))),o&&(typeof o=="object"?(
|
|
3
|
+
Falling back to global average grid intensity.`),e.gridIntensity.device={value:u}),e.gridIntensity.device={country:t.country,value:parseFloat(y.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"?(y.data[o.country?.toUpperCase()]||(console.warn(`"${o.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
5
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(
|
|
7
|
-
Falling back to global average grid intensity.`))),n&&(typeof n=="object"?(
|
|
6
|
+
Falling back to global average grid intensity.`),e.gridIntensity.dataCenter={value:u}),e.gridIntensity.dataCenter={country:o.country,value:parseFloat(y.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"?(y.data[n.country?.toUpperCase()]||(console.warn(`"${n.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
8
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(
|
|
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=
|
|
11
|
-
Falling back to default value.`)):(e.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=
|
|
13
|
-
Falling back to default value.`)):(e.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=
|
|
15
|
-
Falling back to default value.`)):(e.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/
|
|
9
|
+
Falling back to global average grid intensity.`),e.gridIntensity.network={value:u}),e.gridIntensity.network={country:n.country,value:parseFloat(y.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=b,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=b,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=O,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=O,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/K.GIGABYTE*ie;return{consumerDeviceEnergy:o*W,networkEnergy:o*Y,productionEnergy:o*H,dataCenterEnergy:o*k}}co2byComponent(e,t=u,o={}){let n=u,i=u,a=u,f=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=T);let C={};for(let[l,s]of Object.entries(e))l.startsWith("dataCenterEnergy")?C[l.replace("Energy","CO2")]=s*a:l.startsWith("consumerDeviceEnergy")?C[l.replace("Energy","CO2")]=s*n:l.startsWith("networkEnergy")?C[l.replace("Energy","CO2")]=s*i:C[l.replace("Energy","CO2")]=s*f;return C}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),C=Object.values(a).reduce((l,s)=>l+s);return o?{...a,total:C}:C}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),C=Object.values(a).reduce((l,s)=>l+s);return o?{...a,total:C}:C}energyPerByte(e){let t=this.energyPerByteByComponent(e);return Object.values(t).reduce((n,i)=>n+i)}energyPerVisitByComponent(e,t={},o=b,n=O,i=S){t.dataReloadRatio&&(i=t.dataReloadRatio),t.firstVisitPercentage&&(o=t.firstVisitPercentage),t.returnVisitPercentage&&(n=t.returnVisitPercentage);let a=this.energyPerByteByComponent(e),f={};ae({energyBycomponent:a});let C=Object.values(a);for(let[l,s]of Object.entries(a))f[`${l} - first`]=s*o,f[`${l} - subsequent`]=s*n*i;return ae({cacheAdjustedSegmentEnergy:f}),f}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 A(e*t)}annualEnergyInKwh(e,t=1e3){return e*t*12}annualEmissionsInGrams(e,t=1e3){return e*t*12}annualSegmentEnergy(e){return{consumerDeviceEnergy:A(e*W),networkEnergy:A(e*Y),dataCenterEnergy:A(e*k),productionEnergy:A(e*H)}}};var Z=j;var $=class{constructor(e){if(this.model=new Z,e?.model==="1byte")this.model=new te;else if(e?.model==="swd")this.model=new Z;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
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=
|
|
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,f=i.transferSize,C=this.perByte(f,t&&t.indexOf(a)>-1),l=i.type;o[l]||(o[l]={co2:0,transferSize:0}),o[l].co2+=C,o[l].transferSize+=f}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,f=this.perByte(a,t&&t.indexOf(i)>-1);o.push({url:n.url,co2:f,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
|
|
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?T: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?T: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,f=i.transferSize,C=this.perByte(f,t&&t.indexOf(a)>-1),l=i.type;o[l]||(o[l]={co2:0,transferSize:0}),o[l].co2+=C,o[l].transferSize+=f}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,f=this.perByte(a,t&&t.indexOf(i)>-1);o.push({url:n.url,co2:f,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=$;var de=D(w());var le=D(w()),ft=(0,le.default)("tgwf:hostingAPI");function we(r){return typeof r=="string"?Me(r):Le(r)}async function Me(r){return(await(await fetch(`https://api.thegreenwebfoundation.org/greencheck/${r}`)).json()).green}async function Le(r){try{let e="https://api.thegreenwebfoundation.org/v2/greencheckmulti",t=JSON.stringify(r),n=await(await fetch(`${e}/${t}`)).json();return De(n)}catch{return[]}}function De(r){return Object.entries(r).filter(([o,n])=>n.green).map(([o,n])=>n.url)}var ue={check:we};var gt=(0,de.default)("tgwf:hosting");function Ve(r,e){return ue.check(r)}var J={check:Ve};var Ue={AFG:"120.48",AFRICA:"483.89",DZA:"488.39",ASM:"687.5",AGO:"168.59",ATG:"657.14",ARG:"357.79",ARM:"222.68",ABW:"591.4",ASIA:"543.26",AUS:"531.25",AUT:"147.57",AZE:"532.9",BHS:"698.11",BHR:"489.92",BGD:"560.51",BRB:"644.86",BLR:"415.77",BEL:"156.92",BLZ:"484.38",BEN:"666.67",BMU:"",BTN:"24.44",BOL:"306.89",BIH:"489.07",BWA:"794.52",BRA:"158.59",BRN:"658.85",BGR:"354.33",BFA:"611.43",BDI:"250",CPV:"600",KHM:"399.31",CMR:"278.26",CAN:"128.46",CYM:"684.93",CAF:"0",TCD:"677.42",CHL:"416.88",CHN:"544.36",COL:"181.68",COM:"714.29",COD:"25.36",COG:"398.01",COK:"400",CRI:"33.05",CIV:"390.71",HRV:"210.98",CUB:"574.68",CYP:"599.61",CZE:"405.59",DNK:"221.42",DJI:"666.67",DMA:"529.41",DOM:"540.39",ECU:"136.05",EGY:"464.43",SLV:"185.98",GNQ:"492.96",ERI:"688.89",EST:"481.22",SWZ:"189.19",ETH:"25.19",EU:"261.91",EUROPE:"288.13",FLK:"500",FRO:"428.57",FJI:"292.04",FIN:"146.21",FRA:"67.39",GUF:"",PYF:"471.43",G20:"446.08",G7:"340.97",GAB:"397.38",GMB:"700",GEO:"111.55",DEU:"365.98",GHA:"362.94",GIB:"",GRC:"353.34",GRL:"133.33",GRD:"714.29",GLP:"",GUM:"670.33",GTM:"313.02",GIN:"208.63",GNB:"750",GUY:"634.15",HTI:"606.06",HND:"374.27",HKG:"684.82",HUN:"233.04",IND:"637.18",IDN:"623.28",IRN:"492.68",IRQ:"500.21",IRL:"363.61",ISR:"550.49",ITA:"340.79",JAM:"524.14",JPN:"478.55",JOR:"399.91",KAZ:"656.1",KEN:"87.07",KIR:"666.67",PRK:"157.79",KWT:"489.61",KGZ:"104.35",LAO:"242.18","LATIN AMERICA AND CARIBBEAN":"261.4",LVA:"223.93",LBN:"545.94",LSO:"20",LBR:"304.35",LBY:"496.57",LTU:"244.6",LUX:"186.99",MAC:"491.53",MDG:"483.25",MWI:"133.8",MYS:"548.61",MDV:"651.52",MLI:"466.08",MLT:"451.61",MTQ:"",MRT:"526.6",MUS:"611.11",MEX:"399.85",MDA:"645.65",MNG:"741.57",MNE:"335.96",MSR:"1000",MAR:"610.41",MOZ:"125.06",MMR:"348.84",NAM:"63.69",NRU:"750",NPL:"24.51",NLD:"388.62",NCL:"610.12",NZL:"133.35",NIC:"354.21",NER:"622.22",NGA:"377.19",NIU:"","NORTH AMERICA":"346.48",MKD:"487.37",NOR:"26.07",OCEANIA:"474.92",OECD:"341.29",OMN:"488.24",PAK:"365.19",PSE:"465.12",PAN:"193.92",PNG:"526.75",PRY:"25.49",PER:"228.59",PHL:"581.15",POL:"660.12",PRT:"219.05",PRI:"681.47",QAT:"489.9",REU:"",ROU:"255.88",RUS:"359.94",RWA:"294.12",SHN:"",KNA:"681.82",LCA:"685.71",SPM:"800",VCT:"500",WSM:"470.59",STP:"600",SAU:"571.34",SEN:"502.67",SRB:"548.94",SYC:"615.39",SLE:"47.62",SGP:"488.59",SVK:"168.28",SVN:"238.61",SLB:"727.27",SOM:"634.15",ZAF:"715.68",KOR:"458.08",SSD:"684.21",ESP:"193.86",LKA:"479.83",SDN:"242.92",SUR:"356.44",SWE:"45.82",CHE:"47.1",SYR:"540.57",TWN:"573.28",TJK:"84.14",TZA:"361.08",THA:"506.64",TLS:"698.11",TGO:"507.94",TON:"625",TTO:"520.05",TUN:"468.23",TUR:"432.29",TKM:"544.39",TCA:"703.7",UGA:"52.27",UKR:"240.18",ARE:"461.85",GBR:"268.33",USA:"379.38",URY:"147.28",UZB:"506.16",VUT:"571.43",VEN:"189.45",VNM:"448.22",VGB:"714.29",VIR:"685.71",ESH:"",WORLD:"441.27",YEM:"528.41",ZMB:"84.7",ZWE:"393.04"},Ke="average",We="2021";var y={data:Ue,type:Ke,year:We};var Ye={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:Ye,type:ke,year:He};var xe={co2:z,hosting:J,averageIntensity:y,marginalIntensity:Q};return he(je);})();
|
|
20
20
|
//# sourceMappingURL=index.js.map
|