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

Remove default lines #88

Closed drydenwilliams closed 1 year ago

drydenwilliams commented 2 years ago

https://github.com/thegreenwebfoundation/co2.js/blob/8901d1d5c730240a5023ec1a913bb41dc559d2db/src/sustainable-web-design.js#L100

We can remove these lines as carbonIntensity is set in the function args carbonIntensity = GLOBAL_INTENSITY

Updated:

  perByte(bytes, carbonIntensity = GLOBAL_INTENSITY) {
    const energyBycomponent = this.energyPerByteByComponent(bytes);

    // otherwise when faced with non numeric values throw an error
    if (typeof carbonIntensity !== "number") {
      throw new Error(
        `perByte expects a numeric value or boolean for the carbon intensity value. Received: ${carbonIntensity}`
      );
    }

    const co2ValuesbyComponent = this.co2byComponent(
      energyBycomponent,
      carbonIntensity
    );

    // pull out our values…
    const co2Values = Object.values(co2ValuesbyComponent);

    // so we can return their sum
    return co2Values.reduce(
      (prevValue, currentValue) => prevValue + currentValue
    );
  }
fershad commented 1 year ago

This issue seems to be resolved/is dated. @drydenwilliams I'm going to mark it as closed.