@tgwf/co2 0.17.0 → 0.17.3-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +22 -4
  2. package/LICENSE +11 -1
  3. package/README.md +19 -0
  4. package/dist/cjs/co2.js +9 -10
  5. package/dist/cjs/co2.js.map +3 -3
  6. package/dist/cjs/data/electricity-maps/index.js +50 -0
  7. package/dist/cjs/data/electricity-maps/index.js.map +7 -0
  8. package/dist/cjs/data/electricity-maps/yearly_2021.js +28 -0
  9. package/dist/cjs/data/electricity-maps/yearly_2021.js.map +7 -0
  10. package/dist/cjs/data/electricity-maps/yearly_2022.js +28 -0
  11. package/dist/cjs/data/electricity-maps/yearly_2022.js.map +7 -0
  12. package/dist/cjs/data/electricity-maps/yearly_2023.js +28 -0
  13. package/dist/cjs/data/electricity-maps/yearly_2023.js.map +7 -0
  14. package/dist/cjs/data/electricity-maps/yearly_2024.js +28 -0
  15. package/dist/cjs/data/electricity-maps/yearly_2024.js.map +7 -0
  16. package/dist/cjs/data/electricity-maps/yearly_2025.js +28 -0
  17. package/dist/cjs/data/electricity-maps/yearly_2025.js.map +7 -0
  18. package/dist/cjs/data.js +3 -1
  19. package/dist/cjs/data.js.map +3 -3
  20. package/dist/cjs/helpers/index.js +1 -1
  21. package/dist/cjs/helpers/index.js.map +1 -1
  22. package/dist/cjs/index.js +9 -1
  23. package/dist/cjs/index.js.map +3 -3
  24. package/dist/esm/co2.js +9 -5
  25. package/dist/esm/data/electricity-maps/index.js +20 -0
  26. package/dist/esm/data/electricity-maps/yearly_2021.js +8 -0
  27. package/dist/esm/data/electricity-maps/yearly_2022.js +8 -0
  28. package/dist/esm/data/electricity-maps/yearly_2023.js +8 -0
  29. package/dist/esm/data/electricity-maps/yearly_2024.js +8 -0
  30. package/dist/esm/data/electricity-maps/yearly_2025.js +8 -0
  31. package/dist/esm/data.js +3 -1
  32. package/dist/esm/helpers/index.js +1 -1
  33. package/dist/esm/index.js +9 -1
  34. package/package.json +16 -11
package/CHANGELOG.md CHANGED
@@ -13,14 +13,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
13
  > - **Security** in case of vulnerabilities.
14
14
 
15
15
  ## Unreleased
16
-
17
- - Add ability to create adaptors which provide access to external data sources #134
18
- - Add access to the Electricity Maps API free tier #134
19
- - Allow access to individual models and their internal functions #195
16
+ - Add carbon.txt validator lookup functionality #273
17
+ - Add subpath exports for estimation models #271
20
18
  <!-- - _(Add a summary of your feature, and if relevant the issue, in your PR for merging into `main`)_ -->
21
19
 
22
20
  ## Released
23
21
 
22
+ ### [0.18.0-alpha2]
23
+
24
+ #### Added
25
+ * Annual grid carbon intensity, renewable percentage, carbon free percentage data from Electricity Maps for the years 2021 - 2025.
26
+
27
+ ### [0.18.0-alpha] - 2025-12-08
28
+
29
+ #### Changed
30
+ * Default carbon estimation model is now the Sustainaable Web Design Model version 4.
31
+
32
+ ### [0.17.0] - 2025-12-02
33
+
34
+ #### Changed
35
+ * Add `data` and `hosting` subpath exports
36
+ * Add warning about switching default model to SWDMv4
37
+
38
+ #### Security
39
+ * Bump tar-fs from 2.1.3 to 2.1.4 by @dependabot[bot] in https://github.com/thegreenwebfoundation/co2.js/pull/265
40
+ * Bump js-yaml by @dependabot[bot] in https://github.com/thegreenwebfoundation/co2.js/pull/268
41
+
24
42
  ### [0.16.8] - 2025-05-12
25
43
 
26
44
  #### Fixed
package/LICENSE CHANGED
@@ -203,7 +203,7 @@ Marginal Carbon intensity data
203
203
 
204
204
  The marginal carbon intensity data bundled in CO2.js is published by the Green Web Foundation under the same permissive CC-BY-SA license as the average carbon intensity data. This data is largely based on the operating marginal intensity data published by International Financial Institutions Technical Working group (the IFI TWG) project within the United Nations Framework Convention on Climate Change (the UNFCCC), to harmonize project-level greenhouse gas emissions accounting.
205
205
 
206
- The data used in this report is provided on an ‘as is’ basis. Data is assembled using the best available data at the time of publication. Every effort has been made to ensure accuracy, and where possible we compare multiple sources to confirm their agreement. We take no responsibility for errors.
206
+ The data used in this report is provided on an ‘as is’ basis. Data is assembled using the best available data at the time of publication. Every effort has been made to ensure accuracy, and where possible we compare multiple sources to confirm their agreement. We take no responsibility for errors.
207
207
 
