@tgwf/co2 0.16.2 → 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 -0
- package/README.md +14 -5
- 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 +61 -108
- 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 +61 -108
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -21,6 +21,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
21
21
|
|
|
22
22
|
## Released
|
|
23
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
|
+
|
|
24
52
|
### [0.16.0] - 2024-07-01
|
|
25
53
|
|
|
26
54
|
#### _Added_
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
4
4
|
|
|
5
|
-
[](#contributors-)
|
|
6
6
|
|
|
7
7
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
8
8
|
|
|
@@ -24,7 +24,7 @@ Internally, you may want to use this library to create a _carbon budget_ for you
|
|
|
24
24
|
|
|
25
25
|
For user facing applications, CO2.js could be used to check & block the uploading of carbon intensive files. Or, to present users with information about the carbon impact of their online activities (such as browsing a website).
|
|
26
26
|
|
|
27
|
-
The above
|
|
27
|
+
The above are just a few examples of the many and varied ways CO2.js can be applied to provide carbon estimates for data transfer. If you’re using CO2.js in production we’d love to hear how! [Contact us](https://www.thegreenwebfoundation.org/support-form/) via our website.
|
|
28
28
|
|
|
29
29
|
## Installation
|
|
30
30
|
|
|
@@ -36,12 +36,12 @@ You can install CO2.js as a dependency for your projects using NPM.
|
|
|
36
36
|
npm install @tgwf/co2
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
### Using
|
|
39
|
+
### Using esm.sh
|
|
40
40
|
|
|
41
|
-
You can import the CO2.js library into projects using
|
|
41
|
+
You can import the CO2.js library into projects using esm.sh.
|
|
42
42
|
|
|
43
43
|
```js
|
|
44
|
-
import tgwf from "https://
|
|
44
|
+
import tgwf from "https://esm.sh/@tgwf/co2@latest";
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
## Using a JS CDN
|
|
@@ -160,6 +160,15 @@ To contribute changes back to this project, please follow the steps outlined in
|
|
|
160
160
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/p-gerard"><img src="https://avatars.githubusercontent.com/u/97036756?v=4?s=100" width="100px;" alt="p-gerard"/><br /><sub><b>p-gerard</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/issues?q=author%3Ap-gerard" title="Bug reports">🐛</a> <a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=p-gerard" title="Code">💻</a></td>
|
|
161
161
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/sfishel18"><img src="https://avatars.githubusercontent.com/u/294695?v=4?s=100" width="100px;" alt="Simon Fishel"/><br /><sub><b>Simon Fishel</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=sfishel18" title="Code">💻</a></td>
|
|
162
162
|
</tr>
|
|
163
|
+
<tr>
|
|
164
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/dsubject"><img src="https://avatars.githubusercontent.com/u/33845418?s=64&v=4?s=100" width="100px;" alt="Dani Subject"/><br /><sub><b>Dani Subject</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=dsubject" title="Code">💻</a></td>
|
|
165
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Malay-dev"><img src="https://avatars.githubusercontent.com/u/91375797?s=64&v=4?s=100" width="100px;" alt="Malay Kumar"/><br /><sub><b>Malay Kumar</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=Malay-dev" title="Documentation">📖</a></td>
|
|
166
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/samuelIkoli"><img src="https://avatars.githubusercontent.com/u/98848723?v=4?s=100" width="100px;" alt="Samuel Ikoli"/><br /><sub><b>Samuel Ikoli</b></sub></a><br /><a href="https://github.com/thegreenwebfoundation/co2.js/commits?author=samuelIkoli" title="Documentation">📖</a></td>
|
|
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>
|
|
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>
|
|
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>
|
|
171
|
+
</tr>
|
|
163
172
|
</tbody>
|
|
164
173
|
</table>
|
|
165
174
|
|
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;AAC5B,WAAO,KAAK,MAAM,QAAQ,OAAO,OAAO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F,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,OAAM,OAAM,OAAM,QAAO,OAAM,QAAO,OAAM,QAAO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,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,OAAM,QAAO,OAAM,QAAO,OAAM,OAAM,OAAM,QA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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,112 +30,57 @@ 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
|
-
var _a, _b, _c, _d, _e, _f;
|
|
33
|
+
function parseByteTraceOptions(options = {}, version = 3, green = false) {
|
|
34
34
|
const globalGridIntensity = version === 4 ? SWDM4_GLOBAL_GRID_INTENSITY : import_constants.GLOBAL_GRID_INTENSITY;
|
|
35
35
|
if (typeof options !== "object") {
|
|
36
36
|
throw new Error("Options must be an object");
|
|
37
37
|
}
|
|
38
38
|
const adjustments = {};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (!import__.averageIntensity.data[(_a = device.country) == null ? void 0 : _a.toUpperCase()]) {
|
|
39
|
+
function setIntensity(segment, segmentIntensity) {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
if (segmentIntensity || segmentIntensity === 0) {
|
|
42
|
+
if (typeof segmentIntensity === "object") {
|
|
43
|
+
if (!import__.averageIntensity.data[(_a = segmentIntensity.country) == null ? void 0 : _a.toUpperCase()]) {
|
|
45
44
|
console.warn(
|
|
46
|
-
`"${
|
|
45
|
+
`"${segmentIntensity.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
47
46
|
See https://developers.thegreenwebfoundation.org/co2js/data/ for more information.
|
|
48
47
|
Falling back to global average grid intensity.`
|
|
49
48
|
);
|
|
50
|
-
adjustments.gridIntensity[
|
|
51
|
-
value: globalGridIntensity
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
adjustments.gridIntensity["device"] = {
|
|
55
|
-
country: device.country,
|
|
56
|
-
value: parseFloat(
|
|
57
|
-
import__.averageIntensity.data[(_b = device.country) == null ? void 0 : _b.toUpperCase()]
|
|
58
|
-
)
|
|
59
|
-
};
|
|
60
|
-
} else if (typeof device === "number") {
|
|
61
|
-
adjustments.gridIntensity["device"] = {
|
|
62
|
-
value: device
|
|
63
|
-
};
|
|
64
|
-
} else {
|
|
65
|
-
adjustments.gridIntensity["device"] = {
|
|
66
|
-
value: globalGridIntensity
|
|
67
|
-
};
|
|
68
|
-
console.warn(
|
|
69
|
-
`The device grid intensity must be a number or an object. You passed in a ${typeof device}.
|
|
70
|
-
Falling back to global average grid intensity.`
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (dataCenter || dataCenter === 0) {
|
|
75
|
-
if (typeof dataCenter === "object") {
|
|
76
|
-
if (!import__.averageIntensity.data[(_c = dataCenter.country) == null ? void 0 : _c.toUpperCase()]) {
|
|
77
|
-
console.warn(
|
|
78
|
-
`"${dataCenter.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
79
|
-
See https://developers.thegreenwebfoundation.org/co2js/data/ for more information.
|
|
80
|
-
Falling back to global average grid intensity.`
|
|
81
|
-
);
|
|
82
|
-
adjustments.gridIntensity["dataCenter"] = {
|
|
83
|
-
value: import_constants.GLOBAL_GRID_INTENSITY
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
adjustments.gridIntensity["dataCenter"] = {
|
|
87
|
-
country: dataCenter.country,
|
|
88
|
-
value: parseFloat(
|
|
89
|
-
import__.averageIntensity.data[(_d = dataCenter.country) == null ? void 0 : _d.toUpperCase()]
|
|
90
|
-
)
|
|
91
|
-
};
|
|
92
|
-
} else if (typeof dataCenter === "number") {
|
|
93
|
-
adjustments.gridIntensity["dataCenter"] = {
|
|
94
|
-
value: dataCenter
|
|
95
|
-
};
|
|
96
|
-
} else {
|
|
97
|
-
adjustments.gridIntensity["dataCenter"] = {
|
|
98
|
-
value: globalGridIntensity
|
|
99
|
-
};
|
|
100
|
-
console.warn(
|
|
101
|
-
`The data center grid intensity must be a number or an object. You passed in a ${typeof dataCenter}.
|
|
102
|
-
Falling back to global average grid intensity.`
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (network || network === 0) {
|
|
107
|
-
if (typeof network === "object") {
|
|
108
|
-
if (!import__.averageIntensity.data[(_e = network.country) == null ? void 0 : _e.toUpperCase()]) {
|
|
109
|
-
console.warn(
|
|
110
|
-
`"${network.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
111
|
-
See https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity.
|
|
112
|
-
Falling back to global average grid intensity.`
|
|
113
|
-
);
|
|
114
|
-
adjustments.gridIntensity["network"] = {
|
|
49
|
+
adjustments.gridIntensity[segment] = {
|
|
115
50
|
value: globalGridIntensity
|
|
116
51
|
};
|
|
117
52
|
}
|
|
118
|
-
adjustments.gridIntensity[
|
|
119
|
-
country:
|
|
53
|
+
adjustments.gridIntensity[segment] = {
|
|
54
|
+
country: segmentIntensity.country,
|
|
120
55
|
value: parseFloat(
|
|
121
|
-
import__.averageIntensity.data[(
|
|
56
|
+
import__.averageIntensity.data[(_b = segmentIntensity.country) == null ? void 0 : _b.toUpperCase()]
|
|
122
57
|
)
|
|
123
58
|
};
|
|
124
|
-
} else if (typeof
|
|
125
|
-
adjustments.gridIntensity[
|
|
126
|
-
value:
|
|
59
|
+
} else if (typeof segmentIntensity === "number") {
|
|
60
|
+
adjustments.gridIntensity[segment] = {
|
|
61
|
+
value: segmentIntensity
|
|
127
62
|
};
|
|
128
63
|
} else {
|
|
129
|
-
adjustments.gridIntensity[
|
|
64
|
+
adjustments.gridIntensity[segment] = {
|
|
130
65
|
value: globalGridIntensity
|
|
131
66
|
};
|
|
132
67
|
console.warn(
|
|
133
|
-
`The
|
|
68
|
+
`The ${segment} grid intensity must be a number or an object. You passed in a ${typeof segmentIntensity}.
|
|
134
69
|
Falling back to global average grid intensity.`
|
|
135
70
|
);
|
|
136
71
|
}
|
|
72
|
+
} else {
|
|
73
|
+
adjustments.gridIntensity[segment] = {
|
|
74
|
+
value: globalGridIntensity
|
|
75
|
+
};
|
|
137
76
|
}
|
|
77
|
+
}
|
|
78
|
+
if (options == null ? void 0 : options.gridIntensity) {
|
|
79
|
+
adjustments.gridIntensity = {};
|
|
80
|
+
const { device, dataCenter, network } = options.gridIntensity;
|
|
81
|
+
setIntensity("device", device);
|
|
82
|
+
setIntensity("dataCenter", dataCenter);
|
|
83
|
+
setIntensity("network", network);
|
|
138
84
|
} else {
|
|
139
85
|
adjustments.gridIntensity = {
|
|
140
86
|
device: { value: globalGridIntensity },
|
|
@@ -142,6 +88,37 @@ Falling back to global average grid intensity.`
|
|
|
142
88
|
network: { value: globalGridIntensity }
|
|
143
89
|
};
|
|
144
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);
|
|
145
122
|
if ((options == null ? void 0 : options.dataReloadRatio) || options.dataReloadRatio === 0) {
|
|
146
123
|
if (typeof options.dataReloadRatio === "number") {
|
|
147
124
|
if (options.dataReloadRatio >= 0 && options.dataReloadRatio <= 1) {
|
|
@@ -217,34 +194,10 @@ Falling back to default value.`
|
|
|
217
194
|
Falling back to default value.`
|
|
218
195
|
);
|
|
219
196
|
}
|
|
220
|
-
if ((options == null ? void 0 : options.greenHostingFactor) || options.greenHostingFactor === 0 && version === 4) {
|
|
221
|
-
if (typeof options.greenHostingFactor === "number") {
|
|
222
|
-
if (options.greenHostingFactor >= 0 && options.greenHostingFactor <= 1) {
|
|
223
|
-
adjustments.greenHostingFactor = options.greenHostingFactor;
|
|
224
|
-
} else {
|
|
225
|
-
adjustments.greenHostingFactor = 0;
|
|
226
|
-
console.warn(
|
|
227
|
-
`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}.
|
|
228
|
-
Falling back to default value.`
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
} else {
|
|
232
|
-
adjustments.greenHostingFactor = 0;
|
|
233
|
-
console.warn(
|
|
234
|
-
`The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}.
|
|
235
|
-
Falling back to default value.`
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
} else if (version === 4) {
|
|
239
|
-
adjustments.greenHostingFactor = 0;
|
|
240
|
-
}
|
|
241
|
-
if (green) {
|
|
242
|
-
adjustments.greenHostingFactor = 1;
|
|
243
|
-
}
|
|
244
197
|
return adjustments;
|
|
245
198
|
}
|
|
246
199
|
function getApiRequestHeaders(comment = "") {
|
|
247
|
-
return { "User-Agent": `co2js/${"0.16.
|
|
200
|
+
return { "User-Agent": `co2js/${"0.16.4"} ${comment}` };
|
|
248
201
|
}
|
|
249
202
|
function outputRating(co2e, swdmVersion) {
|
|
250
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 if (options?.gridIntensity) {\n adjustments.gridIntensity = {};\n const { device, dataCenter, network } = options.gridIntensity;\n if (device || device === 0) {\n if (typeof device === \"object\") {\n if (!averageIntensity.data[device.country?.toUpperCase()]) {\n console.warn(\n `\"${device.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[\"device\"] = {\n value: globalGridIntensity,\n };\n }\n adjustments.gridIntensity[\"device\"] = {\n country: device.country,\n value: parseFloat(\n averageIntensity.data[device.country?.toUpperCase()]\n ),\n };\n } else if (typeof device === \"number\") {\n adjustments.gridIntensity[\"device\"] = {\n value: device,\n };\n } else {\n adjustments.gridIntensity[\"device\"] = {\n value: globalGridIntensity,\n };\n console.warn(\n `The device grid intensity must be a number or an object. You passed in a ${typeof device}. \\nFalling back to global average grid intensity.`\n );\n }\n }\n if (dataCenter || dataCenter === 0) {\n if (typeof dataCenter === \"object\") {\n if (!averageIntensity.data[dataCenter.country?.toUpperCase()]) {\n console.warn(\n `\"${dataCenter.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[\"dataCenter\"] = {\n value: SWDM3_GLOBAL_GRID_INTENSITY,\n };\n }\n adjustments.gridIntensity[\"dataCenter\"] = {\n country: dataCenter.country,\n value: parseFloat(\n averageIntensity.data[dataCenter.country?.toUpperCase()]\n ),\n };\n } else if (typeof dataCenter === \"number\") {\n adjustments.gridIntensity[\"dataCenter\"] = {\n value: dataCenter,\n };\n } else {\n adjustments.gridIntensity[\"dataCenter\"] = {\n value: globalGridIntensity,\n };\n console.warn(\n `The data center grid intensity must be a number or an object. You passed in a ${typeof dataCenter}. \\nFalling back to global average grid intensity.`\n );\n }\n }\n if (network || network === 0) {\n if (typeof network === \"object\") {\n if (!averageIntensity.data[network.country?.toUpperCase()]) {\n console.warn(\n `\"${network.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. Falling back to global average grid intensity. \\nFalling back to global average grid intensity.`\n );\n adjustments.gridIntensity[\"network\"] = {\n value: globalGridIntensity,\n };\n }\n adjustments.gridIntensity[\"network\"] = {\n country: network.country,\n value: parseFloat(\n averageIntensity.data[network.country?.toUpperCase()]\n ),\n };\n } else if (typeof network === \"number\") {\n adjustments.gridIntensity[\"network\"] = {\n value: network,\n };\n } else {\n adjustments.gridIntensity[\"network\"] = {\n value: globalGridIntensity,\n };\n console.warn(\n `The network grid intensity must be a number or an object. You passed in a ${typeof network}. \\nFalling back to global average grid intensity.`\n );\n }\n }\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;AAOrB,WAAS,aAAa,SAAS,kBAAkB;AAxCnD;AAyCI,QAAI,oBAAoB,qBAAqB,GAAG;AAC9C,UAAI,OAAO,qBAAqB,UAAU;AACxC,YAAI,CAAC,0BAAiB,MAAK,sBAAiB,YAAjB,mBAA0B,gBAAgB;AACnE,kBAAQ;AAAA,YACN,IAAI,iBAAiB;AAAA;AAAA;AAAA,UACvB;AACA,sBAAY,cAAc,WAAW;AAAA,YACnC,OAAO;AAAA,UACT;AAAA,QACF;AACA,oBAAY,cAAc,WAAW;AAAA,UACnC,SAAS,iBAAiB;AAAA,UAC1B,OAAO;AAAA,YACL,0BAAiB,MAAK,sBAAiB,YAAjB,mBAA0B;AAAA,UAClD;AAAA,QACF;AAAA,MACF,WAAW,OAAO,qBAAqB,UAAU;AAC/C,oBAA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AAmB,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,112 +11,57 @@ 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
|
|
15
|
-
var _a, _b, _c, _d, _e, _f;
|
|
14
|
+
function parseByteTraceOptions(options = {}, version = 3, green = false) {
|
|
16
15
|
const globalGridIntensity = version === 4 ? SWDM4_GLOBAL_GRID_INTENSITY : SWDM3_GLOBAL_GRID_INTENSITY;
|
|
17
16
|
if (typeof options !== "object") {
|
|
18
17
|
throw new Error("Options must be an object");
|
|
19
18
|
}
|
|
20
19
|
const adjustments = {};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (!averageIntensity.data[(_a = device.country) == null ? void 0 : _a.toUpperCase()]) {
|
|
20
|
+
function setIntensity(segment, segmentIntensity) {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
if (segmentIntensity || segmentIntensity === 0) {
|
|
23
|
+
if (typeof segmentIntensity === "object") {
|
|
24
|
+
if (!averageIntensity.data[(_a = segmentIntensity.country) == null ? void 0 : _a.toUpperCase()]) {
|
|
27
25
|
console.warn(
|
|
28
|
-
`"${
|
|
26
|
+
`"${segmentIntensity.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
29
27
|
See https://developers.thegreenwebfoundation.org/co2js/data/ for more information.
|
|
30
28
|
Falling back to global average grid intensity.`
|
|
31
29
|
);
|
|
32
|
-
adjustments.gridIntensity[
|
|
33
|
-
value: globalGridIntensity
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
adjustments.gridIntensity["device"] = {
|
|
37
|
-
country: device.country,
|
|
38
|
-
value: parseFloat(
|
|
39
|
-
averageIntensity.data[(_b = device.country) == null ? void 0 : _b.toUpperCase()]
|
|
40
|
-
)
|
|
41
|
-
};
|
|
42
|
-
} else if (typeof device === "number") {
|
|
43
|
-
adjustments.gridIntensity["device"] = {
|
|
44
|
-
value: device
|
|
45
|
-
};
|
|
46
|
-
} else {
|
|
47
|
-
adjustments.gridIntensity["device"] = {
|
|
48
|
-
value: globalGridIntensity
|
|
49
|
-
};
|
|
50
|
-
console.warn(
|
|
51
|
-
`The device grid intensity must be a number or an object. You passed in a ${typeof device}.
|
|
52
|
-
Falling back to global average grid intensity.`
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (dataCenter || dataCenter === 0) {
|
|
57
|
-
if (typeof dataCenter === "object") {
|
|
58
|
-
if (!averageIntensity.data[(_c = dataCenter.country) == null ? void 0 : _c.toUpperCase()]) {
|
|
59
|
-
console.warn(
|
|
60
|
-
`"${dataCenter.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
61
|
-
See https://developers.thegreenwebfoundation.org/co2js/data/ for more information.
|
|
62
|
-
Falling back to global average grid intensity.`
|
|
63
|
-
);
|
|
64
|
-
adjustments.gridIntensity["dataCenter"] = {
|
|
65
|
-
value: SWDM3_GLOBAL_GRID_INTENSITY
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
adjustments.gridIntensity["dataCenter"] = {
|
|
69
|
-
country: dataCenter.country,
|
|
70
|
-
value: parseFloat(
|
|
71
|
-
averageIntensity.data[(_d = dataCenter.country) == null ? void 0 : _d.toUpperCase()]
|
|
72
|
-
)
|
|
73
|
-
};
|
|
74
|
-
} else if (typeof dataCenter === "number") {
|
|
75
|
-
adjustments.gridIntensity["dataCenter"] = {
|
|
76
|
-
value: dataCenter
|
|
77
|
-
};
|
|
78
|
-
} else {
|
|
79
|
-
adjustments.gridIntensity["dataCenter"] = {
|
|
80
|
-
value: globalGridIntensity
|
|
81
|
-
};
|
|
82
|
-
console.warn(
|
|
83
|
-
`The data center grid intensity must be a number or an object. You passed in a ${typeof dataCenter}.
|
|
84
|
-
Falling back to global average grid intensity.`
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (network || network === 0) {
|
|
89
|
-
if (typeof network === "object") {
|
|
90
|
-
if (!averageIntensity.data[(_e = network.country) == null ? void 0 : _e.toUpperCase()]) {
|
|
91
|
-
console.warn(
|
|
92
|
-
`"${network.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code.
|
|
93
|
-
See https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity.
|
|
94
|
-
Falling back to global average grid intensity.`
|
|
95
|
-
);
|
|
96
|
-
adjustments.gridIntensity["network"] = {
|
|
30
|
+
adjustments.gridIntensity[segment] = {
|
|
97
31
|
value: globalGridIntensity
|
|
98
32
|
};
|
|
99
33
|
}
|
|
100
|
-
adjustments.gridIntensity[
|
|
101
|
-
country:
|
|
34
|
+
adjustments.gridIntensity[segment] = {
|
|
35
|
+
country: segmentIntensity.country,
|
|
102
36
|
value: parseFloat(
|
|
103
|
-
averageIntensity.data[(
|
|
37
|
+
averageIntensity.data[(_b = segmentIntensity.country) == null ? void 0 : _b.toUpperCase()]
|
|
104
38
|
)
|
|
105
39
|
};
|
|
106
|
-
} else if (typeof
|
|
107
|
-
adjustments.gridIntensity[
|
|
108
|
-
value:
|
|
40
|
+
} else if (typeof segmentIntensity === "number") {
|
|
41
|
+
adjustments.gridIntensity[segment] = {
|
|
42
|
+
value: segmentIntensity
|
|
109
43
|
};
|
|
110
44
|
} else {
|
|
111
|
-
adjustments.gridIntensity[
|
|
45
|
+
adjustments.gridIntensity[segment] = {
|
|
112
46
|
value: globalGridIntensity
|
|
113
47
|
};
|
|
114
48
|
console.warn(
|
|
115
|
-
`The
|
|
49
|
+
`The ${segment} grid intensity must be a number or an object. You passed in a ${typeof segmentIntensity}.
|
|
116
50
|
Falling back to global average grid intensity.`
|
|
117
51
|
);
|
|
118
52
|
}
|
|
53
|
+
} else {
|
|
54
|
+
adjustments.gridIntensity[segment] = {
|
|
55
|
+
value: globalGridIntensity
|
|
56
|
+
};
|
|
119
57
|
}
|
|
58
|
+
}
|
|
59
|
+
if (options == null ? void 0 : options.gridIntensity) {
|
|
60
|
+
adjustments.gridIntensity = {};
|
|
61
|
+
const { device, dataCenter, network } = options.gridIntensity;
|
|
62
|
+
setIntensity("device", device);
|
|
63
|
+
setIntensity("dataCenter", dataCenter);
|
|
64
|
+
setIntensity("network", network);
|
|
120
65
|
} else {
|
|
121
66
|
adjustments.gridIntensity = {
|
|
122
67
|
device: { value: globalGridIntensity },
|
|
@@ -124,6 +69,37 @@ Falling back to global average grid intensity.`
|
|
|
124
69
|
network: { value: globalGridIntensity }
|
|
125
70
|
};
|
|
126
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);
|
|
127
103
|
if ((options == null ? void 0 : options.dataReloadRatio) || options.dataReloadRatio === 0) {
|
|
128
104
|
if (typeof options.dataReloadRatio === "number") {
|
|
129
105
|
if (options.dataReloadRatio >= 0 && options.dataReloadRatio <= 1) {
|
|
@@ -199,34 +175,10 @@ Falling back to default value.`
|
|
|
199
175
|
Falling back to default value.`
|
|
200
176
|
);
|
|
201
177
|
}
|
|
202
|
-
if ((options == null ? void 0 : options.greenHostingFactor) || options.greenHostingFactor === 0 && version === 4) {
|
|
203
|
-
if (typeof options.greenHostingFactor === "number") {
|
|
204
|
-
if (options.greenHostingFactor >= 0 && options.greenHostingFactor <= 1) {
|
|
205
|
-
adjustments.greenHostingFactor = options.greenHostingFactor;
|
|
206
|
-
} else {
|
|
207
|
-
adjustments.greenHostingFactor = 0;
|
|
208
|
-
console.warn(
|
|
209
|
-
`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${options.returnVisitPercentage}.
|
|
210
|
-
Falling back to default value.`
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
} else {
|
|
214
|
-
adjustments.greenHostingFactor = 0;
|
|
215
|
-
console.warn(
|
|
216
|
-
`The returnVisitPercentage option must be a number. You passed in a ${typeof options.returnVisitPercentage}.
|
|
217
|
-
Falling back to default value.`
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
} else if (version === 4) {
|
|
221
|
-
adjustments.greenHostingFactor = 0;
|
|
222
|
-
}
|
|
223
|
-
if (green) {
|
|
224
|
-
adjustments.greenHostingFactor = 1;
|
|
225
|
-
}
|
|
226
178
|
return adjustments;
|
|
227
179
|
}
|
|
228
180
|
function getApiRequestHeaders(comment = "") {
|
|
229
|
-
return { "User-Agent": `co2js/${"0.16.
|
|
181
|
+
return { "User-Agent": `co2js/${"0.16.4"} ${comment}` };
|
|
230
182
|
}
|
|
231
183
|
function outputRating(co2e, swdmVersion) {
|
|
232
184
|
let {
|
|
@@ -266,5 +218,6 @@ export {
|
|
|
266
218
|
getApiRequestHeaders,
|
|
267
219
|
lessThanEqualTo,
|
|
268
220
|
outputRating,
|
|
269
|
-
|
|
221
|
+
parseByteTraceOptions,
|
|
222
|
+
parseVisitTraceOptions
|
|
270
223
|
};
|