npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sustainable-web-design

v0.0.4

Published

A package for estimating the carbon emissions from using digital services using the Sustainable Web Design model

Downloads

1

Readme

Sustainable Web Design model for Javascript

A library for estimating the carbon emissions from using digital services using the Sustainable Web Design model.

Installation

To begin, you'll need to add the package to your package.json

npm install sustainable-web-design

Usage

import SWD from 'sustainable-web-design';

const results = await SWD.url('https://beleaf.au');

console.log(results);

Use a different model

You can instruct the SWD test method to estimate the emissions using a different model by providing the model number as the third parameter

import SWD from 'sustainable-web-design';

const results = await SWD.url('https://beleaf.au', {}, 1);

console.log(results);

Alternatively, you can access the test method directly on the model and avoid the SWD wrapper

import {V2 as Model} from 'sustainable-web-design';

const results = await Model.url('https://beleaf.au');

console.log(results);

SWD wrapper and Model methods

The SWD wrapper, and each of the SWD models expose 3 methods that can be called to estimate emissions. The models may choose to expose additional methods, but these are not consistent from model to model.

Each of the methods accept atleast 2 parameters, with the SWD wrapper methods accepting a third (integer) representing the model to use. The SWD wrapper defaults to the latest model released.

Each of the models have different formulas for estimating emissions, and each model has different parameters that can be overwritten. If you know the carbon intensity of the electricity grid in which your data center, network, or user devices are located, you should adjust the grid intensity to estimate the operational emissions of that segment. This will give you results that are more representative of how your website is operated and used.

SWD::test

Test will return the estimated emissions for a page view of the url provided. Test requires atleast the url to be tested as the first parameter, and accepts a second parameter allowing for configuration of the test, and the values provided to the formulas.

The test method will make a call to the GPSAPI to calculate the quantity of bytes transferred. The GPSAPI defaults to testing a desktop screens size, but this can be changed to mobile. Additionally, the key can be provided to allow more frequent tests. A key can be acquired from Google.

The test method will also make a call to then Green Web Foundation API's to retrieve energy and emissions values associated with the url provided.

import SWD from 'sustainable-web-design';

const results = await SWD.url('https://beleaf.au', {
    'gpsapi': {
        'strategy': 'mobile',
        'key' => 'xxx',
    }
});

console.log(results);

Response

The test method returns an array from the Model::breakdown method. See SWD::breakdown response for the structure.

SWD::breakdown

Breakdown returns an array containing the estimated emissions, the rating (if available on the model - V3 onwards), the estimated emissions for each segment in the model, and the variables utilised by the formulas.

SWD::breakdown accepts two parameters, a int|float representing the bytes transferred, and an array of parameters for configuring the values used in the forumlas.

import SWD from 'sustainable-web-design';

const results = await SWD.breakdown(153735);

console.log(results);

Response

Note: The structure of the reponse differs from model to model.

{
  gCO2e: 0.012640330709527517,
  rating: 'A+',
  segments: {
    operationalTotal: 0.00878879241281189,
    embodiedTotal: 0.004462495278567076,
    operational: {
      dataCentre: 0.002491667952085845,
      network: 0.0026728801667829974,
      userDevice: 0.003624244293943048
    },
    embodied: {
      dataCentre: 0.0005051881447434425,
      network: 0.0005472871568053961,
      userDevice: 0.0034100199770182374
    }
  },
  variables: {
    operationalEnergyIntensity: 531.597,
    embodiedEnergyIntensity: 494,
    greenHostingFactor: 0.24519999999999997,
    dataCacheRatio: 0,
    returnVisitorRatio: 0,
    gpsapi: { strategy: 'mobile' },
    bytes: 91505
  }
}

SWD::gCO2e

gCO2e returns a float estimating the emissions.

gCO2e accepts two parameters, a int|float representing the bytes transferred, and an array of parameters for configuring the values used in the forumlas.

import SWD from 'sustainable-web-design';

const results = await SWD.gCO2e(153735);

console.log(results);

Response

0.024419489257414

License

Sustainable Web Design model for PHP is licensed under the MIT License - see the LICENSE file for details.