208
208
 
209
209
  For further information about the methodology used, see the following links
@@ -212,4 +212,14 @@ https://developers.thegreenwebfoundation.org/co2js/data/
212
212
  https://unfccc.int/climate-action/sectoral-engagement/ifis-harmonization-of-standards-for-ghg-accounting
213
213
  https://unfccc.int/sites/default/files/resource/IFITWG_Methodological_approach_to_common_dataset.pdf
214
214
 
215
+ Electricity Maps Grid Intensity Data
216
+ -----------------------------------------------------------------
217
+
218
+ Electricity Maps Grid Intensity Data - The annual grid intensity data is republished from Electricity Maps under the Open Database License (ODbL). Users of this data through CO2.js must:
219
+
220
+ - Attribute: Credit Electricity Maps as the source
221
+ - Share-Alike: Keep derivative works under the same license
222
+ - Keep open: Provide unrestricted versions if using DRM
215
223
 
224
+ For full details on Electricity Maps methodology see: https://www.electricitymaps.com/data/methodology
225
+ For full detail on the ODbL see: https://opendatacommons.org/licenses/odbl/summary/
package/README.md CHANGED
@@ -12,6 +12,14 @@ One day, the internet will be powered by renewable energy. Until that day comes,
12
12
 
13
13
  ## [Documentation](https://developers.thegreenwebfoundation.org/co2js/overview/) | [Changelog](/CHANGELOG.md) | [Roadmap](https://developers.thegreenwebfoundation.org/co2js/roadmap/)
14
14
 
