As clearly as possible, describe the changes made in the pull request. You should at least detail "what changes have been made" and "what the results of these changes will be".
This change adds the Sustainable Web Design rating scale into CO2.js for developers using the Sustainable Web Design Model to estimate emissions.
The rating scale is "off" by default, but developers can opt-in to returning results with a carbon emissions total & a corresponding rating by setting rating: true when instantiating an instance of the Sustainable Web Design Model in CO2.js.
import { co2 } from '@tgwf/co2';
const model = new co2({ rating: true });
The rating system is based on the number of bytes passed into carbon emissions results calculated by the perByte, perVisit, perByteTrace, or perVisitTrace functions.
Currently the perByte and perVisit functions return a number representing the estimated CO2e calculated by those functions. When rating: true is set, these functions will now return an object with two keys - rating and total. For example:
import { co2 } from '@tgwf/co2';
const hasRating = new co2({ rating: true });
const noRating = new co2();
hasRating.perByte(1000);
/* Returns:
{ total: 0.0003936519, rating: 'A+' }
*/
noRating.perByte(1000)
/* Returns:
0.0003936519
*/
Triage
Type of change
Please select any of the below items that are appropriate.
This pull request:
Related issue/s
Please list below any issues this pull request is related to.
205
Docs changes required
Do any changes made in this pull request require parts of the CO2.js documentation to be updated?
If you answered "Yes", please create an corresponding issue in our Developer Documentation repository.
Related issue: https://github.com/thegreenwebfoundation/developer-docs/issues/50
Describe the changes made in this pull request
As clearly as possible, describe the changes made in the pull request. You should at least detail "what changes have been made" and "what the results of these changes will be".
This change adds the Sustainable Web Design rating scale into CO2.js for developers using the Sustainable Web Design Model to estimate emissions.
The rating scale is "off" by default, but developers can opt-in to returning results with a carbon emissions total & a corresponding rating by setting
rating: true
when instantiating an instance of the Sustainable Web Design Model in CO2.js.The rating system is based on the
number of bytes passed intocarbon emissions results calculated by theperByte
,perVisit
,perByteTrace
, orperVisitTrace
functions.Currently the
perByte
andperVisit
functions return a number representing the estimated CO2e calculated by those functions. Whenrating: true
is set, these functions will now return an object with two keys -rating
andtotal
. For example: