@tgwf/co2 0.16.3 → 0.16.4
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 +28 -1
- package/README.md +7 -4
- package/dist/cjs/co2.js +10 -3
- package/dist/cjs/co2.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/helpers/index.js +35 -27
- package/dist/cjs/helpers/index.js.map +2 -2
- package/dist/esm/co2.js +13 -6
- package/dist/esm/data/average-intensities.min.js +1 -1
- package/dist/esm/helpers/index.js +35 -27
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -17,11 +17,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
17
17
|
- Add ability to create adaptors which provide access to external data sources #134
|
|
18
18
|
- Add access to the Electricity Maps API free tier #134
|
|
19
19
|
- Allow access to individual models and their internal functions #195
|
|
20
|
-
- Update the Github actions testing matrix to Node 18,20, and 22 #242
|
|
21
20
|
<!-- - _(Add a summary of your feature, and if relevant the issue, in your PR for merging into `main`)_ -->
|
|
22
21
|
|
|
23
22
|
## Released
|
|
24
23
|
|
|
24
|
+
### [0.16.3] - 2024-11-30
|
|
25
|
+
|
|
26
|
+
#### Fixed
|
|
27
|
+
|
|
28
|
+
- Include all gridIntensity values when running the perVisitTrace or perByteTrace functions. #237
|
|
29
|
+
|
|
30
|
+
### [0.16.2] - 2024-11-12
|
|
31
|
+
|
|
32
|
+
#### _Added_
|
|
33
|
+
|
|
34
|
+
- Add JSDoc comments to data generation scripts and outputs #230
|
|
35
|
+
- Added basic error handling to data fetch in emissions script #221
|
|
36
|
+
|
|
37
|
+
#### Fixed
|
|
38
|
+
|
|
39
|
+
- Bump url2green version #238
|
|
40
|
+
|
|
41
|
+
#### Changed
|
|
42
|
+
|
|
43
|
+
- Automated monthly update of annual average grid intensity data.
|
|
44
|
+
|
|
45
|
+
### [0.16.1] - 2024-09-10
|
|
46
|
+
|
|
47
|
+
#### Changed
|
|
48
|
+
|
|
49
|
+
- _[Experimental]_ Add minimum capability to publish CO2.js to JSR.
|
|
50
|
+
- Automated monthly update of annual average grid intensity data.
|
|
51
|
+
|
|
25
52
|
### [0.16.0] - 2024-07-01
|
|
26
53
|
|
|
27
54
|
#### _Added_
|
package/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# CO2.js
|
|
2
2
|
|
|
3
3
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
[](#contributors-)
|
|
6
|
+
|
|
5
7
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
6
8
|
|
|
7
9
|
<img src="https://github.com/thegreenwebfoundation/co2.js/actions/workflows/unittests.yml/badge.svg" />
|
|
@@ -34,12 +36,12 @@ You can install CO2.js as a dependency for your projects using NPM.
|
|
|
34
36
|
npm install @tgwf/co2
|
|
35
37
|
```
|
|
36
38
|
|
|
37
|
-
### Using
|
|
39
|
+
### Using esm.sh
|
|
38
40
|
|
|
39
|
-
You can import the CO2.js library into projects using
|
|
41
|
+
You can import the CO2.js library into projects using esm.sh.
|
|
40
42
|
|
|
41
43
|
```js
|
|
42
|
-
import tgwf from "https://
|
|
44
|
+
import tgwf from "https://esm.sh/@tgwf/co2@latest";
|
|
43
45
|
```
|
|
44
46
|
|
|
45
47
|
## Using a JS CDN
|
|
@@ -165,6 +167,7 @@ To contribute changes back to this project, please follow the steps outlined in
|
|
|
165
167
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/APJohns"><img src="https://avatars.githubusercontent.com/u/18357173?v=4?s=100" width="100px;" alt="Ash Johns"/><br /><sub><b>Ash Johns</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/issues?q=author%3AAPJohns" title="Bug reports">🐛</a> <a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=APJohns" title="Code">💻</a></td>
|
|
166
168
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mgriffin-scottlogic"><img src="https://avatars.githubusercontent.com/u/117279304?v=4?s=100" width="100px;" alt="Matthew Griffin"/><br /><sub><b>Matthew Griffin</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=mgriffin-scottlogic" title="Documentation">📖</a> <a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=mgriffin-scottlogic" title="Code">💻</a></td>
|
|
167
169
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/hanopcan"><img src="https://avatars.githubusercontent.com/u/11687898?v=4?s=100" width="100px;" alt="Hannah"/><br /><sub><b>Hannah</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=hanopcan" title="Documentation">📖</a></td>
|
|
170
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/alexzurbonsen"><img src="https://avatars.githubusercontent.com/u/82914459?v=4?s=100" width="100px;" alt="Alex"/><br /><sub><b>Alex</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=alexzurbonsen" title="Code">💻</a></td>
|
|
168
171
|
</tr>
|
|
169
172
|
</tbody>
|
|
170
173
|
</table>
|
package/dist/cjs/co2.js
CHANGED
|
@@ -31,7 +31,6 @@ module.exports = __toCommonJS(co2_exports);
|
|
|
31
31
|
var import_byte = __toESM(require("./1byte.js"));
|
|
32
32
|
var import_sustainable_web_design_v3 = __toESM(require("./sustainable-web-design-v3.js"));
|
|
33
33
|
var import_sustainable_web_design_v4 = __toESM(require("./sustainable-web-design-v4.js"));
|
|
34
|
-
var import_constants = require("./constants/index.js");
|
|
35
34
|
var import_helpers = require("./helpers/index.js");
|
|
36
35
|
class CO2 {
|
|
37
36
|
constructor(options) {
|
|
@@ -80,7 +79,11 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
|
|
|
80
79
|
}
|
|
81
80
|
}
|
|
82
81
|
perByteTrace(bytes, green = false, options = {}) {
|
|
83
|
-
const adjustments = (0, import_helpers.
|
|
82
|
+
const adjustments = (0, import_helpers.parseByteTraceOptions)(
|
|
83
|
+
options,
|
|
84
|
+
this.model.version,
|
|
85
|
+
green
|
|
86
|
+
);
|
|
84
87
|
const { gridIntensity, ...traceVariables } = adjustments;
|
|
85
88
|
const {
|
|
86
89
|
dataReloadRatio,
|
|
@@ -111,7 +114,11 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
|
|
|
111
114
|
perVisitTrace(bytes, green = false, options = {}) {
|
|
112
115
|
var _a;
|
|
113
116
|
if ((_a = this.model) == null ? void 0 : _a.perVisit) {
|
|
114
|
-
const adjustments = (0, import_helpers.
|
|
117
|
+
const adjustments = (0, import_helpers.parseVisitTraceOptions)(
|
|
118
|
+
options,
|
|
119
|
+
this.model.version,
|
|
120
|
+
green
|
|
121
|
+
);
|
|
115
122
|
const { gridIntensity, ...variables } = adjustments;
|
|
116
123
|
return {
|
|
117
124
|
co2: this.model.perVisit(
|
package/dist/cjs/co2.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/co2.js"],
|
|
4
|
-
"sourcesContent": ["\"use strict\";\n\n/**\n * @typedef {Object} CO2EstimateTraceResultPerByte\n * @property {number|CO2EstimateComponentsPerByte} co2 - The CO2 estimate in grams or its separate components\n * @property {boolean} green - Whether the domain is green or not\n * @property {TraceResultVariablesPerByte} variables - The variables used to calculate the CO2 estimate\n */\n\n/**\n * @typedef {Object} CO2EstimateTraceResultPerVisit\n * @property {number|CO2EstimateComponentsPerVisit} co2 - The CO2 estimate in grams or its separate components\n * @property {boolean} green - Whether the domain is green or not\n * @property {TraceResultVariablesPerVisit} variables - The variables used to calculate the CO2 estimate\n */\n\n/**\n * @typedef {Object} TraceResultVariablesPerByte\n * @property {GridIntensityVariables} gridIntensity - The grid intensity related variables\n */\n/**\n * @typedef {Object} TraceResultVariablesPerVisit\n * @property {GridIntensityVariables} gridIntensity - The grid intensity related variables\n * @property {number} dataReloadRatio - What percentage of a page is reloaded on each subsequent page view\n * @property {number} firstVisitPercentage - What percentage of visits are loading this page for subsequent times\n * @property {number} returnVisitPercentage - What percentage of visits are loading this page for the second or more time\n */\n\n/**\n * @typedef {Object} GridIntensityVariables\n * @property {string} description - The description of the variables\n * @property {number} network - The network grid intensity set by the user or the default\n * @property {number} dataCenter - The data center grid intensity set by the user or the default\n * @property {number} device - The device grid intensity set by the user or the default\n * @property {number} production - The production grid intensity set by the user or the default\n */\n\n/**\n * @typedef {Object} CO2EstimateComponentsPerByte\n * @property {number} networkCO2 - The CO2 estimate for networking in grams\n * @property {number} dataCenterCO2 - The CO2 estimate for data centers in grams\n * @property {number} consumerDeviceCO2 - The CO2 estimate for consumer devices in grams\n * @property {number} productionCO2 - The CO2 estimate for device production in grams\n * @property {string} rating - The rating of the CO2 estimate based on the Sustainable Web Design Model\n * @property {number} total - The total CO2 estimate in grams\n */\n\n/**\n * @typedef {Object} CO2EstimateComponentsPerVisit\n * @property {number} 'networkCO2 - first' - The CO2 estimate for networking in grams on first visit\n * @property {number} 'networkCO2 - subsequent' - The CO2 estimate for networking in grams on subsequent visits\n * @property {number} 'dataCenterCO2 - first' - The CO2 estimate for data centers in grams on first visit\n * @property {number} 'dataCenterCO2 - subsequent' - The CO2 estimate for data centers in grams on subsequent visits\n * @property {number} 'consumerDeviceCO2 - first' - The CO2 estimate for consumer devices in grams on first visit\n * @property {number} 'consumerDeviceCO2 - subsequent' - The CO2 estimate for consumer devices in grams on subsequent visits\n * @property {number} 'productionCO2 - first' - The CO2 estimate for device production in grams on first visit\n * @property {number} 'productionCO2 - subsequent' - The CO2 estimate for device production in grams on subsequent visits\n * @property {string} rating - The rating of the CO2 estimate based on the Sustainable Web Design Model\n * @property {number} total - The total CO2 estimate in grams\n */\n\nimport OneByte from \"./1byte.js\";\nimport SustainableWebDesignV3 from \"./sustainable-web-design-v3.js\";\nimport SustainableWebDesignV4 from \"./sustainable-web-design-v4.js\";\n\nimport {\n GLOBAL_GRID_INTENSITY,\n RENEWABLES_GRID_INTENSITY,\n} from \"./constants/index.js\";\nimport { parseOptions } from \"./helpers/index.js\";\n\nclass CO2 {\n constructor(options) {\n this.model = new SustainableWebDesignV3();\n // Using optional chaining allows an empty object to be passed\n // in without breaking the code.\n if (options?.model === \"1byte\") {\n this.model = new OneByte();\n } else if (options?.model === \"swd\") {\n this.model = new SustainableWebDesignV3();\n if (options?.version === 4) {\n this.model = new SustainableWebDesignV4();\n }\n } else if (options?.model) {\n throw new Error(\n `\"${options.model}\" is not a valid model. Please use \"1byte\" for the OneByte model, and \"swd\" for the Sustainable Web Design model.\\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`\n );\n }\n\n if (options?.rating && typeof options.rating !== \"boolean\") {\n throw new Error(\n `The rating option must be a boolean. Please use true or false.\\nSee https://developers.thegreenwebfoundation.org/co2js/options/ to learn more about the options available in CO2.js.`\n );\n }\n\n // This flag checks to see if the model itself has a rating system.\n const allowRatings = !!this.model.allowRatings;\n\n /** @private */\n this._segment = options?.results === \"segment\";\n // This flag is set by the user to enable the rating system.\n this._rating = options?.rating === true;\n\n // The rating system is only supported in the Sustainable Web Design Model.\n if (!allowRatings && this._rating) {\n throw new Error(\n `The rating system is not supported in the model you are using. Try using the Sustainable Web Design model instead.\\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`\n );\n }\n }\n\n /**\n * Accept a figure in bytes for data transfer, and a boolean for whether\n * the domain shows as 'green', and return a CO2 figure for energy used to shift the corresponding\n * the data transfer.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @return {number|CO2EstimateComponentsPerByte} the amount of CO2 in grammes or its separate components\n */\n perByte(bytes, green = false) {\n return this.model.perByte(bytes, green, this._segment, this._rating);\n }\n\n /**\n * Accept a figure in bytes for data transfer, and a boolean for whether\n * the domain shows as 'green', and return a CO2 figure for energy used to shift the corresponding\n * the data transfer.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @return {number|CO2EstimateComponentsPerVisit} the amount of CO2 in grammes or its separate components\n */\n perVisit(bytes, green = false) {\n if (this.model?.perVisit) {\n return this.model.perVisit(bytes, green, this._segment, this._rating);\n } else {\n throw new Error(\n `The perVisit() method is not supported in the model you are using. Try using perByte() instead.\\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`\n );\n }\n }\n\n /**\n * Accept a figure in bytes for data transfer, a boolean for whether\n * the domain shows as 'green', and an options object.\n * Returns an object containing CO2 figure, green boolean, and object of the variables used in calculating the CO2 figure.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @param {Object} options\n * @return {CO2EstimateTraceResultPerByte} the amount of CO2 in grammes\n */\n perByteTrace(bytes, green = false, options = {}) {\n const adjustments = parseOptions(options, this.model.version, green);\n\n // Filter out the trace items that aren't relevant to this function.\n const { gridIntensity, ...traceVariables } = adjustments;\n const {\n dataReloadRatio,\n firstVisitPercentage,\n returnVisitPercentage,\n ...otherVariables\n } = traceVariables;\n return {\n co2: this.model.perByte(\n bytes,\n green,\n this._segment,\n this._rating,\n adjustments\n ),\n green,\n variables: {\n description:\n \"Below are the variables used to calculate this CO2 estimate.\",\n bytes,\n gridIntensity: {\n description:\n \"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.\",\n ...adjustments.gridIntensity,\n },\n ...otherVariables,\n },\n };\n }\n\n /**\n * Accept a figure in bytes for data transfer, a boolean for whether\n * the domain shows as 'green', and an options object.\n * Returns an object containing CO2 figure, green boolean, and object of the variables used in calculating the CO2 figure.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @param {Object} options\n * @return {CO2EstimateTraceResultPerVisit} the amount of CO2 in grammes\n */\n perVisitTrace(bytes, green = false, options = {}) {\n if (this.model?.perVisit) {\n const adjustments = parseOptions(options, this.model.version, green);\n const { gridIntensity, ...variables } = adjustments;\n\n return {\n co2: this.model.perVisit(\n bytes,\n green,\n this._segment,\n this._rating,\n adjustments\n ),\n green,\n variables: {\n description:\n \"Below are the variables used to calculate this CO2 estimate.\",\n bytes,\n gridIntensity: {\n description:\n \"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.\",\n ...adjustments.gridIntensity,\n },\n ...variables,\n },\n };\n } else {\n throw new Error(\n `The perVisitTrace() method is not supported in the model you are using. Try using perByte() instead.\\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`\n );\n }\n }\n\n SustainableWebDesignV3() {\n return new SustainableWebDesignV3();\n }\n\n SustainableWebDesignV4() {\n return new SustainableWebDesignV4();\n }\n\n OneByte() {\n return new OneByte();\n }\n}\n\nexport { CO2 };\nexport default CO2;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6DA,kBAAoB;AACpB,uCAAmC;AACnC,uCAAmC;AAEnC,
|
|
4
|
+
"sourcesContent": ["\"use strict\";\n\n/**\n * @typedef {Object} CO2EstimateTraceResultPerByte\n * @property {number|CO2EstimateComponentsPerByte} co2 - The CO2 estimate in grams or its separate components\n * @property {boolean} green - Whether the domain is green or not\n * @property {TraceResultVariablesPerByte} variables - The variables used to calculate the CO2 estimate\n */\n\n/**\n * @typedef {Object} CO2EstimateTraceResultPerVisit\n * @property {number|CO2EstimateComponentsPerVisit} co2 - The CO2 estimate in grams or its separate components\n * @property {boolean} green - Whether the domain is green or not\n * @property {TraceResultVariablesPerVisit} variables - The variables used to calculate the CO2 estimate\n */\n\n/**\n * @typedef {Object} TraceResultVariablesPerByte\n * @property {GridIntensityVariables} gridIntensity - The grid intensity related variables\n */\n/**\n * @typedef {Object} TraceResultVariablesPerVisit\n * @property {GridIntensityVariables} gridIntensity - The grid intensity related variables\n * @property {number} dataReloadRatio - What percentage of a page is reloaded on each subsequent page view\n * @property {number} firstVisitPercentage - What percentage of visits are loading this page for subsequent times\n * @property {number} returnVisitPercentage - What percentage of visits are loading this page for the second or more time\n */\n\n/**\n * @typedef {Object} GridIntensityVariables\n * @property {string} description - The description of the variables\n * @property {number} network - The network grid intensity set by the user or the default\n * @property {number} dataCenter - The data center grid intensity set by the user or the default\n * @property {number} device - The device grid intensity set by the user or the default\n * @property {number} production - The production grid intensity set by the user or the default\n */\n\n/**\n * @typedef {Object} CO2EstimateComponentsPerByte\n * @property {number} networkCO2 - The CO2 estimate for networking in grams\n * @property {number} dataCenterCO2 - The CO2 estimate for data centers in grams\n * @property {number} consumerDeviceCO2 - The CO2 estimate for consumer devices in grams\n * @property {number} productionCO2 - The CO2 estimate for device production in grams\n * @property {string} rating - The rating of the CO2 estimate based on the Sustainable Web Design Model\n * @property {number} total - The total CO2 estimate in grams\n */\n\n/**\n * @typedef {Object} CO2EstimateComponentsPerVisit\n * @property {number} 'networkCO2 - first' - The CO2 estimate for networking in grams on first visit\n * @property {number} 'networkCO2 - subsequent' - The CO2 estimate for networking in grams on subsequent visits\n * @property {number} 'dataCenterCO2 - first' - The CO2 estimate for data centers in grams on first visit\n * @property {number} 'dataCenterCO2 - subsequent' - The CO2 estimate for data centers in grams on subsequent visits\n * @property {number} 'consumerDeviceCO2 - first' - The CO2 estimate for consumer devices in grams on first visit\n * @property {number} 'consumerDeviceCO2 - subsequent' - The CO2 estimate for consumer devices in grams on subsequent visits\n * @property {number} 'productionCO2 - first' - The CO2 estimate for device production in grams on first visit\n * @property {number} 'productionCO2 - subsequent' - The CO2 estimate for device production in grams on subsequent visits\n * @property {string} rating - The rating of the CO2 estimate based on the Sustainable Web Design Model\n * @property {number} total - The total CO2 estimate in grams\n */\n\nimport OneByte from \"./1byte.js\";\nimport SustainableWebDesignV3 from \"./sustainable-web-design-v3.js\";\nimport SustainableWebDesignV4 from \"./sustainable-web-design-v4.js\";\n\nimport {\n parseByteTraceOptions,\n parseVisitTraceOptions,\n} from \"./helpers/index.js\";\n\nclass CO2 {\n constructor(options) {\n this.model = new SustainableWebDesignV3();\n // Using optional chaining allows an empty object to be passed\n // in without breaking the code.\n if (options?.model === \"1byte\") {\n this.model = new OneByte();\n } else if (options?.model === \"swd\") {\n this.model = new SustainableWebDesignV3();\n if (options?.version === 4) {\n this.model = new SustainableWebDesignV4();\n }\n } else if (options?.model) {\n throw new Error(\n `\"${options.model}\" is not a valid model. Please use \"1byte\" for the OneByte model, and \"swd\" for the Sustainable Web Design model.\\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`\n );\n }\n\n if (options?.rating && typeof options.rating !== \"boolean\") {\n throw new Error(\n `The rating option must be a boolean. Please use true or false.\\nSee https://developers.thegreenwebfoundation.org/co2js/options/ to learn more about the options available in CO2.js.`\n );\n }\n\n // This flag checks to see if the model itself has a rating system.\n const allowRatings = !!this.model.allowRatings;\n\n /** @private */\n this._segment = options?.results === \"segment\";\n // This flag is set by the user to enable the rating system.\n this._rating = options?.rating === true;\n\n // The rating system is only supported in the Sustainable Web Design Model.\n if (!allowRatings && this._rating) {\n throw new Error(\n `The rating system is not supported in the model you are using. Try using the Sustainable Web Design model instead.\\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`\n );\n }\n }\n\n /**\n * Accept a figure in bytes for data transfer, and a boolean for whether\n * the domain shows as 'green', and return a CO2 figure for energy used to shift the corresponding\n * the data transfer.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @return {number|CO2EstimateComponentsPerByte} the amount of CO2 in grammes or its separate components\n */\n perByte(bytes, green = false) {\n return this.model.perByte(bytes, green, this._segment, this._rating);\n }\n\n /**\n * Accept a figure in bytes for data transfer, and a boolean for whether\n * the domain shows as 'green', and return a CO2 figure for energy used to shift the corresponding\n * the data transfer.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @return {number|CO2EstimateComponentsPerVisit} the amount of CO2 in grammes or its separate components\n */\n perVisit(bytes, green = false) {\n if (this.model?.perVisit) {\n return this.model.perVisit(bytes, green, this._segment, this._rating);\n } else {\n throw new Error(\n `The perVisit() method is not supported in the model you are using. Try using perByte() instead.\\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`\n );\n }\n }\n\n /**\n * Accept a figure in bytes for data transfer, a boolean for whether\n * the domain shows as 'green', and an options object.\n * Returns an object containing CO2 figure, green boolean, and object of the variables used in calculating the CO2 figure.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @param {Object} options\n * @return {CO2EstimateTraceResultPerByte} the amount of CO2 in grammes\n */\n perByteTrace(bytes, green = false, options = {}) {\n const adjustments = parseByteTraceOptions(\n options,\n this.model.version,\n green\n );\n\n // Filter out the trace items that aren't relevant to this function.\n const { gridIntensity, ...traceVariables } = adjustments;\n const {\n dataReloadRatio,\n firstVisitPercentage,\n returnVisitPercentage,\n ...otherVariables\n } = traceVariables;\n return {\n co2: this.model.perByte(\n bytes,\n green,\n this._segment,\n this._rating,\n adjustments\n ),\n green,\n variables: {\n description:\n \"Below are the variables used to calculate this CO2 estimate.\",\n bytes,\n gridIntensity: {\n description:\n \"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.\",\n ...adjustments.gridIntensity,\n },\n ...otherVariables,\n },\n };\n }\n\n /**\n * Accept a figure in bytes for data transfer, a boolean for whether\n * the domain shows as 'green', and an options object.\n * Returns an object containing CO2 figure, green boolean, and object of the variables used in calculating the CO2 figure.\n *\n * @param {number} bytes\n * @param {boolean} green\n * @param {Object} options\n * @return {CO2EstimateTraceResultPerVisit} the amount of CO2 in grammes\n */\n perVisitTrace(bytes, green = false, options = {}) {\n if (this.model?.perVisit) {\n const adjustments = parseVisitTraceOptions(\n options,\n this.model.version,\n green\n );\n const { gridIntensity, ...variables } = adjustments;\n\n return {\n co2: this.model.perVisit(\n bytes,\n green,\n this._segment,\n this._rating,\n adjustments\n ),\n green,\n variables: {\n description:\n \"Below are the variables used to calculate this CO2 estimate.\",\n bytes,\n gridIntensity: {\n description:\n \"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.\",\n ...adjustments.gridIntensity,\n },\n ...variables,\n },\n };\n } else {\n throw new Error(\n `The perVisitTrace() method is not supported in the model you are using. Try using perByte() instead.\\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`\n );\n }\n }\n\n SustainableWebDesignV3() {\n return new SustainableWebDesignV3();\n }\n\n SustainableWebDesignV4() {\n return new SustainableWebDesignV4();\n }\n\n OneByte() {\n return new OneByte();\n }\n}\n\nexport { CO2 };\nexport default CO2;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6DA,kBAAoB;AACpB,uCAAmC;AACnC,uCAAmC;AAEnC,qBAGO;AAEP,MAAM,IAAI;AAAA,EACR,YAAY,SAAS;AACnB,SAAK,QAAQ,IAAI,iCAAAA,QAAuB;AAGxC,SAAI,mCAAS,WAAU,SAAS;AAC9B,WAAK,QAAQ,IAAI,YAAAC,QAAQ;AAAA,IAC3B,YAAW,mCAAS,WAAU,OAAO;AACnC,WAAK,QAAQ,IAAI,iCAAAD,QAAuB;AACxC,WAAI,mCAAS,aAAY,GAAG;AAC1B,aAAK,QAAQ,IAAI,iCAAAE,QAAuB;AAAA,MAC1C;AAAA,IACF,WAAW,mCAAS,OAAO;AACzB,YAAM,IAAI;AAAA,QACR,IAAI,QAAQ;AAAA;AAAA,MACd;AAAA,IACF;AAEA,SAAI,mCAAS,WAAU,OAAO,QAAQ,WAAW,WAAW;AAC1D,YAAM,IAAI;AAAA,QACR;AAAA;AAAA,MACF;AAAA,IACF;AAGA,UAAM,eAAe,CAAC,CAAC,KAAK,MAAM;AAGlC,SAAK,YAAW,mCAAS,aAAY;AAErC,SAAK,WAAU,mCAAS,YAAW;AAGnC,QAAI,CAAC,gBAAgB,KAAK,SAAS;AACjC,YAAM,IAAI;AAAA,QACR;AAAA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAWA,QAAQ,OAAO,QAAQ,OAAO;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F;AAAA,UACA,eAAe;AAAA,YACb,aACE;AAAA,YACF,GAAG,YAAY;AAAA,UACjB;AAAA,UACA,GAAG;AAAA,QACL;AAAA,MACF;AAAA,IACF,OAAO;AACL,YAAM,IAAI;AAAA,QACR;AAAA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,yBAAyB;AACvB,WAAO,IAAI,iCAAAF,QAAuB;AAAA,EACpC;AAAA,EAEA,yBAAyB;AACvB,WAAO,IAAI,iCAAAE,QAAuB;AAAA,EACpC;AAAA,EAEA,UAAU;AACR,WAAO,IAAI,YAAAD,QAAQ;AAAA,EACrB;AACF;AAGA,IAAO,cAAQ;",
|
|
6
6
|
"names": ["SustainableWebDesignV3", "OneByte", "SustainableWebDesignV4"]
|
|
7
7
|
}
|
|
@@ -22,7 +22,7 @@ __export(average_intensities_min_exports, {
|
|
|
22
22
|
type: () => type
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(average_intensities_min_exports);
|
|
25
|
-
const data = { "AFG": 132.53, "AFRICA": 547.83, "ALB": 24.29, "DZA": 634.61, "ASM": 611.11, "AGO": 174.73, "ATG": 611.11, "ARG": 353.96, "ARM": 264.54, "ABW": 561.22, "ASEAN": 570.
|
|
25
|
+
const data = { "AFG": 132.53, "AFRICA": 547.83, "ALB": 24.29, "DZA": 634.61, "ASM": 611.11, "AGO": 174.73, "ATG": 611.11, "ARG": 353.96, "ARM": 264.54, "ABW": 561.22, "ASEAN": 570.43, "ASIA": 591.02, "AUS": 556.3, "AUT": 110.14, "AZE": 671.39, "BHS": 660.1, "BHR": 904.62, "BGD": 691.41, "BRB": 605.51, "BLR": 441.74, "BEL": 138.11, "BLZ": 225.81, "BEN": 584.07, "BTN": 23.33, "BOL": 531.69, "BIH": 600.94, "BWA": 847.91, "BRA": 96.4, "BRN": 893.91, "BGR": 335.33, "BFA": 467.53, "BDI": 250, "CPV": 558.14, "KHM": 417.71, "CMR": 305.42, "CAN": 165.15, "CYM": 642.86, "CAF": 0, "TCD": 628.57, "CHL": 291.11, "CHN": 583.61, "COL": 259.51, "COM": 642.86, "COG": 700, "COD": 24.46, "COK": 250, "CRI": 53.38, "CIV": 393.89, "HRV": 202.68, "CUB": 637.61, "CYP": 526.02, "CZE": 449.72, "DNK": 151.65, "DJI": 692.31, "DMA": 529.41, "DOM": 578.41, "ECU": 166.91, "EGY": 574.04, "SLV": 224.76, "GNQ": 591.84, "ERI": 631.58, "EST": 416.67, "SWZ": 172.41, "ETH": 24.64, "EU": 243.55, "EUROPE": 302.09, "FLK": 500, "FRO": 404.76, "FJI": 288.46, "FIN": 79.39, "FRA": 56.02, "GUF": 217.82, "PYF": 442.86, "G20": 477.79, "G7": 341.49, "GAB": 491.6, "GMB": 666.67, "GEO": 167.59, "DEU": 381.41, "GHA": 484, "GRC": 336.57, "GRL": 178.57, "GRD": 640, "GLP": 500, "GUM": 622.86, "GTM": 328.27, "GIN": 236.84, "GNB": 625, "GUY": 640.35, "HTI": 567.31, "HND": 282.27, "HKG": 699.5, "HUN": 204.01, "ISL": 27.68, "IND": 713.01, "IDN": 682.43, "IRN": 641.73, "IRQ": 688.81, "IRL": 283.71, "ISR": 582.93, "ITA": 330.72, "JAM": 555.56, "JPN": 493.59, "JOR": 540.92, "KAZ": 821.9, "KEN": 71.2, "KIR": 666.67, "XKX": 894.65, "KWT": 649.16, "KGZ": 147.29, "LAO": 265.51, "LATIN AMERICA AND CARIBBEAN": 259.77, "LVA": 123.99, "LBN": 599.01, "LSO": 20, "LBR": 227.85, "LBY": 818.69, "LTU": 160.07, "LUX": 105.26, "MAC": 448.98, "MDG": 436.44, "MWI": 66.67, "MYS": 607.88, "MDV": 611.77, "MLI": 408, "MLT": 444.03, "MTQ": 523.18, "MRT": 464.71, "MUS": 632.48, "MEX": 492.34, "MIDDLE EAST": 643.04, "MDA": 643.46, "MNG": 775.31, "MNE": 418.09, "MSR": 1e3, "MAR": 624.45, "MOZ": 135.65, "MMR": 440.37, "NAM": 59.26, "NRU": 750, "NPL": 24.44, "NLD": 268.48, "NCL": 660.58, "NZL": 112.76, "NIC": 265.12, "NER": 670.89, "NGA": 523.25, "NORTH AMERICA": 343.03, "PRK": 389.59, "MKD": 539.55, "NOR": 30.05, "OCEANIA": 495.74, "OECD": 341.25, "OMN": 564.55, "PAK": 440.61, "PSE": 516.13, "PAN": 161.68, "PNG": 507.25, "PRY": 24.31, "PER": 266.48, "POL": 661.93, "PRT": 164.86, "PRI": 677.96, "QAT": 602.5, "REU": 572.82, "ROU": 238.65, "RUS": 445.02, "RWA": 316.33, "KNA": 636.36, "LCA": 666.67, "SPM": 600, "VCT": 529.41, "WSM": 473.68, "STP": 642.86, "SAU": 696.31, "SEN": 511.6, "SRB": 648.2, "SYC": 564.52, "SLE": 50, "SGP": 470.87, "SVK": 116.77, "SVN": 230.87, "SLB": 700, "SOM": 578.95, "ZAF": 709.69, "KOR": 432.11, "SSD": 629.03, "ESP": 172.2, "LKA": 509.78, "SDN": 263.16, "SUR": 349.28, "SWE": 40.77, "CHE": 29.56, "SYR": 701.66, "TWN": 644.36, "TJK": 116.86, "TZA": 339.25, "THA": 549.85, "PHL": 610.74, "TGO": 443.18, "TON": 625, "TTO": 681.53, "TUN": 563.96, "TUR": 464.59, "TKM": 1306.03, "TCA": 653.85, "UGA": 44.53, "UKR": 256.21, "ARE": 492.7, "GBR": 228.25, "USA": 369.53, "URY": 128.79, "UZB": 1167.6, "VUT": 571.43, "VEN": 185.8, "VNM": 472.47, "VGB": 647.06, "VIR": 632.35, "WORLD": 481.6, "YEM": 566.1, "ZMB": 111.97, "ZWE": 297.87 };
|
|
26
26
|
const type = "average";
|
|
27
27
|
var average_intensities_min_default = { data, type };
|
|
28
28
|
//# sourceMappingURL=average-intensities.min.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/data/average-intensities.min.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview Minified average CO2 emissions intensity data for countries.\n * @generated Generated by generate_average_co2.js\n * @version 1.0.0\n*/\n/**\n * @constant {Object.<string, number>} data - Average CO2 emissions intensity data for various countries.\n * @constant {string} type - Type of data being represented.\n */\n const data = {\"AFG\":132.53,\"AFRICA\":547.83,\"ALB\":24.29,\"DZA\":634.61,\"ASM\":611.11,\"AGO\":174.73,\"ATG\":611.11,\"ARG\":353.96,\"ARM\":264.54,\"ABW\":561.22,\"ASEAN\":570.
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASM,MAAM,OAAO,EAAC,OAAM,QAAO,UAAS,QAAO,OAAM,OAAM,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,SAAQ,QAAO,QAAO,QAAO,OAAM,OAAM,OAAM,QAAO,OAAM,QAAO,OAAM,OAAM,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,OAAM,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,MAAK,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,KAAI,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,GAAE,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,KAAI,OAAM,OAAM,OAAM,KAAI,OAAM,OAAM,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,OAAM,MAAK,QAAO,UAAS,QAAO,OAAM,KAAI,OAAM,QAAO,OAAM,QAAO,OAAM,OAAM,OAA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M,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,OAAM,OAAM,OAAM,OAAM,QAAO,OAAM,IAAG,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,KAAI,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview Minified average CO2 emissions intensity data for countries.\n * @generated Generated by generate_average_co2.js\n * @version 1.0.0\n*/\n/**\n * @constant {Object.<string, number>} data - Average CO2 emissions intensity data for various countries.\n * @constant {string} type - Type of data being represented.\n */\n const data = {\"AFG\":132.53,\"AFRICA\":547.83,\"ALB\":24.29,\"DZA\":634.61,\"ASM\":611.11,\"AGO\":174.73,\"ATG\":611.11,\"ARG\":353.96,\"ARM\":264.54,\"ABW\":561.22,\"ASEAN\":570.43,\"ASIA\":591.02,\"AUS\":556.3,\"AUT\":110.14,\"AZE\":671.39,\"BHS\":660.1,\"BHR\":904.62,\"BGD\":691.41,\"BRB\":605.51,\"BLR\":441.74,\"BEL\":138.11,\"BLZ\":225.81,\"BEN\":584.07,\"BTN\":23.33,\"BOL\":531.69,\"BIH\":600.94,\"BWA\":847.91,\"BRA\":96.4,\"BRN\":893.91,\"BGR\":335.33,\"BFA\":467.53,\"BDI\":250,\"CPV\":558.14,\"KHM\":417.71,\"CMR\":305.42,\"CAN\":165.15,\"CYM\":642.86,\"CAF\":0,\"TCD\":628.57,\"CHL\":291.11,\"CHN\":583.61,\"COL\":259.51,\"COM\":642.86,\"COG\":700,\"COD\":24.46,\"COK\":250,\"CRI\":53.38,\"CIV\":393.89,\"HRV\":202.68,\"CUB\":637.61,\"CYP\":526.02,\"CZE\":449.72,\"DNK\":151.65,\"DJI\":692.31,\"DMA\":529.41,\"DOM\":578.41,\"ECU\":166.91,\"EGY\":574.04,\"SLV\":224.76,\"GNQ\":591.84,\"ERI\":631.58,\"EST\":416.67,\"SWZ\":172.41,\"ETH\":24.64,\"EU\":243.55,\"EUROPE\":302.09,\"FLK\":500,\"FRO\":404.76,\"FJI\":288.46,\"FIN\":79.39,\"FRA\":56.02,\"GUF\":217.82,\"PYF\":442.86,\"G20\":477.79,\"G7\":341.49,\"GAB\":491.6,\"GMB\":666.67,\"GEO\":167.59,\"DEU\":381.41,\"GHA\":484,\"GRC\":336.57,\"GRL\":178.57,\"GRD\":640,\"GLP\":500,\"GUM\":622.86,\"GTM\":328.27,\"GIN\":236.84,\"GNB\":625,\"GUY\":640.35,\"HTI\":567.31,\"HND\":282.27,\"HKG\":699.5,\"HUN\":204.01,\"ISL\":27.68,\"IND\":713.01,\"IDN\":682.43,\"IRN\":641.73,\"IRQ\":688.81,\"IRL\":283.71,\"ISR\":582.93,\"ITA\":330.72,\"JAM\":555.56,\"JPN\":493.59,\"JOR\":540.92,\"KAZ\":821.9,\"KEN\":71.2,\"KIR\":666.67,\"XKX\":894.65,\"KWT\":649.16,\"KGZ\":147.29,\"LAO\":265.51,\"LATIN AMERICA AND CARIBBEAN\":259.77,\"LVA\":123.99,\"LBN\":599.01,\"LSO\":20,\"LBR\":227.85,\"LBY\":818.69,\"LTU\":160.07,\"LUX\":105.26,\"MAC\":448.98,\"MDG\":436.44,\"MWI\":66.67,\"MYS\":607.88,\"MDV\":611.77,\"MLI\":408,\"MLT\":444.03,\"MTQ\":523.18,\"MRT\":464.71,\"MUS\":632.48,\"MEX\":492.34,\"MIDDLE EAST\":643.04,\"MDA\":643.46,\"MNG\":775.31,\"MNE\":418.09,\"MSR\":1000,\"MAR\":624.45,\"MOZ\":135.65,\"MMR\":440.37,\"NAM\":59.26,\"NRU\":750,\"NPL\":24.44,\"NLD\":268.48,\"NCL\":660.58,\"NZL\":112.76,\"NIC\":265.12,\"NER\":670.89,\"NGA\":523.25,\"NORTH AMERICA\":343.03,\"PRK\":389.59,\"MKD\":539.55,\"NOR\":30.05,\"OCEANIA\":495.74,\"OECD\":341.25,\"OMN\":564.55,\"PAK\":440.61,\"PSE\":516.13,\"PAN\":161.68,\"PNG\":507.25,\"PRY\":24.31,\"PER\":266.48,\"POL\":661.93,\"PRT\":164.86,\"PRI\":677.96,\"QAT\":602.5,\"REU\":572.82,\"ROU\":238.65,\"RUS\":445.02,\"RWA\":316.33,\"KNA\":636.36,\"LCA\":666.67,\"SPM\":600,\"VCT\":529.41,\"WSM\":473.68,\"STP\":642.86,\"SAU\":696.31,\"SEN\":511.6,\"SRB\":648.2,\"SYC\":564.52,\"SLE\":50,\"SGP\":470.87,\"SVK\":116.77,\"SVN\":230.87,\"SLB\":700,\"SOM\":578.95,\"ZAF\":709.69,\"KOR\":432.11,\"SSD\":629.03,\"ESP\":172.2,\"LKA\":509.78,\"SDN\":263.16,\"SUR\":349.28,\"SWE\":40.77,\"CHE\":29.56,\"SYR\":701.66,\"TWN\":644.36,\"TJK\":116.86,\"TZA\":339.25,\"THA\":549.85,\"PHL\":610.74,\"TGO\":443.18,\"TON\":625,\"TTO\":681.53,\"TUN\":563.96,\"TUR\":464.59,\"TKM\":1306.03,\"TCA\":653.85,\"UGA\":44.53,\"UKR\":256.21,\"ARE\":492.7,\"GBR\":228.25,\"USA\":369.53,\"URY\":128.79,\"UZB\":1167.6,\"VUT\":571.43,\"VEN\":185.8,\"VNM\":472.47,\"VGB\":647.06,\"VIR\":632.35,\"WORLD\":481.6,\"YEM\":566.1,\"ZMB\":111.97,\"ZWE\":297.87}; const type = \"average\"; export { data, type }; export default { data, type };"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASM,MAAM,OAAO,EAAC,OAAM,QAAO,UAAS,QAAO,OAAM,OAAM,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,SAAQ,QAAO,QAAO,QAAO,OAAM,OAAM,OAAM,QAAO,OAAM,QAAO,OAAM,OAAM,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO,O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EAAE,MAAM,KAAK;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -21,7 +21,8 @@ __export(helpers_exports, {
|
|
|
21
21
|
getApiRequestHeaders: () => getApiRequestHeaders,
|
|
22
22
|
lessThanEqualTo: () => lessThanEqualTo,
|
|
23
23
|
outputRating: () => outputRating,
|
|
24
|
-
|
|
24
|
+
parseByteTraceOptions: () => parseByteTraceOptions,
|
|
25
|
+
parseVisitTraceOptions: () => parseVisitTraceOptions
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(helpers_exports);
|
|
27
28
|
var import__ = require("../index.js");
|
|
@@ -29,7 +30,7 @@ var import_constants = require("../constants/index.js");
|
|
|
29
30
|
const SWDM4_GLOBAL_GRID_INTENSITY = import_constants.SWDV4.GLOBAL_GRID_INTENSITY;
|
|
30
31
|
const formatNumber = (num) => parseFloat(num.toFixed(2));
|
|
31
32
|
const lessThanEqualTo = (num, limit) => num <= limit;
|
|
32
|
-
function
|
|
33
|
+
function parseByteTraceOptions(options = {}, version = 3, green = false) {
|
|
33
34
|
const globalGridIntensity = version === 4 ? SWDM4_GLOBAL_GRID_INTENSITY : import_constants.GLOBAL_GRID_INTENSITY;
|
|
34
35
|
if (typeof options !== "object") {
|
|
35
36
|
throw new Error("Options must be an object");
|
|
@@ -87,6 +88,37 @@ Falling back to global average grid intensity.`
|
|
|
87
88
|
network: { value: globalGridIntensity }
|
|
88
89
|
};
|
|
89
90
|
}
|
|
91
|
+
if ((options == null ? void 0 : options.greenHostingFactor) || options.greenHostingFactor === 0 && version === 4) {
|
|
92
|
+
if (typeof options.greenHostingFactor === "number") {
|
|
93
|
+
if (options.greenHostingFactor >= 0 && options.greenHostingFactor <= 1) {
|
|
94
|
+
adjustments.greenHostingFactor = options.greenHostingFactor;
|
|
95
|
+
} else {
|
|
96
|
+
adjustments.greenHostingFactor = 0;
|
|
97
|
+
console.warn(
|
|
98
|
+
`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}.
|
|
99
|
+
Falling back to default value.`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
adjustments.greenHostingFactor = 0;
|
|
104
|
+
console.warn(
|
|
105
|
+
`The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}.
|
|
106
|
+
Falling back to default value.`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
} else if (version === 4) {
|
|
110
|
+
adjustments.greenHostingFactor = 0;
|
|
111
|
+
}
|
|
112
|
+
if (green) {
|
|
113
|
+
adjustments.greenHostingFactor = 1;
|
|
114
|
+
}
|
|
115
|
+
return adjustments;
|
|
116
|
+
}
|
|
117
|
+
function parseVisitTraceOptions(options = {}, version = 3, green = false) {
|
|
118
|
+
if (typeof options !== "object") {
|
|
119
|
+
throw new Error("Options must be an object");
|
|
120
|
+
}
|
|
121
|
+
const adjustments = parseByteTraceOptions(options, version, green);
|
|
90
122
|
if ((options == null ? void 0 : options.dataReloadRatio) || options.dataReloadRatio === 0) {
|
|
91
123
|
if (typeof options.dataReloadRatio === "number") {
|
|
92
124
|
if (options.dataReloadRatio >= 0 && options.dataReloadRatio <= 1) {
|
|
@@ -162,34 +194,10 @@ Falling back to default value.`
|
|
|
162
194
|
Falling back to default value.`
|
|
163
195
|
);
|
|
164
196
|
}
|
|
165
|
-
if ((options == null ? void 0 : options.greenHostingFactor) || options.greenHostingFactor === 0 && version === 4) {
|
|
166
|
-
if (typeof options.greenHostingFactor === "number") {
|
|
167
|
-
if (options.greenHostingFactor >= 0 && options.greenHostingFactor <= 1) {
|
|
168
|
-
adjustments.greenHostingFactor = options.greenHostingFactor;
|
|
169
|
-
} else {
|
|
170
|
-
adjustments.greenHostingFactor = 0;
|
|
171
|
-
console.warn(
|
|
172
|
-
`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}.
|
|
173
|
-
Falling back to default value.`
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
} else {
|
|
177
|
-
adjustments.greenHostingFactor = 0;
|
|
178
|
-
console.warn(
|
|
179
|
-
`The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}.
|
|
180
|
-
Falling back to default value.`
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
} else if (version === 4) {
|
|
184
|
-
adjustments.greenHostingFactor = 0;
|
|
185
|
-
}
|
|
186
|
-
if (green) {
|
|
187
|
-
adjustments.greenHostingFactor = 1;
|
|
188
|
-
}
|
|
189
197
|
return adjustments;
|
|
190
198
|
}
|
|
191
199
|
function getApiRequestHeaders(comment = "") {
|
|
192
|
-
return { "User-Agent": `co2js/${"0.16.
|
|
200
|
+
return { "User-Agent": `co2js/${"0.16.4"} ${comment}` };
|
|
193
201
|
}
|
|
194
202
|
function outputRating(co2e, swdmVersion) {
|
|
195
203
|
let {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/index.js"],
|
|
4
|
-
"sourcesContent": ["import { averageIntensity } from \"../index.js\";\nimport {\n GLOBAL_GRID_INTENSITY as SWDM3_GLOBAL_GRID_INTENSITY,\n SWDV4,\n PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD,\n FIRST_TIME_VIEWING_PERCENTAGE,\n RETURNING_VISITOR_PERCENTAGE,\n SWDMV3_RATINGS,\n SWDMV4_RATINGS,\n} from \"../constants/index.js\";\n\nconst SWDM4_GLOBAL_GRID_INTENSITY = SWDV4.GLOBAL_GRID_INTENSITY;\n// Shared type definitions to be used across different files\n\n/**\n * @typedef {Object} DomainCheckOptions options to control the behavior when checking a domain\n * @property {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.\n * @property {boolean} verbose - Optional. Whether to return a verbose response.\n * @property {string[]} db - Optional. A database list to use for lookups.\n */\n\nconst formatNumber = (num) => parseFloat(num.toFixed(2));\n\nconst lessThanEqualTo = (num, limit) => num <= limit;\n\nfunction parseOptions(options = {}, version = 3, green = false) {\n const globalGridIntensity =\n version === 4 ? SWDM4_GLOBAL_GRID_INTENSITY : SWDM3_GLOBAL_GRID_INTENSITY;\n // CHeck that it is an object\n if (typeof options !== \"object\") {\n throw new Error(\"Options must be an object\");\n }\n\n const adjustments = {};\n\n /**\n *\n * @param {string} segment The name of the segment (\"device\"|\"dataCenter\"|\"network\")\n * @param {number|object} segmentIntensity The segment intensity\n */\n function setIntensity(segment, segmentIntensity) {\n if (segmentIntensity || segmentIntensity === 0) {\n if (typeof segmentIntensity === \"object\") {\n if (!averageIntensity.data[segmentIntensity.country?.toUpperCase()]) {\n console.warn(\n `\"${segmentIntensity.country}\" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \\nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \\nFalling back to global average grid intensity.`\n );\n adjustments.gridIntensity[segment] = {\n value: globalGridIntensity,\n };\n }\n adjustments.gridIntensity[segment] = {\n country: segmentIntensity.country,\n value: parseFloat(\n averageIntensity.data[segmentIntensity.country?.toUpperCase()]\n ),\n };\n } else if (typeof segmentIntensity === \"number\") {\n adjustments.gridIntensity[segment] = {\n value: segmentIntensity,\n };\n } else {\n adjustments.gridIntensity[segment] = {\n value: globalGridIntensity,\n };\n console.warn(\n `The ${segment} grid intensity must be a number or an object. You passed in a ${typeof segmentIntensity}. \\nFalling back to global average grid intensity.`\n );\n }\n } else {\n adjustments.gridIntensity[segment] = {\n value: globalGridIntensity,\n };\n }\n }\n\n if (options?.gridIntensity) {\n adjustments.gridIntensity = {};\n const { device, dataCenter, network } = options.gridIntensity;\n setIntensity(\"device\", device);\n setIntensity(\"dataCenter\", dataCenter);\n setIntensity(\"network\", network);\n } else {\n adjustments.gridIntensity = {\n device: { value: globalGridIntensity },\n dataCenter: { value: globalGridIntensity },\n network: { value: globalGridIntensity },\n };\n }\n\n if (options?.dataReloadRatio || options.dataReloadRatio === 0) {\n if (typeof options.dataReloadRatio === \"number\") {\n if (options.dataReloadRatio >= 0 && options.dataReloadRatio <= 1) {\n adjustments.dataReloadRatio = options.dataReloadRatio;\n } else {\n adjustments.dataReloadRatio =\n version === 3 ? PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD : 0;\n console.warn(\n `The dataReloadRatio option must be a number between 0 and 1. You passed in ${options.dataReloadRatio}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.dataReloadRatio =\n version === 3 ? PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD : 0;\n console.warn(\n `The dataReloadRatio option must be a number. You passed in a ${typeof options.dataReloadRatio}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.dataReloadRatio =\n version === 3 ? PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD : 0;\n console.warn(\n `The dataReloadRatio option must be a number. You passed in a ${typeof options.dataReloadRatio}. \\nFalling back to default value.`\n );\n }\n\n if (options?.firstVisitPercentage || options.firstVisitPercentage === 0) {\n if (typeof options.firstVisitPercentage === \"number\") {\n if (\n options.firstVisitPercentage >= 0 &&\n options.firstVisitPercentage <= 1\n ) {\n adjustments.firstVisitPercentage = options.firstVisitPercentage;\n } else {\n adjustments.firstVisitPercentage =\n version === 3 ? FIRST_TIME_VIEWING_PERCENTAGE : 1;\n console.warn(\n `The firstVisitPercentage option must be a number between 0 and 1. You passed in ${options.firstVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.firstVisitPercentage =\n version === 3 ? FIRST_TIME_VIEWING_PERCENTAGE : 1;\n console.warn(\n `The firstVisitPercentage option must be a number. You passed in a ${typeof options.firstVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.firstVisitPercentage =\n version === 3 ? FIRST_TIME_VIEWING_PERCENTAGE : 1;\n console.warn(\n `The firstVisitPercentage option must be a number. You passed in a ${typeof options.firstVisitPercentage}. \\nFalling back to default value.`\n );\n }\n\n if (options?.returnVisitPercentage || options.returnVisitPercentage === 0) {\n if (typeof options.returnVisitPercentage === \"number\") {\n if (\n options.returnVisitPercentage >= 0 &&\n options.returnVisitPercentage <= 1\n ) {\n adjustments.returnVisitPercentage = options.returnVisitPercentage;\n } else {\n adjustments.returnVisitPercentage =\n version === 3 ? RETURNING_VISITOR_PERCENTAGE : 0;\n console.warn(\n `The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.returnVisitPercentage =\n version === 3 ? RETURNING_VISITOR_PERCENTAGE : 0;\n console.warn(\n `The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.returnVisitPercentage =\n version === 3 ? RETURNING_VISITOR_PERCENTAGE : 0;\n console.warn(\n `The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}. \\nFalling back to default value.`\n );\n }\n\n if (\n options?.greenHostingFactor ||\n (options.greenHostingFactor === 0 && version === 4)\n ) {\n if (typeof options.greenHostingFactor === \"number\") {\n if (options.greenHostingFactor >= 0 && options.greenHostingFactor <= 1) {\n adjustments.greenHostingFactor = options.greenHostingFactor;\n } else {\n adjustments.greenHostingFactor = 0;\n console.warn(\n `The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.greenHostingFactor = 0;\n console.warn(\n `The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else if (version === 4) {\n adjustments.greenHostingFactor = 0;\n }\n\n if (green) {\n adjustments.greenHostingFactor = 1;\n }\n\n return adjustments;\n}\n\n/**\n * Returns an object containing all the HTTP headers to use when making a request to the Green Web Foundation API.\n * @param {string} comment - Optional. The app, site, or organisation that is making the request.\n *\n * @returns {import('http').OutgoingHttpHeaders}\n */\nfunction getApiRequestHeaders(comment = \"\") {\n return { \"User-Agent\": `co2js/${process.env.CO2JS_VERSION} ${comment}` };\n}\n\n/**\n * Returns the SWDM rating for a given CO2e value and version of the SWDM.\n * @param {number} co2e - The CO2e value to rate.\n * @param {number} swdmVersion - The version of the SWDM to use. Defaults to version 3.\n * @returns {string} The SWDM rating.\n */\nfunction outputRating(co2e, swdmVersion) {\n let {\n FIFTH_PERCENTILE,\n TENTH_PERCENTILE,\n TWENTIETH_PERCENTILE,\n THIRTIETH_PERCENTILE,\n FORTIETH_PERCENTILE,\n FIFTIETH_PERCENTILE,\n } = SWDMV3_RATINGS;\n\n if (swdmVersion === 4) {\n FIFTH_PERCENTILE = SWDMV4_RATINGS.FIFTH_PERCENTILE;\n TENTH_PERCENTILE = SWDMV4_RATINGS.TENTH_PERCENTILE;\n TWENTIETH_PERCENTILE = SWDMV4_RATINGS.TWENTIETH_PERCENTILE;\n THIRTIETH_PERCENTILE = SWDMV4_RATINGS.THIRTIETH_PERCENTILE;\n FORTIETH_PERCENTILE = SWDMV4_RATINGS.FORTIETH_PERCENTILE;\n FIFTIETH_PERCENTILE = SWDMV4_RATINGS.FIFTIETH_PERCENTILE;\n }\n\n if (lessThanEqualTo(co2e, FIFTH_PERCENTILE)) {\n return \"A+\";\n } else if (lessThanEqualTo(co2e, TENTH_PERCENTILE)) {\n return \"A\";\n } else if (lessThanEqualTo(co2e, TWENTIETH_PERCENTILE)) {\n return \"B\";\n } else if (lessThanEqualTo(co2e, THIRTIETH_PERCENTILE)) {\n return \"C\";\n } else if (lessThanEqualTo(co2e, FORTIETH_PERCENTILE)) {\n return \"D\";\n } else if (lessThanEqualTo(co2e, FIFTIETH_PERCENTILE)) {\n return \"E\";\n } else {\n return \"F\";\n }\n}\n\nexport {\n formatNumber,\n parseOptions,\n getApiRequestHeaders,\n lessThanEqualTo,\n outputRating,\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAAiC;AACjC,uBAQO;AAEP,MAAM,8BAA8B,uBAAM;AAU1C,MAAM,eAAe,CAAC,QAAQ,WAAW,IAAI,QAAQ,CAAC,CAAC;AAEvD,MAAM,kBAAkB,CAAC,KAAK,UAAU,OAAO;AAE/C,SAAS,
|
|
4
|
+
"sourcesContent": ["import { averageIntensity } from \"../index.js\";\nimport {\n GLOBAL_GRID_INTENSITY as SWDM3_GLOBAL_GRID_INTENSITY,\n SWDV4,\n PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD,\n FIRST_TIME_VIEWING_PERCENTAGE,\n RETURNING_VISITOR_PERCENTAGE,\n SWDMV3_RATINGS,\n SWDMV4_RATINGS,\n} from \"../constants/index.js\";\n\nconst SWDM4_GLOBAL_GRID_INTENSITY = SWDV4.GLOBAL_GRID_INTENSITY;\n// Shared type definitions to be used across different files\n\n/**\n * @typedef {Object} DomainCheckOptions options to control the behavior when checking a domain\n * @property {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.\n * @property {boolean} verbose - Optional. Whether to return a verbose response.\n * @property {string[]} db - Optional. A database list to use for lookups.\n */\n\nconst formatNumber = (num) => parseFloat(num.toFixed(2));\n\nconst lessThanEqualTo = (num, limit) => num <= limit;\n\nfunction parseByteTraceOptions(options = {}, version = 3, green = false) {\n const globalGridIntensity =\n version === 4 ? SWDM4_GLOBAL_GRID_INTENSITY : SWDM3_GLOBAL_GRID_INTENSITY;\n // CHeck that it is an object\n if (typeof options !== \"object\") {\n throw new Error(\"Options must be an object\");\n }\n\n const adjustments = {};\n\n /**\n *\n * @param {string} segment The name of the segment (\"device\"|\"dataCenter\"|\"network\")\n * @param {number|object} segmentIntensity The segment intensity\n */\n function setIntensity(segment, segmentIntensity) {\n if (segmentIntensity || segmentIntensity === 0) {\n if (typeof segmentIntensity === \"object\") {\n if (!averageIntensity.data[segmentIntensity.country?.toUpperCase()]) {\n console.warn(\n `\"${segmentIntensity.country}\" is not a valid country. Please use a valid 3 digit ISO 3166 country code. \\nSee https://developers.thegreenwebfoundation.org/co2js/data/ for more information. \\nFalling back to global average grid intensity.`\n );\n adjustments.gridIntensity[segment] = {\n value: globalGridIntensity,\n };\n }\n adjustments.gridIntensity[segment] = {\n country: segmentIntensity.country,\n value: parseFloat(\n averageIntensity.data[segmentIntensity.country?.toUpperCase()]\n ),\n };\n } else if (typeof segmentIntensity === \"number\") {\n adjustments.gridIntensity[segment] = {\n value: segmentIntensity,\n };\n } else {\n adjustments.gridIntensity[segment] = {\n value: globalGridIntensity,\n };\n console.warn(\n `The ${segment} grid intensity must be a number or an object. You passed in a ${typeof segmentIntensity}. \\nFalling back to global average grid intensity.`\n );\n }\n } else {\n adjustments.gridIntensity[segment] = {\n value: globalGridIntensity,\n };\n }\n }\n\n if (options?.gridIntensity) {\n adjustments.gridIntensity = {};\n const { device, dataCenter, network } = options.gridIntensity;\n setIntensity(\"device\", device);\n setIntensity(\"dataCenter\", dataCenter);\n setIntensity(\"network\", network);\n } else {\n adjustments.gridIntensity = {\n device: { value: globalGridIntensity },\n dataCenter: { value: globalGridIntensity },\n network: { value: globalGridIntensity },\n };\n }\n\n if (\n options?.greenHostingFactor ||\n (options.greenHostingFactor === 0 && version === 4)\n ) {\n if (typeof options.greenHostingFactor === \"number\") {\n if (options.greenHostingFactor >= 0 && options.greenHostingFactor <= 1) {\n adjustments.greenHostingFactor = options.greenHostingFactor;\n } else {\n adjustments.greenHostingFactor = 0;\n console.warn(\n `The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.greenHostingFactor = 0;\n console.warn(\n `The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else if (version === 4) {\n adjustments.greenHostingFactor = 0;\n }\n\n if (green) {\n adjustments.greenHostingFactor = 1;\n }\n\n return adjustments;\n}\n\nfunction parseVisitTraceOptions(options = {}, version = 3, green = false) {\n // CHeck that it is an object\n if (typeof options !== \"object\") {\n throw new Error(\"Options must be an object\");\n }\n\n const adjustments = parseByteTraceOptions(options, version, green);\n\n if (options?.dataReloadRatio || options.dataReloadRatio === 0) {\n if (typeof options.dataReloadRatio === \"number\") {\n if (options.dataReloadRatio >= 0 && options.dataReloadRatio <= 1) {\n adjustments.dataReloadRatio = options.dataReloadRatio;\n } else {\n adjustments.dataReloadRatio =\n version === 3 ? PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD : 0;\n console.warn(\n `The dataReloadRatio option must be a number between 0 and 1. You passed in ${options.dataReloadRatio}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.dataReloadRatio =\n version === 3 ? PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD : 0;\n console.warn(\n `The dataReloadRatio option must be a number. You passed in a ${typeof options.dataReloadRatio}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.dataReloadRatio =\n version === 3 ? PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD : 0;\n console.warn(\n `The dataReloadRatio option must be a number. You passed in a ${typeof options.dataReloadRatio}. \\nFalling back to default value.`\n );\n }\n\n if (options?.firstVisitPercentage || options.firstVisitPercentage === 0) {\n if (typeof options.firstVisitPercentage === \"number\") {\n if (\n options.firstVisitPercentage >= 0 &&\n options.firstVisitPercentage <= 1\n ) {\n adjustments.firstVisitPercentage = options.firstVisitPercentage;\n } else {\n adjustments.firstVisitPercentage =\n version === 3 ? FIRST_TIME_VIEWING_PERCENTAGE : 1;\n console.warn(\n `The firstVisitPercentage option must be a number between 0 and 1. You passed in ${options.firstVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.firstVisitPercentage =\n version === 3 ? FIRST_TIME_VIEWING_PERCENTAGE : 1;\n console.warn(\n `The firstVisitPercentage option must be a number. You passed in a ${typeof options.firstVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.firstVisitPercentage =\n version === 3 ? FIRST_TIME_VIEWING_PERCENTAGE : 1;\n console.warn(\n `The firstVisitPercentage option must be a number. You passed in a ${typeof options.firstVisitPercentage}. \\nFalling back to default value.`\n );\n }\n\n if (options?.returnVisitPercentage || options.returnVisitPercentage === 0) {\n if (typeof options.returnVisitPercentage === \"number\") {\n if (\n options.returnVisitPercentage >= 0 &&\n options.returnVisitPercentage <= 1\n ) {\n adjustments.returnVisitPercentage = options.returnVisitPercentage;\n } else {\n adjustments.returnVisitPercentage =\n version === 3 ? RETURNING_VISITOR_PERCENTAGE : 0;\n console.warn(\n `The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.returnVisitPercentage =\n version === 3 ? RETURNING_VISITOR_PERCENTAGE : 0;\n console.warn(\n `The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}. \\nFalling back to default value.`\n );\n }\n } else {\n adjustments.returnVisitPercentage =\n version === 3 ? RETURNING_VISITOR_PERCENTAGE : 0;\n console.warn(\n `The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}. \\nFalling back to default value.`\n );\n }\n\n return adjustments;\n}\n\n/**\n * Returns an object containing all the HTTP headers to use when making a request to the Green Web Foundation API.\n * @param {string} comment - Optional. The app, site, or organisation that is making the request.\n *\n * @returns {import('http').OutgoingHttpHeaders}\n */\nfunction getApiRequestHeaders(comment = \"\") {\n return { \"User-Agent\": `co2js/${process.env.CO2JS_VERSION} ${comment}` };\n}\n\n/**\n * Returns the SWDM rating for a given CO2e value and version of the SWDM.\n * @param {number} co2e - The CO2e value to rate.\n * @param {number} swdmVersion - The version of the SWDM to use. Defaults to version 3.\n * @returns {string} The SWDM rating.\n */\nfunction outputRating(co2e, swdmVersion) {\n let {\n FIFTH_PERCENTILE,\n TENTH_PERCENTILE,\n TWENTIETH_PERCENTILE,\n THIRTIETH_PERCENTILE,\n FORTIETH_PERCENTILE,\n FIFTIETH_PERCENTILE,\n } = SWDMV3_RATINGS;\n\n if (swdmVersion === 4) {\n FIFTH_PERCENTILE = SWDMV4_RATINGS.FIFTH_PERCENTILE;\n TENTH_PERCENTILE = SWDMV4_RATINGS.TENTH_PERCENTILE;\n TWENTIETH_PERCENTILE = SWDMV4_RATINGS.TWENTIETH_PERCENTILE;\n THIRTIETH_PERCENTILE = SWDMV4_RATINGS.THIRTIETH_PERCENTILE;\n FORTIETH_PERCENTILE = SWDMV4_RATINGS.FORTIETH_PERCENTILE;\n FIFTIETH_PERCENTILE = SWDMV4_RATINGS.FIFTIETH_PERCENTILE;\n }\n\n if (lessThanEqualTo(co2e, FIFTH_PERCENTILE)) {\n return \"A+\";\n } else if (lessThanEqualTo(co2e, TENTH_PERCENTILE)) {\n return \"A\";\n } else if (lessThanEqualTo(co2e, TWENTIETH_PERCENTILE)) {\n return \"B\";\n } else if (lessThanEqualTo(co2e, THIRTIETH_PERCENTILE)) {\n return \"C\";\n } else if (lessThanEqualTo(co2e, FORTIETH_PERCENTILE)) {\n return \"D\";\n } else if (lessThanEqualTo(co2e, FIFTIETH_PERCENTILE)) {\n return \"E\";\n } else {\n return \"F\";\n }\n}\n\nexport {\n formatNumber,\n parseByteTraceOptions,\n parseVisitTraceOptions,\n getApiRequestHeaders,\n lessThanEqualTo,\n outputRating,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAAiC;AACjC,uBAQO;AAEP,MAAM,8BAA8B,uBAAM;AAU1C,MAAM,eAAe,CAAC,QAAQ,WAAW,IAAI,QAAQ,CAAC,CAAC;AAEvD,MAAM,kBAAkB,CAAC,KAAK,UAAU,OAAO;AAE/C,SAAS,sBAAsB,UAAU,CAAC,GAAG,UAAU,GAAG,QAAQ,OAAO;AACvE,QAAM,sBACJ,YAAY,IAAI,8BAA8B,iBAAAA;AAEhD,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC7C;AAEA,QAAM,cAAc,CAAC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,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,MAAI,gBAAgB,GAAG;AACrB,uBAAmB,gCAAe;AAClC,uBAAmB,gCAAe;AAClC,2BAAuB,gCAAe;AACtC,2BAAuB,gCAAe;AACtC,0BAAsB,gCAAe;AACrC,0BAAsB,gCAAe;AAAA,EACvC;AAEA,MAAI,gBAAgB,MAAM,gBAAgB,GAAG;AAC3C,WAAO;AAAA,EACT,WAAW,gBAAgB,MAAM,gBAAgB,GAAG;AAClD,WAAO;AAAA,EACT,WAAW,gBAAgB,MAAM,oBAAoB,GAAG;AACtD,WAAO;AAAA,EACT,WAAW,gBAAgB,MAAM,oBAAoB,GAAG;AACtD,WAAO;AAAA,EACT,WAAW,gBAAgB,MAAM,mBAAmB,GAAG;AACrD,WAAO;AAAA,EACT,WAAW,gBAAgB,MAAM,mBAAmB,GAAG;AACrD,WAAO;AAAA,EACT,OAAO;AACL,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": ["SWDM3_GLOBAL_GRID_INTENSITY"]
|
|
7
7
|
}
|
package/dist/esm/co2.js
CHANGED
|
@@ -30,10 +30,9 @@ import OneByte from "./1byte.js";
|
|
|
30
30
|
import SustainableWebDesignV3 from "./sustainable-web-design-v3.js";
|
|
31
31
|
import SustainableWebDesignV4 from "./sustainable-web-design-v4.js";
|
|
32
32
|
import {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} from "./
|
|
36
|
-
import { parseOptions } from "./helpers/index.js";
|
|
33
|
+
parseByteTraceOptions,
|
|
34
|
+
parseVisitTraceOptions
|
|
35
|
+
} from "./helpers/index.js";
|
|
37
36
|
class CO2 {
|
|
38
37
|
constructor(options) {
|
|
39
38
|
this.model = new SustainableWebDesignV3();
|
|
@@ -81,7 +80,11 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
|
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
82
|
perByteTrace(bytes, green = false, options = {}) {
|
|
84
|
-
const adjustments =
|
|
83
|
+
const adjustments = parseByteTraceOptions(
|
|
84
|
+
options,
|
|
85
|
+
this.model.version,
|
|
86
|
+
green
|
|
87
|
+
);
|
|
85
88
|
const _a = adjustments, { gridIntensity } = _a, traceVariables = __objRest(_a, ["gridIntensity"]);
|
|
86
89
|
const _b = traceVariables, {
|
|
87
90
|
dataReloadRatio,
|
|
@@ -113,7 +116,11 @@ See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more ab
|
|
|
113
116
|
perVisitTrace(bytes, green = false, options = {}) {
|
|
114
117
|
var _a;
|
|
115
118
|
if ((_a = this.model) == null ? void 0 : _a.perVisit) {
|
|
116
|
-
const adjustments =
|
|
119
|
+
const adjustments = parseVisitTraceOptions(
|
|
120
|
+
options,
|
|
121
|
+
this.model.version,
|
|
122
|
+
green
|
|
123
|
+
);
|
|
117
124
|
const _b = adjustments, { gridIntensity } = _b, variables = __objRest(_b, ["gridIntensity"]);
|
|
118
125
|
return {
|
|
119
126
|
co2: this.model.perVisit(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const data = { "AFG": 132.53, "AFRICA": 547.83, "ALB": 24.29, "DZA": 634.61, "ASM": 611.11, "AGO": 174.73, "ATG": 611.11, "ARG": 353.96, "ARM": 264.54, "ABW": 561.22, "ASEAN": 570.
|
|
1
|
+
const data = { "AFG": 132.53, "AFRICA": 547.83, "ALB": 24.29, "DZA": 634.61, "ASM": 611.11, "AGO": 174.73, "ATG": 611.11, "ARG": 353.96, "ARM": 264.54, "ABW": 561.22, "ASEAN": 570.43, "ASIA": 591.02, "AUS": 556.3, "AUT": 110.14, "AZE": 671.39, "BHS": 660.1, "BHR": 904.62, "BGD": 691.41, "BRB": 605.51, "BLR": 441.74, "BEL": 138.11, "BLZ": 225.81, "BEN": 584.07, "BTN": 23.33, "BOL": 531.69, "BIH": 600.94, "BWA": 847.91, "BRA": 96.4, "BRN": 893.91, "BGR": 335.33, "BFA": 467.53, "BDI": 250, "CPV": 558.14, "KHM": 417.71, "CMR": 305.42, "CAN": 165.15, "CYM": 642.86, "CAF": 0, "TCD": 628.57, "CHL": 291.11, "CHN": 583.61, "COL": 259.51, "COM": 642.86, "COG": 700, "COD": 24.46, "COK": 250, "CRI": 53.38, "CIV": 393.89, "HRV": 202.68, "CUB": 637.61, "CYP": 526.02, "CZE": 449.72, "DNK": 151.65, "DJI": 692.31, "DMA": 529.41, "DOM": 578.41, "ECU": 166.91, "EGY": 574.04, "SLV": 224.76, "GNQ": 591.84, "ERI": 631.58, "EST": 416.67, "SWZ": 172.41, "ETH": 24.64, "EU": 243.55, "EUROPE": 302.09, "FLK": 500, "FRO": 404.76, "FJI": 288.46, "FIN": 79.39, "FRA": 56.02, "GUF": 217.82, "PYF": 442.86, "G20": 477.79, "G7": 341.49, "GAB": 491.6, "GMB": 666.67, "GEO": 167.59, "DEU": 381.41, "GHA": 484, "GRC": 336.57, "GRL": 178.57, "GRD": 640, "GLP": 500, "GUM": 622.86, "GTM": 328.27, "GIN": 236.84, "GNB": 625, "GUY": 640.35, "HTI": 567.31, "HND": 282.27, "HKG": 699.5, "HUN": 204.01, "ISL": 27.68, "IND": 713.01, "IDN": 682.43, "IRN": 641.73, "IRQ": 688.81, "IRL": 283.71, "ISR": 582.93, "ITA": 330.72, "JAM": 555.56, "JPN": 493.59, "JOR": 540.92, "KAZ": 821.9, "KEN": 71.2, "KIR": 666.67, "XKX": 894.65, "KWT": 649.16, "KGZ": 147.29, "LAO": 265.51, "LATIN AMERICA AND CARIBBEAN": 259.77, "LVA": 123.99, "LBN": 599.01, "LSO": 20, "LBR": 227.85, "LBY": 818.69, "LTU": 160.07, "LUX": 105.26, "MAC": 448.98, "MDG": 436.44, "MWI": 66.67, "MYS": 607.88, "MDV": 611.77, "MLI": 408, "MLT": 444.03, "MTQ": 523.18, "MRT": 464.71, "MUS": 632.48, "MEX": 492.34, "MIDDLE EAST": 643.04, "MDA": 643.46, "MNG": 775.31, "MNE": 418.09, "MSR": 1e3, "MAR": 624.45, "MOZ": 135.65, "MMR": 440.37, "NAM": 59.26, "NRU": 750, "NPL": 24.44, "NLD": 268.48, "NCL": 660.58, "NZL": 112.76, "NIC": 265.12, "NER": 670.89, "NGA": 523.25, "NORTH AMERICA": 343.03, "PRK": 389.59, "MKD": 539.55, "NOR": 30.05, "OCEANIA": 495.74, "OECD": 341.25, "OMN": 564.55, "PAK": 440.61, "PSE": 516.13, "PAN": 161.68, "PNG": 507.25, "PRY": 24.31, "PER": 266.48, "POL": 661.93, "PRT": 164.86, "PRI": 677.96, "QAT": 602.5, "REU": 572.82, "ROU": 238.65, "RUS": 445.02, "RWA": 316.33, "KNA": 636.36, "LCA": 666.67, "SPM": 600, "VCT": 529.41, "WSM": 473.68, "STP": 642.86, "SAU": 696.31, "SEN": 511.6, "SRB": 648.2, "SYC": 564.52, "SLE": 50, "SGP": 470.87, "SVK": 116.77, "SVN": 230.87, "SLB": 700, "SOM": 578.95, "ZAF": 709.69, "KOR": 432.11, "SSD": 629.03, "ESP": 172.2, "LKA": 509.78, "SDN": 263.16, "SUR": 349.28, "SWE": 40.77, "CHE": 29.56, "SYR": 701.66, "TWN": 644.36, "TJK": 116.86, "TZA": 339.25, "THA": 549.85, "PHL": 610.74, "TGO": 443.18, "TON": 625, "TTO": 681.53, "TUN": 563.96, "TUR": 464.59, "TKM": 1306.03, "TCA": 653.85, "UGA": 44.53, "UKR": 256.21, "ARE": 492.7, "GBR": 228.25, "USA": 369.53, "URY": 128.79, "UZB": 1167.6, "VUT": 571.43, "VEN": 185.8, "VNM": 472.47, "VGB": 647.06, "VIR": 632.35, "WORLD": 481.6, "YEM": 566.1, "ZMB": 111.97, "ZWE": 297.87 };
|
|
2
2
|
const type = "average";
|
|
3
3
|
var average_intensities_min_default = { data, type };
|
|
4
4
|
export {
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
const SWDM4_GLOBAL_GRID_INTENSITY = SWDV4.GLOBAL_GRID_INTENSITY;
|
|
12
12
|
const formatNumber = (num) => parseFloat(num.toFixed(2));
|
|
13
13
|
const lessThanEqualTo = (num, limit) => num <= limit;
|
|
14
|
-
function
|
|
14
|
+
function parseByteTraceOptions(options = {}, version = 3, green = false) {
|
|
15
15
|
const globalGridIntensity = version === 4 ? SWDM4_GLOBAL_GRID_INTENSITY : SWDM3_GLOBAL_GRID_INTENSITY;
|
|
16
16
|
if (typeof options !== "object") {
|
|
17
17
|
throw new Error("Options must be an object");
|
|
@@ -69,6 +69,37 @@ Falling back to global average grid intensity.`
|
|
|
69
69
|
network: { value: globalGridIntensity }
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
+
if ((options == null ? void 0 : options.greenHostingFactor) || options.greenHostingFactor === 0 && version === 4) {
|
|
73
|
+
if (typeof options.greenHostingFactor === "number") {
|
|
74
|
+
if (options.greenHostingFactor >= 0 && options.greenHostingFactor <= 1) {
|
|
75
|
+
adjustments.greenHostingFactor = options.greenHostingFactor;
|
|
76
|
+
} else {
|
|
77
|
+
adjustments.greenHostingFactor = 0;
|
|
78
|
+
console.warn(
|
|
79
|
+
`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}.
|
|
80
|
+
Falling back to default value.`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
adjustments.greenHostingFactor = 0;
|
|
85
|
+
console.warn(
|
|
86
|
+
`The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}.
|
|
87
|
+
Falling back to default value.`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
} else if (version === 4) {
|
|
91
|
+
adjustments.greenHostingFactor = 0;
|
|
92
|
+
}
|
|
93
|
+
if (green) {
|
|
94
|
+
adjustments.greenHostingFactor = 1;
|
|
95
|
+
}
|
|
96
|
+
return adjustments;
|
|
97
|
+
}
|
|
98
|
+
function parseVisitTraceOptions(options = {}, version = 3, green = false) {
|
|
99
|
+
if (typeof options !== "object") {
|
|
100
|
+
throw new Error("Options must be an object");
|
|
101
|
+
}
|
|
102
|
+
const adjustments = parseByteTraceOptions(options, version, green);
|
|
72
103
|
if ((options == null ? void 0 : options.dataReloadRatio) || options.dataReloadRatio === 0) {
|
|
73
104
|
if (typeof options.dataReloadRatio === "number") {
|
|
74
105
|
if (options.dataReloadRatio >= 0 && options.dataReloadRatio <= 1) {
|
|
@@ -144,34 +175,10 @@ Falling back to default value.`
|
|
|
144
175
|
Falling back to default value.`
|
|
145
176
|
);
|
|
146
177
|
}
|
|
147
|
-
if ((options == null ? void 0 : options.greenHostingFactor) || options.greenHostingFactor === 0 && version === 4) {
|
|
148
|
-
if (typeof options.greenHostingFactor === "number") {
|
|
149
|
-
if (options.greenHostingFactor >= 0 && options.greenHostingFactor <= 1) {
|
|
150
|
-
adjustments.greenHostingFactor = options.greenHostingFactor;
|
|
151
|
-
} else {
|
|
152
|
-
adjustments.greenHostingFactor = 0;
|
|
153
|
-
console.warn(
|
|
154
|
-
`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}.
|
|
155
|
-
Falling back to default value.`
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
} else {
|
|
159
|
-
adjustments.greenHostingFactor = 0;
|
|
160
|
-
console.warn(
|
|
161
|
-
`The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}.
|
|
162
|
-
Falling back to default value.`
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
} else if (version === 4) {
|
|
166
|
-
adjustments.greenHostingFactor = 0;
|
|
167
|
-
}
|
|
168
|
-
if (green) {
|
|
169
|
-
adjustments.greenHostingFactor = 1;
|
|
170
|
-
}
|
|
171
178
|
return adjustments;
|
|
172
179
|
}
|
|
173
180
|
function getApiRequestHeaders(comment = "") {
|
|
174
|
-
return { "User-Agent": `co2js/${"0.16.
|
|
181
|
+
return { "User-Agent": `co2js/${"0.16.4"} ${comment}` };
|
|
175
182
|
}
|
|
176
183
|
function outputRating(co2e, swdmVersion) {
|
|
177
184
|
let {
|
|
@@ -211,5 +218,6 @@ export {
|
|
|
211
218
|
getApiRequestHeaders,
|
|
212
219
|
lessThanEqualTo,
|
|
213
220
|
outputRating,
|
|
214
|
-
|
|
221
|
+
parseByteTraceOptions,
|
|
222
|
+
parseVisitTraceOptions
|
|
215
223
|
};
|