From f4a68349c4eb0fae6ae32a7bd53cd434863847dd Mon Sep 17 00:00:00 2001 From: fershad <27988517+fershad@users.noreply.github.com> Date: Mon, 1 Jan 2024 17:09:36 +0800 Subject: [PATCH 01/11] add file to ignore when packaging for npm --- .npmignore | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/.npmignore b/.npmignore index 5a20065..62a39bb 100644 --- a/.npmignore +++ b/.npmignore @@ -18,11 +18,7 @@ src/constants/test-constants.js # Data # exclude mode data data/** - -# but include the output js / json files -!data/output/** -# and include the minimized versions -!src/data/** +dist/data/** # Local sqlite db url2green.db @@ -30,4 +26,16 @@ url2green.json # don't track workspace files *.vscode -*.code-workspace \ No newline at end of file +*.code-workspace + +# don't publish IIFE files, will commit these to git for people who need them +dist/iife/** + +# don't publish the src folder, that code can be found on github +src/** + +## ignore the fixup file +fixup + +## don't publish the dotfiles +.* \ No newline at end of file From d7eca01d3494b2b9ea4a67b27db131af61694ccc Mon Sep 17 00:00:00 2001 From: fershad <27988517+fershad@users.noreply.github.com> Date: Mon, 1 Jan 2024 17:42:28 +0800 Subject: [PATCH 02/11] commit iife bundle --- .gitignore | 5 ++++- dist/iife/index.js | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 dist/iife/index.js diff --git a/.gitignore b/.gitignore index 7db62e0..a7bc4ea 100644 --- a/.gitignore +++ b/.gitignore @@ -95,7 +95,10 @@ url2green.db url2green.json # don't track generated content -dist +dist/* + +# but commit the bundled IIFE code for anyone who needs it +!dist/iife # don't track source maps *.js.map diff --git a/dist/iife/index.js b/dist/iife/index.js new file mode 100644 index 0000000..1216ddd --- /dev/null +++ b/dist/iife/index.js @@ -0,0 +1,20 @@ +var co2=(()=>{var A=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var F=(a,e)=>{for(var t in e)A(a,t,{get:e[t],enumerable:!0})},W=(a,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of K(e))!w.call(a,r)&&r!==t&&A(a,r,{get:()=>e[r],enumerable:!(n=U(e,r))||n.enumerable});return a};var Y=a=>W(A({},"__esModule",{value:!0}),a);var ee={};F(ee,{averageIntensity:()=>E,co2:()=>M,default:()=>X,hosting:()=>b,marginalIntensity:()=>V});var T=4883333333333333e-25;var m=class{constructor(e){this.options=e,this.KWH_PER_BYTE_FOR_NETWORK=T}perByte(e,t){if(e<1)return 0;if(t){let r=e*72e-12*0,i=e*T*475;return r+i}let n=72e-12+T;return e*n*519}};var L=m;var C={GIGABYTE:1e9};var H={AFG:120.48,AFRICA:484.7,ALB:23.44,DZA:485.49,ASM:687.5,AGO:195.98,ATG:657.14,ARG:344.31,ARM:222.68,ABW:591.4,ASEAN:508.2,ASIA:534.83,AUS:501.7,AUT:158.22,AZE:469.58,BHS:698.11,BHR:494.02,BGD:574.28,BRB:644.86,BLR:425.9,BEL:167.11,BLZ:484.38,BEN:666.67,BTN:24.44,BOL:335.4,BIH:553.47,BWA:794.52,BRA:102.04,BRN:493.59,BGR:399.72,BFA:611.43,BDI:250,CPV:600,KHM:400.46,CMR:278.26,CAN:125.84,CYM:684.93,CAF:0,TCD:677.42,CHL:332.61,CHN:533.98,COL:163.99,COM:714.29,COG:395.52,COD:25.36,COK:400,CRI:37.21,CIV:410.75,HRV:246.29,CUB:654.68,CYP:589.35,CZE:414.8,DNK:180.42,DJI:666.67,DMA:529.41,DOM:549.8,ECU:183.63,EGY:469.63,SLV:194.23,GNQ:492.96,ERI:688.89,EST:460.26,SWZ:189.19,ETH:25.19,EU:276.63,EUROPE:297.05,FLK:500,FRO:428.57,FJI:289.47,FIN:131.71,FRA:84.88,GUF:254.72,PYF:471.43,G20:442.57,G7:344.31,GAB:397.38,GMB:700,GEO:134.83,DEU:385.39,GHA:361.2,GRC:344.41,GRL:133.33,GRD:714.29,GLP:623.53,GUM:670.33,GTM:304.71,GIN:208.63,GNB:750,GUY:642.28,HTI:606.06,HND:373.96,HKG:609.93,HUN:222.1,ISL:28.56,IND:633.4,IDN:619.03,IRN:487.86,IRQ:531.36,IRL:346.43,ISR:537.57,ITA:372.63,JAM:537.93,JPN:494.86,JOR:391.13,KAZ:635.57,KEN:101.13,KIR:666.67,XKX:767,KWT:574.56,KGZ:104.43,LAO:242.18,"LATIN AMERICA AND CARIBBEAN":237.91,LVA:183.43,LBN:663.1,LSO:20,LBR:304.35,LBY:558.85,LTU:195.7,LUX:162.6,MAC:491.53,MDG:483.25,MWI:133.8,MYS:543.87,MDV:651.52,MLI:463.13,MLT:433.48,MTQ:698.63,MRT:526.6,MUS:611.11,MEX:423.81,"MIDDLE EAST":519.92,MDA:666.67,MNG:642.37,MNE:392.75,MSR:1e3,MAR:630.75,MOZ:126.63,MMR:330.8,NAM:63.69,NRU:750,NPL:24.51,NLD:354.31,NCL:610.12,NZL:105.22,NIC:354.21,NER:622.22,NGA:368.11,"NORTH AMERICA":336.68,PRK:102.42,MKD:543.71,NOR:28.93,OCEANIA:450.73,OECD:341.08,OMN:488.27,PAK:344.16,PSE:465.12,PAN:152.68,PNG:526.75,PRY:25.49,PER:256.51,POL:633.23,PRT:234.61,PRI:612.39,QAT:490.28,REU:519.03,ROU:264.24,RUS:363.68,RWA:294.12,KNA:681.82,LCA:685.71,SPM:800,VCT:500,WSM:470.59,STP:600,SAU:557.78,SEN:523.13,SRB:582.13,SYC:615.39,SLE:47.62,SGP:488.78,SVK:140.14,SVN:237.38,SLB:727.27,SOM:634.15,ZAF:708.21,KOR:437.6,SSD:684.21,ESP:217.42,LKA:501.53,SDN:288.13,SUR:356.44,SWE:45.12,CHE:41.28,SYR:541.17,TWN:560.98,TJK:83.63,TZA:366.75,THA:501.57,PHL:594.45,TGO:460.32,TON:625,TTO:491.41,TUN:469.43,TUR:413.6,TKM:490.19,TCA:703.7,UGA:52.27,UKR:232.74,ARE:407.98,GBR:261.16,USA:368.1,URY:150.13,UZB:505.41,VUT:571.43,VEN:212.48,VNM:386.49,VGB:714.29,VIR:685.71,WORLD:437.63,YEM:559.66,ZMB:84.7,ZWE:392.28},k="average";var E={data:H,type:k};var D=.81,O=.52,S=.14,p=.15,P=.19,c=E.data.WORLD,f=50,g=.75,y=.25,N=.02;var R=a=>parseFloat(a.toFixed(2));function B(a){if(typeof a!="object")throw new Error("Options must be an object");let e={};if(a?.gridIntensity){e.gridIntensity={};let{device:t,dataCenter:n,network:r}=a.gridIntensity;(t||t===0)&&(typeof t=="object"?(E.data[t.country?.toUpperCase()]||(console.warn(`"${t.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. +See https://developers.thegreenwebfoundation.org/co2js/data/ for more information. +Falling back to global average grid intensity.`),e.gridIntensity.device={value:c}),e.gridIntensity.device={country:t.country,value:parseFloat(E.data[t.country?.toUpperCase()])}):typeof t=="number"?e.gridIntensity.device={value:t}:(e.gridIntensity.device={value:c},console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof t}. +Falling back to global average grid intensity.`))),(n||n===0)&&(typeof n=="object"?(E.data[n.country?.toUpperCase()]||(console.warn(`"${n.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. +See https://developers.thegreenwebfoundation.org/co2js/data/ for more information. +Falling back to global average grid intensity.`),e.gridIntensity.dataCenter={value:c}),e.gridIntensity.dataCenter={country:n.country,value:parseFloat(E.data[n.country?.toUpperCase()])}):typeof n=="number"?e.gridIntensity.dataCenter={value:n}:(e.gridIntensity.dataCenter={value:c},console.warn(`The data center grid intensity must be a number or an object. You passed in a ${typeof n}. +Falling back to global average grid intensity.`))),(r||r===0)&&(typeof r=="object"?(E.data[r.country?.toUpperCase()]||(console.warn(`"${r.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. +See https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity. +Falling back to global average grid intensity.`),e.gridIntensity.network={value:c}),e.gridIntensity.network={country:r.country,value:parseFloat(E.data[r.country?.toUpperCase()])}):typeof r=="number"?e.gridIntensity.network={value:r}:(e.gridIntensity.network={value:c},console.warn(`The network grid intensity must be a number or an object. You passed in a ${typeof r}. +Falling back to global average grid intensity.`)))}return(a?.dataReloadRatio||a.dataReloadRatio===0)&&(typeof a.dataReloadRatio=="number"?a.dataReloadRatio>=0&&a.dataReloadRatio<=1?e.dataReloadRatio=a.dataReloadRatio:(e.dataReloadRatio=N,console.warn(`The dataReloadRatio option must be a number between 0 and 1. You passed in ${a.dataReloadRatio}. +Falling back to default value.`)):(e.dataReloadRatio=N,console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof a.dataReloadRatio}. +Falling back to default value.`))),(a?.firstVisitPercentage||a.firstVisitPercentage===0)&&(typeof a.firstVisitPercentage=="number"?a.firstVisitPercentage>=0&&a.firstVisitPercentage<=1?e.firstVisitPercentage=a.firstVisitPercentage:(e.firstVisitPercentage=g,console.warn(`The firstVisitPercentage option must be a number between 0 and 1. You passed in ${a.firstVisitPercentage}. +Falling back to default value.`)):(e.firstVisitPercentage=g,console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof a.firstVisitPercentage}. +Falling back to default value.`))),(a?.returnVisitPercentage||a.returnVisitPercentage===0)&&(typeof a.returnVisitPercentage=="number"?a.returnVisitPercentage>=0&&a.returnVisitPercentage<=1?e.returnVisitPercentage=a.returnVisitPercentage:(e.returnVisitPercentage=y,console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${a.returnVisitPercentage}. +Falling back to default value.`)):(e.returnVisitPercentage=y,console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof a.returnVisitPercentage}. +Falling back to default value.`))),e}var _=class{constructor(e){this.options=e}energyPerByteByComponent(e){let n=e/C.GIGABYTE*D;return{consumerDeviceEnergy:n*O,networkEnergy:n*S,productionEnergy:n*P,dataCenterEnergy:n*p}}co2byComponent(e,t=c,n={}){let r=c,i=c,o=c,d=c;if(n?.gridIntensity){let{device:s,network:l,dataCenter:I}=n.gridIntensity;(s?.value||s?.value===0)&&(r=s.value),(l?.value||l?.value===0)&&(i=l.value),(I?.value||I?.value===0)&&(o=I.value)}t===!0&&(o=f);let u={};for(let[s,l]of Object.entries(e))s.startsWith("dataCenterEnergy")?u[s.replace("Energy","CO2")]=l*o:s.startsWith("consumerDeviceEnergy")?u[s.replace("Energy","CO2")]=l*r:s.startsWith("networkEnergy")?u[s.replace("Energy","CO2")]=l*i:u[s.replace("Energy","CO2")]=l*d;return u}perByte(e,t=!1,n=!1,r={}){e<1&&(e=0);let i=this.energyPerByteByComponent(e,r);if(typeof t!="boolean")throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${t}`);let o=this.co2byComponent(i,t,r),u=Object.values(o).reduce((s,l)=>s+l);return n?{...o,total:u}:u}perVisit(e,t=!1,n=!1,r={}){let i=this.energyPerVisitByComponent(e,r);if(typeof t!="boolean")throw new Error(`perVisit expects a boolean for the carbon intensity value. Received: ${t}`);let o=this.co2byComponent(i,t,r),u=Object.values(o).reduce((s,l)=>s+l);return n?{...o,total:u}:u}energyPerByte(e){let t=this.energyPerByteByComponent(e);return Object.values(t).reduce((r,i)=>r+i)}energyPerVisitByComponent(e,t={},n=g,r=y,i=N){(t.dataReloadRatio||t.dataReloadRatio===0)&&(i=t.dataReloadRatio),(t.firstVisitPercentage||t.firstVisitPercentage===0)&&(n=t.firstVisitPercentage),(t.returnVisitPercentage||t.returnVisitPercentage===0)&&(r=t.returnVisitPercentage);let o=this.energyPerByteByComponent(e),d={},u=Object.values(o);for(let[s,l]of Object.entries(o))d[`${s} - first`]=l*n,d[`${s} - subsequent`]=l*r*i;return d}energyPerVisit(e){let t=0,n=0,r=Object.entries(this.energyPerVisitByComponent(e));for(let[i,o]of r)i.indexOf("first")>0&&(t+=o);for(let[i,o]of r)i.indexOf("subsequent")>0&&(n+=o);return t+n}emissionsPerVisitInGrams(e,t=c){return R(e*t)}annualEnergyInKwh(e,t=1e3){return e*t*12}annualEmissionsInGrams(e,t=1e3){return e*t*12}annualSegmentEnergy(e){return{consumerDeviceEnergy:R(e*O),networkEnergy:R(e*S),dataCenterEnergy:R(e*p),productionEnergy:R(e*P)}}};var G=_;var h=class{constructor(e){if(this.model=new G,e?.model==="1byte")this.model=new L;else if(e?.model==="swd")this.model=new G;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. +See https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);this._segment=e?.results==="segment"}perByte(e,t=!1){return this.model.perByte(e,t,this._segment)}perVisit(e,t=!1){if(this.model?.perVisit)return this.model.perVisit(e,t,this._segment);throw new Error(`The perVisit() method is not supported in the model you are using. Try using perByte() instead. +See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`)}perByteTrace(e,t=!1,n={}){let r={};return n&&(r=B(n)),{co2:this.model.perByte(e,t,this._segment,r),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:r?.gridIntensity?.network?.value??c,dataCenter:t?f:r?.gridIntensity?.dataCenter?.value??c,production:c,device:r?.gridIntensity?.device?.value??c}}}}perVisitTrace(e,t=!1,n={}){if(this.model?.perVisit){let r={};return n&&(r=B(n)),{co2:this.model.perVisit(e,t,this._segment,r),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:r?.gridIntensity?.network?.value??c,dataCenter:t?f:r?.gridIntensity?.dataCenter?.value??c,production:c,device:r?.gridIntensity?.device?.value??c},dataReloadRatio:r?.dataReloadRatio??.02,firstVisitPercentage:r?.firstVisitPercentage??.75,returnVisitPercentage:r?.returnVisitPercentage??.25}}}else throw new Error(`The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead. +See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`)}perDomain(e,t){let n=[];for(let r of Object.keys(e.domains)){let i;t&&t.indexOf(r)>-1?i=this.perByte(e.domains[r].transferSize,!0):i=this.perByte(e.domains[r].transferSize),n.push({domain:r,co2:i,transferSize:e.domains[r].transferSize})}return n.sort((r,i)=>i.co2-r.co2),n}perPage(e,t){let n=this.perDomain(e,t),r=0;for(let i of n)r+=i.co2;return r}perContentType(e,t){let n={};for(let i of e.assets){let o=new URL(i.url).domain,d=i.transferSize,u=this.perByte(d,t&&t.indexOf(o)>-1),s=i.type;n[s]||(n[s]={co2:0,transferSize:0}),n[s].co2+=u,n[s].transferSize+=d}let r=[];for(let i of Object.keys(n))r.push({type:i,co2:n[i].co2,transferSize:n[i].transferSize});return r.sort((i,o)=>o.co2-i.co2),r}dirtiestResources(e,t){let n=[];for(let r of e.assets){let i=new URL(r.url).domain,o=r.transferSize,d=this.perByte(o,t&&t.indexOf(i)>-1);n.push({url:r.url,co2:d,transferSize:o})}return n.sort((r,i)=>i.co2-r.co2),n.slice(0,n.length>10?10:n.length)}perParty(e,t){let n=0,r=0,i=e.firstPartyRegEx;for(let o of Object.keys(e.domains))o.match(i)?n+=this.perByte(e.domains[o].transferSize,t&&t.indexOf(o)>-1):r+=this.perByte(e.domains[o].transferSize,t&&t.indexOf(o)>-1);return{firstParty:n,thirdParty:r}}};var M=h;function j(a){return typeof a=="string"?x(a):Z(a)}async function x(a){return(await(await fetch(`https://api.thegreenwebfoundation.org/greencheck/${a}`)).json()).green}async function Z(a){try{let e="https://api.thegreenwebfoundation.org/v2/greencheckmulti",t=JSON.stringify(a),r=await(await fetch(`${e}/${t}`)).json();return $(r)}catch{return[]}}function $(a){return Object.entries(a).filter(([n,r])=>r.green).map(([n,r])=>r.url)}var v={check:j};function z(a){return v.check(a)}var b={check:z};var J={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"},Q="marginal",q="2021";var V={data:J,type:Q,year:q};var X={co2:M,hosting:b,averageIntensity:E,marginalIntensity:V};return Y(ee);})(); +//# sourceMappingURL=index.js.map From 84384da1df1c5cc65cd547e75e2feed85751049b Mon Sep 17 00:00:00 2001 From: fershad Date: Wed, 3 Jan 2024 10:09:01 +0000 Subject: [PATCH 03/11] Update average annual grid intensities --- data/output/average-intensities.js | 6 +++--- data/output/average-intensities.json | 6 +++--- src/data/average-intensities.min.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/data/output/average-intensities.js b/data/output/average-intensities.js index 1529205..3ff517a 100644 --- a/data/output/average-intensities.js +++ b/data/output/average-intensities.js @@ -10,7 +10,7 @@ const data = { ARM: 222.68, ABW: 591.4, ASEAN: 508.2, - ASIA: 534.83, + ASIA: 534.89, AUS: 501.7, AUT: 158.22, AZE: 469.58, @@ -131,7 +131,7 @@ const data = { MEX: 423.81, "MIDDLE EAST": 519.92, MDA: 666.67, - MNG: 642.37, + MNG: 749.66, MNE: 392.75, MSR: 1000, MAR: 630.75, @@ -217,7 +217,7 @@ const data = { VNM: 386.49, VGB: 714.29, VIR: 685.71, - WORLD: 437.63, + WORLD: 437.66, YEM: 559.66, ZMB: 84.7, ZWE: 392.28, diff --git a/data/output/average-intensities.json b/data/output/average-intensities.json index 0a624e5..9fdd27e 100644 --- a/data/output/average-intensities.json +++ b/data/output/average-intensities.json @@ -69,7 +69,7 @@ "country_code": "", "country_or_region": "Asia", "year": 2022, - "emissions_intensity_gco2_per_kwh": 534.83 + "emissions_intensity_gco2_per_kwh": 534.89 }, "AUS": { "country_code": "AUS", @@ -795,7 +795,7 @@ "country_code": "MNG", "country_or_region": "Mongolia", "year": 2022, - "emissions_intensity_gco2_per_kwh": 642.37 + "emissions_intensity_gco2_per_kwh": 749.66 }, "MNE": { "country_code": "MNE", @@ -1311,7 +1311,7 @@ "country_code": "", "country_or_region": "World", "year": 2022, - "emissions_intensity_gco2_per_kwh": 437.63 + "emissions_intensity_gco2_per_kwh": 437.66 }, "YEM": { "country_code": "YEM", diff --git a/src/data/average-intensities.min.js b/src/data/average-intensities.min.js index d66c8e9..23fe097 100644 --- a/src/data/average-intensities.min.js +++ b/src/data/average-intensities.min.js @@ -1 +1 @@ -const data = {"AFG":120.48,"AFRICA":484.7,"ALB":23.44,"DZA":485.49,"ASM":687.5,"AGO":195.98,"ATG":657.14,"ARG":344.31,"ARM":222.68,"ABW":591.4,"ASEAN":508.2,"ASIA":534.83,"AUS":501.7,"AUT":158.22,"AZE":469.58,"BHS":698.11,"BHR":494.02,"BGD":574.28,"BRB":644.86,"BLR":425.9,"BEL":167.11,"BLZ":484.38,"BEN":666.67,"BTN":24.44,"BOL":335.4,"BIH":553.47,"BWA":794.52,"BRA":102.04,"BRN":493.59,"BGR":399.72,"BFA":611.43,"BDI":250,"CPV":600,"KHM":400.46,"CMR":278.26,"CAN":125.84,"CYM":684.93,"CAF":0,"TCD":677.42,"CHL":332.61,"CHN":533.98,"COL":163.99,"COM":714.29,"COG":395.52,"COD":25.36,"COK":400,"CRI":37.21,"CIV":410.75,"HRV":246.29,"CUB":654.68,"CYP":589.35,"CZE":414.8,"DNK":180.42,"DJI":666.67,"DMA":529.41,"DOM":549.8,"ECU":183.63,"EGY":469.63,"SLV":194.23,"GNQ":492.96,"ERI":688.89,"EST":460.26,"SWZ":189.19,"ETH":25.19,"EU":276.63,"EUROPE":297.05,"FLK":500,"FRO":428.57,"FJI":289.47,"FIN":131.71,"FRA":84.88,"GUF":254.72,"PYF":471.43,"G20":442.57,"G7":344.31,"GAB":397.38,"GMB":700,"GEO":134.83,"DEU":385.39,"GHA":361.2,"GRC":344.41,"GRL":133.33,"GRD":714.29,"GLP":623.53,"GUM":670.33,"GTM":304.71,"GIN":208.63,"GNB":750,"GUY":642.28,"HTI":606.06,"HND":373.96,"HKG":609.93,"HUN":222.1,"ISL":28.56,"IND":633.4,"IDN":619.03,"IRN":487.86,"IRQ":531.36,"IRL":346.43,"ISR":537.57,"ITA":372.63,"JAM":537.93,"JPN":494.86,"JOR":391.13,"KAZ":635.57,"KEN":101.13,"KIR":666.67,"XKX":767,"KWT":574.56,"KGZ":104.43,"LAO":242.18,"LATIN AMERICA AND CARIBBEAN":237.91,"LVA":183.43,"LBN":663.1,"LSO":20,"LBR":304.35,"LBY":558.85,"LTU":195.7,"LUX":162.6,"MAC":491.53,"MDG":483.25,"MWI":133.8,"MYS":543.87,"MDV":651.52,"MLI":463.13,"MLT":433.48,"MTQ":698.63,"MRT":526.6,"MUS":611.11,"MEX":423.81,"MIDDLE EAST":519.92,"MDA":666.67,"MNG":642.37,"MNE":392.75,"MSR":1000,"MAR":630.75,"MOZ":126.63,"MMR":330.8,"NAM":63.69,"NRU":750,"NPL":24.51,"NLD":354.31,"NCL":610.12,"NZL":105.22,"NIC":354.21,"NER":622.22,"NGA":368.11,"NORTH AMERICA":336.68,"PRK":102.42,"MKD":543.71,"NOR":28.93,"OCEANIA":450.73,"OECD":341.08,"OMN":488.27,"PAK":344.16,"PSE":465.12,"PAN":152.68,"PNG":526.75,"PRY":25.49,"PER":256.51,"POL":633.23,"PRT":234.61,"PRI":612.39,"QAT":490.28,"REU":519.03,"ROU":264.24,"RUS":363.68,"RWA":294.12,"KNA":681.82,"LCA":685.71,"SPM":800,"VCT":500,"WSM":470.59,"STP":600,"SAU":557.78,"SEN":523.13,"SRB":582.13,"SYC":615.39,"SLE":47.62,"SGP":488.78,"SVK":140.14,"SVN":237.38,"SLB":727.27,"SOM":634.15,"ZAF":708.21,"KOR":437.6,"SSD":684.21,"ESP":217.42,"LKA":501.53,"SDN":288.13,"SUR":356.44,"SWE":45.12,"CHE":41.28,"SYR":541.17,"TWN":560.98,"TJK":83.63,"TZA":366.75,"THA":501.57,"PHL":594.45,"TGO":460.32,"TON":625,"TTO":491.41,"TUN":469.43,"TUR":413.6,"TKM":490.19,"TCA":703.7,"UGA":52.27,"UKR":232.74,"ARE":407.98,"GBR":261.16,"USA":368.1,"URY":150.13,"UZB":505.41,"VUT":571.43,"VEN":212.48,"VNM":386.49,"VGB":714.29,"VIR":685.71,"WORLD":437.63,"YEM":559.66,"ZMB":84.7,"ZWE":392.28}; const type = "average"; export { data, type }; export default { data, type }; \ No newline at end of file +const data = {"AFG":120.48,"AFRICA":484.7,"ALB":23.44,"DZA":485.49,"ASM":687.5,"AGO":195.98,"ATG":657.14,"ARG":344.31,"ARM":222.68,"ABW":591.4,"ASEAN":508.2,"ASIA":534.89,"AUS":501.7,"AUT":158.22,"AZE":469.58,"BHS":698.11,"BHR":494.02,"BGD":574.28,"BRB":644.86,"BLR":425.9,"BEL":167.11,"BLZ":484.38,"BEN":666.67,"BTN":24.44,"BOL":335.4,"BIH":553.47,"BWA":794.52,"BRA":102.04,"BRN":493.59,"BGR":399.72,"BFA":611.43,"BDI":250,"CPV":600,"KHM":400.46,"CMR":278.26,"CAN":125.84,"CYM":684.93,"CAF":0,"TCD":677.42,"CHL":332.61,"CHN":533.98,"COL":163.99,"COM":714.29,"COG":395.52,"COD":25.36,"COK":400,"CRI":37.21,"CIV":410.75,"HRV":246.29,"CUB":654.68,"CYP":589.35,"CZE":414.8,"DNK":180.42,"DJI":666.67,"DMA":529.41,"DOM":549.8,"ECU":183.63,"EGY":469.63,"SLV":194.23,"GNQ":492.96,"ERI":688.89,"EST":460.26,"SWZ":189.19,"ETH":25.19,"EU":276.63,"EUROPE":297.05,"FLK":500,"FRO":428.57,"FJI":289.47,"FIN":131.71,"FRA":84.88,"GUF":254.72,"PYF":471.43,"G20":442.57,"G7":344.31,"GAB":397.38,"GMB":700,"GEO":134.83,"DEU":385.39,"GHA":361.2,"GRC":344.41,"GRL":133.33,"GRD":714.29,"GLP":623.53,"GUM":670.33,"GTM":304.71,"GIN":208.63,"GNB":750,"GUY":642.28,"HTI":606.06,"HND":373.96,"HKG":609.93,"HUN":222.1,"ISL":28.56,"IND":633.4,"IDN":619.03,"IRN":487.86,"IRQ":531.36,"IRL":346.43,"ISR":537.57,"ITA":372.63,"JAM":537.93,"JPN":494.86,"JOR":391.13,"KAZ":635.57,"KEN":101.13,"KIR":666.67,"XKX":767,"KWT":574.56,"KGZ":104.43,"LAO":242.18,"LATIN AMERICA AND CARIBBEAN":237.91,"LVA":183.43,"LBN":663.1,"LSO":20,"LBR":304.35,"LBY":558.85,"LTU":195.7,"LUX":162.6,"MAC":491.53,"MDG":483.25,"MWI":133.8,"MYS":543.87,"MDV":651.52,"MLI":463.13,"MLT":433.48,"MTQ":698.63,"MRT":526.6,"MUS":611.11,"MEX":423.81,"MIDDLE EAST":519.92,"MDA":666.67,"MNG":749.66,"MNE":392.75,"MSR":1000,"MAR":630.75,"MOZ":126.63,"MMR":330.8,"NAM":63.69,"NRU":750,"NPL":24.51,"NLD":354.31,"NCL":610.12,"NZL":105.22,"NIC":354.21,"NER":622.22,"NGA":368.11,"NORTH AMERICA":336.68,"PRK":102.42,"MKD":543.71,"NOR":28.93,"OCEANIA":450.73,"OECD":341.08,"OMN":488.27,"PAK":344.16,"PSE":465.12,"PAN":152.68,"PNG":526.75,"PRY":25.49,"PER":256.51,"POL":633.23,"PRT":234.61,"PRI":612.39,"QAT":490.28,"REU":519.03,"ROU":264.24,"RUS":363.68,"RWA":294.12,"KNA":681.82,"LCA":685.71,"SPM":800,"VCT":500,"WSM":470.59,"STP":600,"SAU":557.78,"SEN":523.13,"SRB":582.13,"SYC":615.39,"SLE":47.62,"SGP":488.78,"SVK":140.14,"SVN":237.38,"SLB":727.27,"SOM":634.15,"ZAF":708.21,"KOR":437.6,"SSD":684.21,"ESP":217.42,"LKA":501.53,"SDN":288.13,"SUR":356.44,"SWE":45.12,"CHE":41.28,"SYR":541.17,"TWN":560.98,"TJK":83.63,"TZA":366.75,"THA":501.57,"PHL":594.45,"TGO":460.32,"TON":625,"TTO":491.41,"TUN":469.43,"TUR":413.6,"TKM":490.19,"TCA":703.7,"UGA":52.27,"UKR":232.74,"ARE":407.98,"GBR":261.16,"USA":368.1,"URY":150.13,"UZB":505.41,"VUT":571.43,"VEN":212.48,"VNM":386.49,"VGB":714.29,"VIR":685.71,"WORLD":437.66,"YEM":559.66,"ZMB":84.7,"ZWE":392.28}; const type = "average"; export { data, type }; export default { data, type }; \ No newline at end of file From b22bf09bbaef8e5d48df296ab3875c9ebdd5655c Mon Sep 17 00:00:00 2001 From: fershad <27988517+fershad@users.noreply.github.com> Date: Mon, 8 Jan 2024 11:52:53 +0800 Subject: [PATCH 04/11] update test constants --- src/constants/test-constants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants/test-constants.js b/src/constants/test-constants.js index 8daa1f6..c645520 100644 --- a/src/constants/test-constants.js +++ b/src/constants/test-constants.js @@ -12,7 +12,7 @@ export const ONEBYTE = { export const SWD = { MILLION_GREY: 0.35418, MILLION_GREEN: 0.30713, - MILLION_PERVISIT_GREY: 0.26763, + MILLION_PERVISIT_GREY: 0.26765, MILLION_PERVISIT_GREEN: 0.23188, TGWF_GREY_VALUE: 0.24963, From ff6f767fac8a263eaba578329989bc21c09deb16 Mon Sep 17 00:00:00 2001 From: fershad <27988517+fershad@users.noreply.github.com> Date: Mon, 8 Jan 2024 12:02:46 +0800 Subject: [PATCH 05/11] remove index.d.ts file --- index.d.ts | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4610950..0000000 --- a/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -declare module '@tgwf/co2'; - From b5d88284b0e939bb0fceb7fc4605124f2fa7c7d8 Mon Sep 17 00:00:00 2001 From: fershad <27988517+fershad@users.noreply.github.com> Date: Mon, 8 Jan 2024 12:03:02 +0800 Subject: [PATCH 06/11] add guidance on installing type definitions --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index b702fc7..fc854a9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # CO2.js + [![All Contributors](https://img.shields.io/badge/all_contributors-13-orange.svg?style=flat-square)](#contributors-) + @@ -75,6 +77,14 @@ You can also build the CO2.js library from the source code. To do this: - `dist/esm` - An ES Modules compatible build. - `dist/iife` - An Immediately Invoked Function Expression (IIFE) version of the library. +## Using CO2.js in TypeScript projects + +Type definitions for CO2.js are published in the DefinitelyTyped project, and are available on NPM at `@types/tgwf__co2`. + +If you want to use type definitions in your project, they should be installed as a devDependency. + +`npm install --dev @types/tgwf__co2` + ## Marginal and average emissions intensity data CO2.js includes yearly average grid intensity data from [Ember](https://ember-climate.org/data/data-explorer/), as well as marginal intensity data from the [UNFCCC](https://unfccc.int/) (United Nations Framework Convention on Climate Change). You can find the data in JSON and CommonJS Module format in the `data/output` folder. From bf834fe8225dc8a778a7252069d12c844733aab2 Mon Sep 17 00:00:00 2001 From: fershad <27988517+fershad@users.noreply.github.com> Date: Mon, 8 Jan 2024 12:06:51 +0800 Subject: [PATCH 07/11] add links to npm and DT --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fc854a9..c7b2449 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ You can also build the CO2.js library from the source code. To do this: ## Using CO2.js in TypeScript projects -Type definitions for CO2.js are published in the DefinitelyTyped project, and are available on NPM at `@types/tgwf__co2`. +Type definitions for CO2.js are [published in the DefinitelyTyped project](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/tgwf__co2), and are [available on NPM](https://www.npmjs.com/package/@types/tgwf__co2) at `@types/tgwf__co2`. If you want to use type definitions in your project, they should be installed as a devDependency. From e53da02e085ee1d08c5e0bf9db11b62c4f2dc511 Mon Sep 17 00:00:00 2001 From: fershad <27988517+fershad@users.noreply.github.com> Date: Mon, 8 Jan 2024 12:09:31 +0800 Subject: [PATCH 08/11] change title --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c7b2449..6c48f18 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ You can also build the CO2.js library from the source code. To do this: - `dist/esm` - An ES Modules compatible build. - `dist/iife` - An Immediately Invoked Function Expression (IIFE) version of the library. -## Using CO2.js in TypeScript projects +## TypeScript support Type definitions for CO2.js are [published in the DefinitelyTyped project](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/tgwf__co2), and are [available on NPM](https://www.npmjs.com/package/@types/tgwf__co2) at `@types/tgwf__co2`. From 6555fcf645dd1546c50bfa4e2a87b0a7e5b3c984 Mon Sep 17 00:00:00 2001 From: fershad <27988517+fershad@users.noreply.github.com> Date: Tue, 9 Jan 2024 14:12:01 +0800 Subject: [PATCH 09/11] build with latest grid intensity figures --- dist/iife/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/iife/index.js b/dist/iife/index.js index 1216ddd..ac43d40 100644 --- a/dist/iife/index.js +++ b/dist/iife/index.js @@ -1,4 +1,4 @@ -var co2=(()=>{var A=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var F=(a,e)=>{for(var t in e)A(a,t,{get:e[t],enumerable:!0})},W=(a,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of K(e))!w.call(a,r)&&r!==t&&A(a,r,{get:()=>e[r],enumerable:!(n=U(e,r))||n.enumerable});return a};var Y=a=>W(A({},"__esModule",{value:!0}),a);var ee={};F(ee,{averageIntensity:()=>E,co2:()=>M,default:()=>X,hosting:()=>b,marginalIntensity:()=>V});var T=4883333333333333e-25;var m=class{constructor(e){this.options=e,this.KWH_PER_BYTE_FOR_NETWORK=T}perByte(e,t){if(e<1)return 0;if(t){let r=e*72e-12*0,i=e*T*475;return r+i}let n=72e-12+T;return e*n*519}};var L=m;var C={GIGABYTE:1e9};var H={AFG:120.48,AFRICA:484.7,ALB:23.44,DZA:485.49,ASM:687.5,AGO:195.98,ATG:657.14,ARG:344.31,ARM:222.68,ABW:591.4,ASEAN:508.2,ASIA:534.83,AUS:501.7,AUT:158.22,AZE:469.58,BHS:698.11,BHR:494.02,BGD:574.28,BRB:644.86,BLR:425.9,BEL:167.11,BLZ:484.38,BEN:666.67,BTN:24.44,BOL:335.4,BIH:553.47,BWA:794.52,BRA:102.04,BRN:493.59,BGR:399.72,BFA:611.43,BDI:250,CPV:600,KHM:400.46,CMR:278.26,CAN:125.84,CYM:684.93,CAF:0,TCD:677.42,CHL:332.61,CHN:533.98,COL:163.99,COM:714.29,COG:395.52,COD:25.36,COK:400,CRI:37.21,CIV:410.75,HRV:246.29,CUB:654.68,CYP:589.35,CZE:414.8,DNK:180.42,DJI:666.67,DMA:529.41,DOM:549.8,ECU:183.63,EGY:469.63,SLV:194.23,GNQ:492.96,ERI:688.89,EST:460.26,SWZ:189.19,ETH:25.19,EU:276.63,EUROPE:297.05,FLK:500,FRO:428.57,FJI:289.47,FIN:131.71,FRA:84.88,GUF:254.72,PYF:471.43,G20:442.57,G7:344.31,GAB:397.38,GMB:700,GEO:134.83,DEU:385.39,GHA:361.2,GRC:344.41,GRL:133.33,GRD:714.29,GLP:623.53,GUM:670.33,GTM:304.71,GIN:208.63,GNB:750,GUY:642.28,HTI:606.06,HND:373.96,HKG:609.93,HUN:222.1,ISL:28.56,IND:633.4,IDN:619.03,IRN:487.86,IRQ:531.36,IRL:346.43,ISR:537.57,ITA:372.63,JAM:537.93,JPN:494.86,JOR:391.13,KAZ:635.57,KEN:101.13,KIR:666.67,XKX:767,KWT:574.56,KGZ:104.43,LAO:242.18,"LATIN AMERICA AND CARIBBEAN":237.91,LVA:183.43,LBN:663.1,LSO:20,LBR:304.35,LBY:558.85,LTU:195.7,LUX:162.6,MAC:491.53,MDG:483.25,MWI:133.8,MYS:543.87,MDV:651.52,MLI:463.13,MLT:433.48,MTQ:698.63,MRT:526.6,MUS:611.11,MEX:423.81,"MIDDLE EAST":519.92,MDA:666.67,MNG:642.37,MNE:392.75,MSR:1e3,MAR:630.75,MOZ:126.63,MMR:330.8,NAM:63.69,NRU:750,NPL:24.51,NLD:354.31,NCL:610.12,NZL:105.22,NIC:354.21,NER:622.22,NGA:368.11,"NORTH AMERICA":336.68,PRK:102.42,MKD:543.71,NOR:28.93,OCEANIA:450.73,OECD:341.08,OMN:488.27,PAK:344.16,PSE:465.12,PAN:152.68,PNG:526.75,PRY:25.49,PER:256.51,POL:633.23,PRT:234.61,PRI:612.39,QAT:490.28,REU:519.03,ROU:264.24,RUS:363.68,RWA:294.12,KNA:681.82,LCA:685.71,SPM:800,VCT:500,WSM:470.59,STP:600,SAU:557.78,SEN:523.13,SRB:582.13,SYC:615.39,SLE:47.62,SGP:488.78,SVK:140.14,SVN:237.38,SLB:727.27,SOM:634.15,ZAF:708.21,KOR:437.6,SSD:684.21,ESP:217.42,LKA:501.53,SDN:288.13,SUR:356.44,SWE:45.12,CHE:41.28,SYR:541.17,TWN:560.98,TJK:83.63,TZA:366.75,THA:501.57,PHL:594.45,TGO:460.32,TON:625,TTO:491.41,TUN:469.43,TUR:413.6,TKM:490.19,TCA:703.7,UGA:52.27,UKR:232.74,ARE:407.98,GBR:261.16,USA:368.1,URY:150.13,UZB:505.41,VUT:571.43,VEN:212.48,VNM:386.49,VGB:714.29,VIR:685.71,WORLD:437.63,YEM:559.66,ZMB:84.7,ZWE:392.28},k="average";var E={data:H,type:k};var D=.81,O=.52,S=.14,p=.15,P=.19,c=E.data.WORLD,f=50,g=.75,y=.25,N=.02;var R=a=>parseFloat(a.toFixed(2));function B(a){if(typeof a!="object")throw new Error("Options must be an object");let e={};if(a?.gridIntensity){e.gridIntensity={};let{device:t,dataCenter:n,network:r}=a.gridIntensity;(t||t===0)&&(typeof t=="object"?(E.data[t.country?.toUpperCase()]||(console.warn(`"${t.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. +var co2=(()=>{var A=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var F=(a,e)=>{for(var t in e)A(a,t,{get:e[t],enumerable:!0})},W=(a,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of K(e))!w.call(a,r)&&r!==t&&A(a,r,{get:()=>e[r],enumerable:!(n=U(e,r))||n.enumerable});return a};var Y=a=>W(A({},"__esModule",{value:!0}),a);var ee={};F(ee,{averageIntensity:()=>E,co2:()=>M,default:()=>X,hosting:()=>b,marginalIntensity:()=>V});var T=4883333333333333e-25;var m=class{constructor(e){this.options=e,this.KWH_PER_BYTE_FOR_NETWORK=T}perByte(e,t){if(e<1)return 0;if(t){let r=e*72e-12*0,i=e*T*475;return r+i}let n=72e-12+T;return e*n*519}};var L=m;var C={GIGABYTE:1e9};var H={AFG:120.48,AFRICA:484.7,ALB:23.44,DZA:485.49,ASM:687.5,AGO:195.98,ATG:657.14,ARG:344.31,ARM:222.68,ABW:591.4,ASEAN:508.2,ASIA:534.89,AUS:501.7,AUT:158.22,AZE:469.58,BHS:698.11,BHR:494.02,BGD:574.28,BRB:644.86,BLR:425.9,BEL:167.11,BLZ:484.38,BEN:666.67,BTN:24.44,BOL:335.4,BIH:553.47,BWA:794.52,BRA:102.04,BRN:493.59,BGR:399.72,BFA:611.43,BDI:250,CPV:600,KHM:400.46,CMR:278.26,CAN:125.84,CYM:684.93,CAF:0,TCD:677.42,CHL:332.61,CHN:533.98,COL:163.99,COM:714.29,COG:395.52,COD:25.36,COK:400,CRI:37.21,CIV:410.75,HRV:246.29,CUB:654.68,CYP:589.35,CZE:414.8,DNK:180.42,DJI:666.67,DMA:529.41,DOM:549.8,ECU:183.63,EGY:469.63,SLV:194.23,GNQ:492.96,ERI:688.89,EST:460.26,SWZ:189.19,ETH:25.19,EU:276.63,EUROPE:297.05,FLK:500,FRO:428.57,FJI:289.47,FIN:131.71,FRA:84.88,GUF:254.72,PYF:471.43,G20:442.57,G7:344.31,GAB:397.38,GMB:700,GEO:134.83,DEU:385.39,GHA:361.2,GRC:344.41,GRL:133.33,GRD:714.29,GLP:623.53,GUM:670.33,GTM:304.71,GIN:208.63,GNB:750,GUY:642.28,HTI:606.06,HND:373.96,HKG:609.93,HUN:222.1,ISL:28.56,IND:633.4,IDN:619.03,IRN:487.86,IRQ:531.36,IRL:346.43,ISR:537.57,ITA:372.63,JAM:537.93,JPN:494.86,JOR:391.13,KAZ:635.57,KEN:101.13,KIR:666.67,XKX:767,KWT:574.56,KGZ:104.43,LAO:242.18,"LATIN AMERICA AND CARIBBEAN":237.91,LVA:183.43,LBN:663.1,LSO:20,LBR:304.35,LBY:558.85,LTU:195.7,LUX:162.6,MAC:491.53,MDG:483.25,MWI:133.8,MYS:543.87,MDV:651.52,MLI:463.13,MLT:433.48,MTQ:698.63,MRT:526.6,MUS:611.11,MEX:423.81,"MIDDLE EAST":519.92,MDA:666.67,MNG:749.66,MNE:392.75,MSR:1e3,MAR:630.75,MOZ:126.63,MMR:330.8,NAM:63.69,NRU:750,NPL:24.51,NLD:354.31,NCL:610.12,NZL:105.22,NIC:354.21,NER:622.22,NGA:368.11,"NORTH AMERICA":336.68,PRK:102.42,MKD:543.71,NOR:28.93,OCEANIA:450.73,OECD:341.08,OMN:488.27,PAK:344.16,PSE:465.12,PAN:152.68,PNG:526.75,PRY:25.49,PER:256.51,POL:633.23,PRT:234.61,PRI:612.39,QAT:490.28,REU:519.03,ROU:264.24,RUS:363.68,RWA:294.12,KNA:681.82,LCA:685.71,SPM:800,VCT:500,WSM:470.59,STP:600,SAU:557.78,SEN:523.13,SRB:582.13,SYC:615.39,SLE:47.62,SGP:488.78,SVK:140.14,SVN:237.38,SLB:727.27,SOM:634.15,ZAF:708.21,KOR:437.6,SSD:684.21,ESP:217.42,LKA:501.53,SDN:288.13,SUR:356.44,SWE:45.12,CHE:41.28,SYR:541.17,TWN:560.98,TJK:83.63,TZA:366.75,THA:501.57,PHL:594.45,TGO:460.32,TON:625,TTO:491.41,TUN:469.43,TUR:413.6,TKM:490.19,TCA:703.7,UGA:52.27,UKR:232.74,ARE:407.98,GBR:261.16,USA:368.1,URY:150.13,UZB:505.41,VUT:571.43,VEN:212.48,VNM:386.49,VGB:714.29,VIR:685.71,WORLD:437.66,YEM:559.66,ZMB:84.7,ZWE:392.28},k="average";var E={data:H,type:k};var D=.81,O=.52,S=.14,p=.15,P=.19,c=E.data.WORLD,f=50,g=.75,y=.25,N=.02;var R=a=>parseFloat(a.toFixed(2));function B(a){if(typeof a!="object")throw new Error("Options must be an object");let e={};if(a?.gridIntensity){e.gridIntensity={};let{device:t,dataCenter:n,network:r}=a.gridIntensity;(t||t===0)&&(typeof t=="object"?(E.data[t.country?.toUpperCase()]||(console.warn(`"${t.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. See https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity.`),e.gridIntensity.device={value:c}),e.gridIntensity.device={country:t.country,value:parseFloat(E.data[t.country?.toUpperCase()])}):typeof t=="number"?e.gridIntensity.device={value:t}:(e.gridIntensity.device={value:c},console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof t}. Falling back to global average grid intensity.`))),(n||n===0)&&(typeof n=="object"?(E.data[n.country?.toUpperCase()]||(console.warn(`"${n.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. From fcd392c2931fa02724234bc268294325aa875f38 Mon Sep 17 00:00:00 2001 From: fershad <27988517+fershad@users.noreply.github.com> Date: Tue, 9 Jan 2024 14:29:30 +0800 Subject: [PATCH 10/11] 0.14.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index dad42cb..d664b49 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@tgwf/co2", - "version": "0.13.10", + "version": "0.14.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@tgwf/co2", - "version": "0.13.10", + "version": "0.14.1", "license": "Apache-2.0", "devDependencies": { "@tgwf/url2green": "^0.4.0", diff --git a/package.json b/package.json index bcf9e8f..71503e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tgwf/co2", - "version": "0.13.10", + "version": "0.14.1", "description": "Work out the co2 of your digital services", "main": "dist/cjs/index-node.js", "module": "dist/esm/index.js", From 02464004d1afff53a4066e88758d61029956060c Mon Sep 17 00:00:00 2001 From: fershad <27988517+fershad@users.noreply.github.com> Date: Tue, 9 Jan 2024 16:49:57 +0800 Subject: [PATCH 11/11] update changelog --- CHANGELOG.md | 180 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 107 insertions(+), 73 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca0656d..de072ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,58 +12,92 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 > - **Fixed** for any bug fixes. > - **Security** in case of vulnerabilities. -# Unreleased +## Unreleased -- _(Add a summary of your feature, and if relevant the issue, in your PR for merging into `main`)_ +- Adds user agent header for requests to Green Web Foundation APIs + -# Released +## Released -## [0.13.8] - 2023-10-09 +### [0.14.1] - 2024-01-09 + +#### Changed + +- Removed `index.d.ts` in favour of importing type definitions from `@types/tgwf__co2`. +- Reduce package size by excluding files from publish NPM package. +- Automated monthly update of annual average grid intensity data. + +### [0.13.10] - 2023-12-16 + +#### Changed -- Fix: Properly use value of 0 for system segments and variables in the perByteTrace and perVisitTrace functions. - Automated monthly update of annual average grid intensity data. -## [0.13.7] - 2023-09-13 +### [0.13.9] - 2023-11-07 + +#### Fixed + +- Fix to return expected results when variables with 0 value are passed into function + +#### Changed - Automated monthly update of annual average grid intensity data. -## [0.13.6] - 2023-08-08 +### [0.13.8] - 2023-10-09 + +#### Fixed + +- Properly use value of 0 for system segments and variables in the perByteTrace and perVisitTrace functions. + +#### Changed + +- Automated monthly update of annual average grid intensity data. + +### [0.13.7] - 2023-09-13 + +#### Changed + +- Automated monthly update of annual average grid intensity data. + +### [0.13.6] - 2023-08-08 + +#### Changed - Automated monthly update of annual average grid intensity data. - Create FUNDING.yml to allow sponsor contribution to this project. - Store segment flag on CO2 instance, not models. -## [0.13.5] - 2023-07-5 +### [0.13.5] - 2023-07-5 -### Changed +#### Changed - Automated monthly update of annual average grid intensity data. -## [0.13.4] - 2023-05-24 +### [0.13.4] - 2023-05-24 -### Fixed +#### Fixed - Fixed an error when try to use global grid intensities in IIFE. (PR #147) -## [0.13.3] - 2023-05-18 +### [0.13.3] - 2023-05-18 -### Changed +#### Changed - Updated the global grid intensity constant to use the latest WORLD grid intensity value from Ember. (PR #142) -## [0.13.2] - 2023-04-21 +### [0.13.2] - 2023-04-21 - Fix to ensure that region names that are keys in the average annual grid intensity export are capitalised. -## [0.13.1] - 2023-04-20 +### [0.13.1] - 2023-04-20 -### Fixed +#### Fixed - Fixed the import of average grid intensities in node. (PR #137) -## [0.13.0] - 2023-04-13 +### [0.13.0] - 2023-04-13 -### Changed +#### Changed In PR #135 there were significant changes made to how average annual grid intensities are fetched and generated. @@ -73,59 +107,59 @@ In PR #135 there were significant changes made to how average annual grid intens - Get the _latest_ annual average values for each country/region. - Renamed the average grid intensities export file. -## [0.12.2] - 2023-03-01 +### [0.12.2] - 2023-03-01 -### Added +#### Added - Add a module declaration for use from typescript (PR #131) -### Changed +#### Changed - Updated 2021 average annual grid intensity values (PR #133) -## [0.12.1] - 2023-02-02 +### [0.12.1] - 2023-02-02 -### Fixed +#### Fixed - Removed incorrectly imported constants in tests. -## [0.12.0] - 2023-02-02 +### [0.12.0] - 2023-02-02 -### Added +#### Added - Introduced two new functions `perByteTrace` and `perVisitTrace` which allow developers to pass an options object containing customised values for the constants used in the Sustainable Web Design model. (PR #126) -### Changed +#### Changed - Allowed developers now have the option to return a breakdown of carbon emissions estimates by system segment when using the Sustainable Web Design model. (PR #113) -## [0.11.4] - 2022-12-02 +### [0.11.4] - 2022-12-02 -### Fixed +#### Fixed - Updated the `greenCheckMulti` function to work properly in ESM. (PR #123) -## [0.11.3] - 2022-10-13 +### [0.11.3] - 2022-10-13 -### Fixed +#### Fixed - Corrected the Node export for the hosting raised in issue #110. (PR #118) -## [0.11.2] - 2022-10-11 +### [0.11.2] - 2022-10-11 -### Fixed +#### Fixed - v0.11.x updates increased library size to 17MB + when published to NPM. This has been raised in [#108](https://github.com/thegreenwebfoundation/co2.js/issues/108) and it was found data files were being included in the published package. (PR #117) -## [0.11.1] - 2022-10-07 +### [0.11.1] - 2022-10-07 -### Changed +#### Changed - We have used generic filenames for data files, to avoid any confusion around the data being provided in this library. (PR #112) -## [0.11.0] - 2022-10-03 +### [0.11.0] - 2022-10-03 -### Added +#### Added - Introduced average and marginal carbon intensity data into the library. This comes from [Ember Climate](https://ember-climate.org/data/data-explorer/) (for average carbon intensity data), and [The Green Web Foundation](https://developers.thegreenwebfoundation.org/co2js/data) (marginal intensity data, originally sourced from the UNFCCC - the United Nations Framework Convention on Climate Change). For more, [see our release guide for v0.11](https://www.thegreenwebfoundation.org/news/release-guide-co2-js-v0-11/) about the differences between the kinds of data. See [#64](https://github.com/thegreenwebfoundation/co2.js/issues/64), and [#97](https://github.com/thegreenwebfoundation/co2.js/issues/97) for more. - Added new paths to `import` and `require` the annual, country-level average and marginal carbon intensity data mentioned above like, as javascript objects, or as JSON. See [#104 for more](https://github.com/thegreenwebfoundation/co2.js/issues/104). @@ -133,32 +167,32 @@ In PR #135 there were significant changes made to how average annual grid intens - Introduced scripts to automate the generation of grid intensity data based of Ember & UNFCCC source files. - Introduced a `release:minor` command, to automate the publishing process, to complement `release:patch`. -### Changed +#### Changed - Changed the default model for transfer based CO2 calculations from the _1byte_ model to the _Sustainable Web Design_ model instead. See for guidance on the differences and how to migrate between them. See [#94 for more](https://github.com/thegreenwebfoundation/co2.js/issues/94). - Updated our release commands to generate and format the carbon intensity data as part of the release process. -## [0.10.4] - 2022-08-12 +### [0.10.4] - 2022-08-12 -### Added +#### Added - Introduced a `release:patch` command, to automate the publishing process. This is designed to make sure we always publish the most recent compiled code, by adding a rebuild step that can be easy to forget. -## [0.10.3] - 2022-08-12 +### [0.10.3] - 2022-08-12 -### Added +#### Added - Introduced a new `perVisit()` function for the Sustainable Web Design model, which applies [caching and return visits assumptions](https://sustainablewebdesign.org/calculating-digital-emissions/). -## [0.10.2] - 2022-08-12 +### [0.10.2] - 2022-08-12 - Added the ability to set the model used by CO2.js to the Sustainable Web Design model, using a simple 'swd' string, instead of needing to pass in a class. -## [0.10.1] - 2022-08-01 +### [0.10.1] - 2022-08-01 This release used a version bump as previously we had released v0.10.0 under a pre-release tag. -## [0.10.0] - 2022-06-27 +### [0.10.0] - 2022-06-27 - Added ES import syntax as the main way for handling imports and exports of code within the module. - Changed eslint settings to use later version of ecmascript (2020) @@ -166,104 +200,104 @@ This release used a version bump as previously we had released v0.10.0 under a p - Added more consistent use of the debug logging library in files using the updated import syntax - Fixed the incorrect order of FIRST_TIME_VIEWING_PERCENTAGE and RETURNING_VISITOR_PERCENTAGE constants in the SWD model. This will result in **larger** values for calculations using the sustainable web design, and the default caching assumptions. -## [0.9.0] - 2022-03-28 +### [0.9.0] - 2022-03-28 -### Added +#### Added - Added newly implemented Sustainable Web Design model [thanks @dryden!] - Added new readme page for using both emissions models - Added new source of data to the Sustainable Web Design model from Ember Climate. -### Changed +#### Changed - Changed the CO2 class to accept either the One Byte model or the Sustainable Web Design model -### Fixed +#### Fixed - Fixed various typos. -## [0.8.0] - 2021-11-28 +### [0.8.0] - 2021-11-28 -###  Fixed +####  Fixed - Update further dependencies - Fix embarassing order of magnitude typo in 1byte model (thanks @mstaschik!) -## Added +#### Added - Read JSON blob also as gzipped #44 (thanks @soulgalore) -### Changed +#### Changed - The 1byte model will give different numbers now. It's mentioned in `#fixed` but it's worth repeating. -## [0.7.0] - 2021-11-28 +### [0.7.0] - 2021-11-28 -### Fixed +#### Fixed - Update tests to avoid network requests #50 - Update dependencies across the board -###  Changed +####  Changed - Switch to github actions instead of travis for CI. -## [0.6.1] - 2020-03-15 +### [0.6.1] - 2020-03-15 -### Fixed +#### Fixed - Added the function to load JSON, on the tgwg.hosting object, for use in the sustaiable web sitespeed plugin. -## [0.6.0] - 2020-03-15 +### [0.6.0] - 2020-03-15 -### Added +#### Added - Added the hosting-JSON for running local checks against an array instead of SQLite. -### Changed +#### Changed - Swapped out checking against a sqlite database `hosting-json`in favour of simple array in, - Updated conventions for style - using kebab-cases over CamelCase for naming files -### Removed +#### Removed - Extracted sqlite usage and dependencies into a separate module, `url2green`. This means you no longer need to compile SQLite on install. -## [0.5.0] - 2020-03-03 +### [0.5.0] - 2020-03-03 -### Changed +#### Changed - Updated README - Updated the emissions figured for green energy after further research on methodology with @@JamieBeevor - Incorporated class based CO2 models from @soulgalore - Credit contributors -## [0.4.7] - 2020-03-02 +### [0.4.7] - 2020-03-02 -### Added +#### Added - Added a changelog at last! -## [0.4.6] - 2020-03-01 +### [0.4.6] - 2020-03-01 -### Added +#### Added - Changelog inconsistency section in Bad Practices -## [0.4.4] - 2020-03-01 +### [0.4.4] - 2020-03-01 -### Added +#### Added Added the (currently unused) green byte model. -### Changed +#### Changed Update the 1byte model to use an average of devices, rather than just wifi -## [0.4.3] - 2020-03-01 +### [0.4.3] - 2020-03-01 -### Added +#### Added -### Changed +#### Changed Split hosting API into two separate files (one for sqlite, and one relying on the greencheck API)