@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.
Files changed (39) hide show
  1. package/CHANGELOG.md +11 -2
  2. package/CONTRIBUTING.md +10 -10
  3. package/dist/cjs/1byte.js.map +1 -1
  4. package/dist/cjs/co2.js +47 -13
  5. package/dist/cjs/co2.js.map +3 -3
  6. package/dist/cjs/constants/index.js +4 -1
  7. package/dist/cjs/constants/index.js.map +2 -2
  8. package/dist/cjs/data/average-intensities.min.js +1 -1
  9. package/dist/cjs/data/average-intensities.min.js.map +2 -2
  10. package/dist/cjs/data/marginal-intensities-2021.min.js.map +2 -2
  11. package/dist/cjs/helpers/index.js +78 -38
  12. package/dist/cjs/helpers/index.js.map +2 -2
  13. package/dist/cjs/hosting-api.js +10 -4
  14. package/dist/cjs/hosting-api.js.map +2 -2
  15. package/dist/cjs/hosting-json.js.map +1 -1
  16. package/dist/cjs/hosting-json.node.js +4 -1
  17. package/dist/cjs/hosting-json.node.js.map +2 -2
  18. package/dist/cjs/hosting-node.js +35 -12
  19. package/dist/cjs/hosting-node.js.map +2 -2
  20. package/dist/cjs/hosting.js +5 -4
  21. package/dist/cjs/hosting.js.map +3 -3
  22. package/dist/cjs/index-node.js +4 -1
  23. package/dist/cjs/index-node.js.map +2 -2
  24. package/dist/cjs/index.js +4 -1
  25. package/dist/cjs/index.js.map +2 -2
  26. package/dist/cjs/sustainable-web-design-v3.js +30 -10
  27. package/dist/cjs/sustainable-web-design-v3.js.map +1 -1
  28. package/dist/cjs/sustainable-web-design-v4.js.map +2 -2
  29. package/dist/esm/co2.js +43 -13
  30. package/dist/esm/data/average-intensities.min.js +1 -1
  31. package/dist/esm/helpers/index.js +78 -38
  32. package/dist/esm/hosting-api.js +6 -4
  33. package/dist/esm/hosting-json.js +0 -1
  34. package/dist/esm/hosting.js +1 -4
  35. package/dist/esm/sustainable-web-design-v3.js +30 -11
  36. package/dist/esm/sustainable-web-design-v4.js +0 -1
  37. package/jsr.json +8 -0
  38. package/mod.ts +1 -0
  39. 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(`perByte expects a boolean for the carbon intensity value. Received: ${carbonIntensity}`);
92
- }
93
- const co2ValuesbyComponent = this.co2byComponent(energyBycomponent, carbonIntensity, options);
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((prevValue, currentValue) => prevValue + currentValue);
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(`perVisit expects a boolean for the carbon intensity value. Received: ${carbonIntensity}`);
118
- }
119
- const co2ValuesbyComponent = this.co2byComponent(energyBycomponent, carbonIntensity, options);
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((prevValue, currentValue) => prevValue + currentValue);
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((prevValue, currentValue) => prevValue + currentValue);
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(this.energyPerVisitByComponent(bytes));
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;
@@ -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;
package/jsr.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@greenweb/co2js",
3
+ "version": "0.16.2",
4
+ "exports": "./mod.ts",
5
+ "exclude": [
6
+ "!dist/**"
7
+ ]
8
+ }
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.0",
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.0",
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",