15
+ > [!IMPORTANT]
16
+ > Important note about upcoming changes in CO2.js v0.18
17
+ In the next release of CO2.js (v0.18 – February 2026) we will be changing the default carbon estimation model to Sustainable Web Design Model version 4. If you are using CO2.js to perform carbon estimation, and are not explicitly declaring the model and version to use then you will be impacted by this change.
18
+ >
19
+ > You can install a PREVIEW release to test your code to see how this change will effect you. To do so, use the `npm install @tgwf/co2@next` command.
20
+ >
21
+ > We have detailed the impacts of this change for users of CO2.js in this GitHub issue – [Impact of changing from v3 to v4](https://github.com/thegreenwebfoundation/co2.js/issues/209#issuecomment-3624614392)
22
+
15
23
  ## What is CO2.js?
16
24
 
17
25
  CO2.js is a JavaScript library that enables developers a way to estimate the emissions related to use of their apps, websites, and software.
@@ -132,6 +140,17 @@ The average carbon intensity data from Ember is published under the Creative Com
132
140
 
133
141
  The marginal intensity data is published by the Green Web Foundation, under the Creative Commons ShareAlike Attribution Licence ([CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)). ([What does this mean?](https://www.tldrlegal.com/license/creative-commons-attribution-share-alike-cc-sa))
134
142
 
143
+ Electricity Maps Grid Intensity Data - The annual grid intensity data is republished from Electricity Maps under the [Open Database License (ODbL)](https://opendatacommons.org/licenses/odbl/summary/). Users of this data through CO2.js must:
144
+
145
+ - Attribute: Credit Electricity Maps as the source
146
+ - Share-Alike: Keep derivative works under the same license
147
+ - Keep open: Provide unrestricted versions if using DRM
148
+
149
+ For full details on Electricity Maps methodology see: https://www.electricitymaps.com/data/methodology
150
+ For full detail on the ODbL see: https://opendatacommons.org/licenses/odbl/summary/
151
+
152
+ Data at higher-than-yearly resolution (e.g monthly, hourly etc.), or [other historical and forecasted datapoints](https://www.electricitymaps.com/data) are available through Electricity Maps as a paid service. Users requiring this data should visit the Electricity Maps website for [pricing and details](https://www.electricitymaps.com/pricing).
153
+
135
154
  See LICENCE for more.
136
155
 
137
156
  ## Contributors
package/dist/cjs/co2.js CHANGED
@@ -38,26 +38,25 @@ var import_sustainable_web_design_v4 = __toESM(require("./sustainable-web-design
38
38
  var import_helpers = require("./helpers/index.js");
39
39
  class CO2 {
40
40
  constructor(options) {
41
- this.model = new import_sustainable_web_design_v3.default();
41
+ this.model = new import_sustainable_web_design_v4.default();
42
42
  if ((options == null ? void 0 : options.model) === "1byte") {
43
43
  this.model = new import_byte.default();
44
44
  } else if ((options == null ? void 0 : options.model) === "swd") {
45
- this.model = new import_sustainable_web_design_v3.default();
46
- if ((options == null ? void 0 : options.version) === 4) {
45
+ this.model = new import_sustainable_web_design_v4.default();
46
+ if ((options == null ? void 0 : options.version) === 3) {
47
+ this.model = new import_sustainable_web_design_v3.default();
48
+ } else if ((options == null ? void 0 : options.version) === 4) {
47
49
  this.model = new import_sustainable_web_design_v4.default();
48
50
  }
49
- } else if (!(options == null ? void 0 : options.model)) {
50
- console.warn(`------
51
- WARNING: We are changing the default estimation model in CO2.js to Sustainable Web Design v4 in the next version (v0.18) of CO2.js. This change will take place in February 2026.
52
-
53
- If you would like to keep using Sustainable Web Design v3, please make sure to explicitly set it in your code. See https://developers.thegreenwebfoundation.org/co2js/models/#using-sustainable-web-design-model-version-3 for details.
54
- ------
55
- `);
56
51
  } else if (options == null ? void 0 : options.model) {
57
52
  throw new Error(
58
53
  `"${options.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model.
59
54
  See https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`
60
55
  );
56
+ } else if (!(options == null ? void 0 : options.model) && (options == null ? void 0 : options.version)) {
57
+ throw new Error(
58
+ `"Specified version ${options == null ? void 0 : options.version} but an estimation model is missing. Please specify a model to use for the version you have set.`
59
+ );
61
60
  }
62
61
  if ((options == null ? void 0 : options.rating) && typeof options.rating !== "boolean") {
63
62
  throw new Error(
@@ -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 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 console.warn(`------\nWARNING: We are changing the default estimation model in CO2.js to Sustainable Web Design v4 in the next version (v0.18) of CO2.js. This change will take place in February 2026.\n\nIf you would like to keep using Sustainable Web Design v3, please make sure to explicitly set it in your code. See https://developers.thegreenwebfoundation.org/co2js/models/#using-sustainable-web-design-model-version-3 for details.\n------\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,EAAC,mCAAS,QAA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
+ "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 SustainableWebDesignV4();\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 SustainableWebDesignV4();\n if (options?.version === 3) {\n this.model = new SustainableWebDesignV3();\n } else 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 } else if (!options?.model && options?.version) {\n throw new Error(\n `\"Specified version ${options?.version} but an estimation model is missing. Please specify a model to use for the version you have set.`,\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;AA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,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,iCAAAE,QAAuB;AAAA,EACpC;AAAA,EAEA,yBAAyB;AACvB,WAAO,IAAI,iCAAAF,QAAuB;AAAA,EACpC;AAAA,EAEA,UAAU;AACR,WAAO,IAAI,YAAAC,QAAQ;AAAA,EACrB;AACF;AAGA,IAAO,cAAQ;",
6
+ "names": ["SustainableWebDesignV4", "OneByte", "SustainableWebDesignV3"]
7
7
  }
@@ -0,0 +1,50 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var electricity_maps_exports = {};
29
+ __export(electricity_maps_exports, {
30
+ default: () => electricity_maps_default,
31
+ yearly2021: () => import_yearly_2021.default,
32
+ yearly2022: () => import_yearly_2022.default,
33
+ yearly2023: () => import_yearly_2023.default,
34
+ yearly2024: () => import_yearly_2024.default,
35
+ yearly2025: () => import_yearly_2025.default
36
+ });
37
+ module.exports = __toCommonJS(electricity_maps_exports);
38
+ var import_yearly_2025 = __toESM(require("./yearly_2025.js"));
39
+ var import_yearly_2024 = __toESM(require("./yearly_2024.js"));
40
+ var import_yearly_2023 = __toESM(require("./yearly_2023.js"));
41
+ var import_yearly_2022 = __toESM(require("./yearly_2022.js"));
42
+ var import_yearly_2021 = __toESM(require("./yearly_2021.js"));
43
+ var electricity_maps_default = {
44
+ yearly2025: import_yearly_2025.default,
45
+ yearly2024: import_yearly_2024.default,
46
+ yearly2023: import_yearly_2023.default,
47
+ yearly2022: import_yearly_2022.default,
48
+ yearly2021: import_yearly_2021.default
49
+ };
50
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/data/electricity-maps/index.js"],
4
+ "sourcesContent": ["import yearly2025 from \"./yearly_2025.js\";\nimport yearly2024 from \"./yearly_2024.js\";\nimport yearly2023 from \"./yearly_2023.js\";\nimport yearly2022 from \"./yearly_2022.js\";\nimport yearly2021 from \"./yearly_2021.js\";\n\nexport { yearly2025, yearly2024, yearly2023, yearly2022, yearly2021 };\n\nexport default {\n yearly2025,\n yearly2024,\n yearly2023,\n yearly2022,\n yearly2021,\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,uCAAAA;AAAA,EAAA,qCAAAC;AAAA,EAAA,qCAAAC;AAAA,EAAA,qCAAAC;AAAA,EAAA,qCAAAC;AAAA;AAAA;AAAA,yBAAuB;AACvB,yBAAuB;AACvB,yBAAuB;AACvB,yBAAuB;AACvB,yBAAuB;AAIvB,IAAO,2BAAQ;AAAA,EACb,+BAAAA;AAAA,EACA,+BAAAD;AAAA,EACA,+BAAAD;AAAA,EACA,+BAAAD;AAAA,EACA,+BAAAD;AACF;",
6
+ "names": ["yearly2021", "yearly2022", "yearly2023", "yearly2024", "yearly2025"]
7
+ }