thegreenwebfoundation / co2.js

An npm module for accessing the green web API, and estimating the carbon emissions from using digital services
Other
389 stars 49 forks source link

Allow switching of model to Sustainable Web Model using just a 'swd' string #96

Closed mrchrisadams closed 2 years ago

mrchrisadams commented 2 years ago

This PR introduces the ability to set the model used in CO2.js to use the Sustainable Web Model with a simple string, instead of you needing to add the object yourself.

Previously you might have needed to do this

import CO2 from "./co2.js";
import SustainableWebDesign from "./sustainable-web-design.js";

const co2 = new CO2({ model: 'swd' });

This can be awkward when consuming the distributed package from npm if you want to try out the Sustainable Web Design model in some sample code, without checking out the repo, and we haven't defined an export map to point to various models.

With this change you can now do this:

import CO2 from "./co2.js";
co2 = new CO2({ model: 'swd' });

This is much more helpful for using in notebooks, and things like Observable for quick demos.

mrchrisadams commented 2 years ago

Hey @fershad, would you mind casting an eye of over this, and merge it in if you're happy?

I think it'll help with the stuff we discussed in #95 , and in issue #94.

fershad commented 2 years ago

CO2.js: key feature s provide a way to switch between 1byte & SWD models.