@tgwf/co2 0.16.0 → 0.16.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/CHANGELOG.md +11 -2
- package/CONTRIBUTING.md +10 -10
- package/dist/cjs/1byte.js.map +1 -1
- package/dist/cjs/co2.js +47 -13
- package/dist/cjs/co2.js.map +3 -3
- package/dist/cjs/constants/index.js +4 -1
- package/dist/cjs/constants/index.js.map +2 -2
- package/dist/cjs/data/average-intensities.min.js +1 -1
- package/dist/cjs/data/average-intensities.min.js.map +2 -2
- package/dist/cjs/data/marginal-intensities-2021.min.js.map +2 -2
- package/dist/cjs/helpers/index.js +78 -38
- package/dist/cjs/helpers/index.js.map +2 -2
- package/dist/cjs/hosting-api.js +10 -4
- package/dist/cjs/hosting-api.js.map +2 -2
- package/dist/cjs/hosting-json.js.map +1 -1
- 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 +35 -12
- package/dist/cjs/hosting-node.js.map +2 -2
- package/dist/cjs/hosting.js +5 -4
- package/dist/cjs/hosting.js.map +3 -3
- 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-v3.js +30 -10
- package/dist/cjs/sustainable-web-design-v3.js.map +1 -1
- package/dist/cjs/sustainable-web-design-v4.js.map +2 -2
- package/dist/esm/co2.js +43 -13
- package/dist/esm/data/average-intensities.min.js +1 -1
- package/dist/esm/helpers/index.js +78 -38
- package/dist/esm/hosting-api.js +6 -4
- package/dist/esm/hosting-json.js +0 -1
- package/dist/esm/hosting.js +1 -4
- package/dist/esm/sustainable-web-design-v3.js +30 -11
- package/dist/esm/sustainable-web-design-v4.js +0 -1
- package/jsr.json +8 -0
- package/mod.ts +1 -0
- package/package.json +2 -2
|
@@ -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;
|
|
@@ -88,11 +87,19 @@ class SustainableWebDesign {
|
|
|
88
87
|
}
|
|
89
88
|
const energyBycomponent = this.energyPerByteByComponent(bytes, options);
|
|
90
89
|
if (typeof carbonIntensity !== "boolean") {
|
|
91
|
-
throw new Error(
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
throw new Error(
|
|
91
|
+
`perByte expects a boolean for the carbon intensity value. Received: ${carbonIntensity}`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
const co2ValuesbyComponent = this.co2byComponent(
|
|
95
|
+
energyBycomponent,
|
|
96
|
+
carbonIntensity,
|
|
97
|
+
options
|
|
98
|
+
);
|
|
94
99
|
const co2Values = Object.values(co2ValuesbyComponent);
|
|
95
|
-
const co2ValuesSum = co2Values.reduce(
|
|
100
|
+
const co2ValuesSum = co2Values.reduce(
|
|
101
|
+
(prevValue, currentValue) => prevValue + currentValue
|
|
102
|
+
);
|
|
96
103
|
let rating = null;
|
|
97
104
|
if (ratingResults) {
|
|
98
105
|
rating = this.ratingScale(co2ValuesSum);
|
|
@@ -114,11 +121,19 @@ class SustainableWebDesign {
|
|
|
114
121
|
perVisit(bytes, carbonIntensity = false, segmentResults = false, ratingResults = false, options = {}) {
|
|
115
122
|
const energyBycomponent = this.energyPerVisitByComponent(bytes, options);
|
|
116
123
|
if (typeof carbonIntensity !== "boolean") {
|
|
117
|
-
throw new Error(
|
|
118
|
-
|
|
119
|
-
|
|
124
|
+
throw new Error(
|
|
125
|
+
`perVisit expects a boolean for the carbon intensity value. Received: ${carbonIntensity}`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
const co2ValuesbyComponent = this.co2byComponent(
|
|
129
|
+
energyBycomponent,
|
|
130
|
+
carbonIntensity,
|
|
131
|
+
options
|
|
132
|
+
);
|
|
120
133
|
const co2Values = Object.values(co2ValuesbyComponent);
|
|
121
|
-
const co2ValuesSum = co2Values.reduce(
|
|
134
|
+
const co2ValuesSum = co2Values.reduce(
|
|
135
|
+
(prevValue, currentValue) => prevValue + currentValue
|
|
136
|
+
);
|
|
122
137
|
let rating = null;
|
|
123
138
|
if (ratingResults) {
|
|
124
139
|
rating = this.ratingScale(co2ValuesSum);
|
|
@@ -140,7 +155,9 @@ class SustainableWebDesign {
|
|
|
140
155
|
energyPerByte(bytes) {
|
|
141
156
|
const energyByComponent = this.energyPerByteByComponent(bytes);
|
|
142
157
|
const energyValues = Object.values(energyByComponent);
|
|
143
|
-
return energyValues.reduce(
|
|
158
|
+
return energyValues.reduce(
|
|
159
|
+
(prevValue, currentValue) => prevValue + currentValue
|
|
160
|
+
);
|
|
144
161
|
}
|
|
145
162
|
energyPerVisitByComponent(bytes, options = {}, firstView = FIRST_TIME_VIEWING_PERCENTAGE, returnView = RETURNING_VISITOR_PERCENTAGE, dataReloadRatio = PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD) {
|
|
146
163
|
if (options.dataReloadRatio || options.dataReloadRatio === 0) {
|
|
@@ -164,7 +181,9 @@ class SustainableWebDesign {
|
|
|
164
181
|
energyPerVisit(bytes) {
|
|
165
182
|
let firstVisits = 0;
|
|
166
183
|
let subsequentVisits = 0;
|
|
167
|
-
const energyBycomponent = Object.entries(
|
|
184
|
+
const energyBycomponent = Object.entries(
|
|
185
|
+
this.energyPerVisitByComponent(bytes)
|
|
186
|
+
);
|
|
168
187
|
for (const [key, val] of energyBycomponent) {
|
|
169
188
|
if (key.indexOf("first") > 0) {
|
|
170
189
|
firstVisits += val;
|
package/jsr.json
ADDED
package/mod.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tgwf/co2",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.2",
|
|
4
4
|
"description": "Work out the co2 of your digital services",
|
|
5
5
|
"main": "dist/cjs/index-node.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"author": "Chris Adams",
|
|
45
45
|
"license": "Apache-2.0",
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@tgwf/url2green": "^0.4.
|
|
47
|
+
"@tgwf/url2green": "^0.4.1",
|
|
48
48
|
"all-contributors-cli": "^6.26.1",
|
|
49
49
|
"esbuild": "^0.14.47",
|
|
50
50
|
"esbuild-jest": "^0.5.0",
|