UNPKG

js-electrical-engineering-equations

Version:

This is an ES6/ES2015 library of Electrical Engineering Equations. It works with Typescript, es6, and es5.

148 lines (128 loc) 4.41 kB
'use strict'; /** * * OhmsLaw is a class with methods that can be used without initializing. * * It provides the various methods for determining two of the four variables for each calculation. * * @example * const wattsAndResistance = OhmsLaw.calcWattsResistance(1, 5); * const wattsAndCurrent = OhmsLaw.calcWattsCurrent(100, 5); * const wattsAndVoltage = OhmsLaw.calcWattsVoltage(100, 1); * const voltageAndCurrent = OhmsLaw.calcVoltageCurrent(100, .5); * const voltageAndResistance = OhmsLaw.calcVoltageResistance(1, .5); * const currentAndResistance = OhmsLaw.calcVoltageResistance(.5, 9); * */ Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var OhmsLaw = function () { function OhmsLaw() { _classCallCheck(this, OhmsLaw); } _createClass(OhmsLaw, null, [{ key: 'calcWattsResistance', /** * * equation is voltage^2 / (current * voltage) * * @param {number} current * @param {number} voltage * @returns {{watts: number, resistance: number}} */ value: function calcWattsResistance(current, voltage) { var calculatedWatts = current * voltage; var calculatedResistance = Math.pow(voltage, 2) / calculatedWatts; return { watts: calculatedWatts, resistance: calculatedResistance }; } /** * * @param {number} resistance * @param {number} voltage * @returns {{watts: number, current: number}} */ }, { key: 'calcWattsCurrent', value: function calcWattsCurrent(resistance, voltage) { var calculatedCurrent = voltage / resistance; var calculatedWatts = calculatedCurrent * voltage; return { watts: calculatedWatts, current: calculatedCurrent }; } /** * * @param {number} resistance * @param {number} current * @returns {{watts: number, voltage: number}} */ }, { key: 'calcWattsVoltage', value: function calcWattsVoltage(resistance, current) { var calculatedVoltage = current * resistance; var calculatedWatts = current * calculatedVoltage; return { watts: calculatedWatts, voltage: calculatedVoltage }; } /** * * @param {number} resistance * @param {number} watts * @returns {{voltage: number, current: number}} */ }, { key: 'calcVoltageCurrent', value: function calcVoltageCurrent(resistance, watts) { var calculatedVoltage = Math.sqrt(watts * resistance); var calculatedCurrent = calculatedVoltage / resistance; return { voltage: calculatedVoltage, current: calculatedCurrent }; } /** * * @param {number} current * @param {number} watts * @returns {{voltage: number, resistance: number}} */ }, { key: 'calcVoltageResistance', value: function calcVoltageResistance(current, watts) { var calculatedVoltage = watts / current; var calculatedResistance = Math.pow(calculatedVoltage, 2) / watts; return { voltage: calculatedVoltage, resistance: calculatedResistance }; } /** * * @param {number} watts * @param {number} voltage * @returns {{current: number, resistance: number}} */ }, { key: 'calcCurrentResistance', value: function calcCurrentResistance(watts, voltage) { var calculatedCurrent = watts / voltage; var calculatedResistance = Math.pow(voltage, 2) / watts; return { current: calculatedCurrent, resistance: calculatedResistance }; } }]); return OhmsLaw; }(); exports.default = OhmsLaw; module.exports = exports['default'];