Skip to content

Commit 15e33a5

Browse files
committed
allow for SWDM version change
1 parent 91b73b1 commit 15e33a5

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

src/co2.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161

6262
import OneByte from "./1byte.js";
6363
import SustainableWebDesignV3 from "./sustainable-web-design-v3.js";
64+
import SustainableWebDesignV4 from "./sustainable-web-design-v4.js";
6465

6566
import {
6667
GLOBAL_GRID_INTENSITY,
@@ -77,6 +78,9 @@ class CO2 {
7778
this.model = new OneByte();
7879
} else if (options?.model === "swd") {
7980
this.model = new SustainableWebDesignV3();
81+
if (options?.version === 4) {
82+
this.model = new SustainableWebDesignV4();
83+
}
8084
} else if (options?.model) {
8185
throw new Error(
8286
`"${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.`

src/sustainable-web-design-v3.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class SustainableWebDesign {
3737
constructor(options) {
3838
this.allowRatings = true;
3939
this.options = options;
40+
this.version = 3;
4041
}
4142

4243
/**

src/sustainable-web-design-v4.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const {
2424
class SustainableWebDesign {
2525
constructor(options) {
2626
this.options = options;
27+
this.version = 4;
2728
}
2829

2930
/**

0 commit comments

Comments
 (0)