UNPKG

@tgwf/co2

Version:
54 lines (53 loc) 1.98 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var byte_exports = {}; __export(byte_exports, { OneByte: () => OneByte, default: () => byte_default }); module.exports = __toCommonJS(byte_exports); const CO2_PER_KWH_IN_DC_GREY = 519; const CO2_PER_KWH_NETWORK_GREY = 475; const CO2_PER_KWH_IN_DC_GREEN = 0; const KWH_PER_BYTE_IN_DC = 72e-12; const FIXED_NETWORK_WIRED = 429e-12; const FIXED_NETWORK_WIFI = 152e-12; const FOUR_G_MOBILE = 884e-12; const KWH_PER_BYTE_FOR_NETWORK = (FIXED_NETWORK_WIRED + FIXED_NETWORK_WIFI + FOUR_G_MOBILE) / 3; const KWH_PER_BYTE_FOR_DEVICES = 13e-11; class OneByte { constructor(options) { this.allowRatings = false; this.options = options; this.KWH_PER_BYTE_FOR_NETWORK = KWH_PER_BYTE_FOR_NETWORK; } perByte(bytes, green) { if (bytes < 1) { return 0; } if (green) { const Co2ForDC = bytes * KWH_PER_BYTE_IN_DC * CO2_PER_KWH_IN_DC_GREEN; const Co2forNetwork = bytes * KWH_PER_BYTE_FOR_NETWORK * CO2_PER_KWH_NETWORK_GREY; return Co2ForDC + Co2forNetwork; } const KwHPerByte = KWH_PER_BYTE_IN_DC + KWH_PER_BYTE_FOR_NETWORK; return bytes * KwHPerByte * CO2_PER_KWH_IN_DC_GREY; } } var byte_default = OneByte; //# sourceMappingURL=1byte.js.map