engineering-cal
Version:
A TypeScript library for common engineering calculations across various disciplines.
105 lines • 3.59 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.resistorCalculator = resistorCalculator;
exports.calculateVoltage = calculateVoltage;
exports.calculateCurrent = calculateCurrent;
exports.calculateResistance = calculateResistance;
exports.calculatePower = calculatePower;
exports.calculatePowerFromCurrentAndResistance = calculatePowerFromCurrentAndResistance;
exports.calculatePowerFromVoltageAndResistance = calculatePowerFromVoltageAndResistance;
exports.calculateEnergy = calculateEnergy;
exports.calculateVoltageDrop = calculateVoltageDrop;
/**
* Calculate the resistor ratio for a voltage divider.
* For a divider: V_out = V_in * (R2 / (R1 + R2))
* This function returns the ratio R2 / (R1 + R2).
*/
function resistorCalculator(vIn, vOut) {
if (vOut >= vIn) {
throw new Error('Output voltage must be less than input voltage.');
}
return vOut / vIn;
}
/**
* Ohm's Law: Calculate voltage, current, or resistance.
* V = I × R
* @param current Current in amperes (A).
* @param resistance Resistance in ohms (Ω).
* @returns Voltage in volts (V).
*/
function calculateVoltage(current, resistance) {
return current * resistance;
}
/**
* Ohm's Law: Calculate current using voltage and resistance.
* I = V / R
* @param voltage Voltage in volts (V).
* @param resistance Resistance in ohms (Ω).
* @returns Current in amperes (A).
*/
function calculateCurrent(voltage, resistance) {
return voltage / resistance;
}
/**
* Ohm's Law: Calculate resistance using voltage and current.
* R = V / I
* @param voltage Voltage in volts (V).
* @param current Current in amperes (A).
* @returns Resistance in ohms (Ω).
*/
function calculateResistance(voltage, current) {
return voltage / current;
}
/**
* Power Formula: Calculate power using voltage and current.
* P = V × I
* @param voltage Voltage in volts (V).
* @param current Current in amperes (A).
* @returns Power in watts (W).
*/
function calculatePower(voltage, current) {
return voltage * current;
}
/**
* Alternative Power Formula: Calculate power using current and resistance.
* P = I² × R
* @param current Current in amperes (A).
* @param resistance Resistance in ohms (Ω).
* @returns Power in watts (W).
*/
function calculatePowerFromCurrentAndResistance(current, resistance) {
return Math.pow(current, 2) * resistance;
}
/**
* Alternative Power Formula: Calculate power using voltage and resistance.
* P = V² / R
* @param voltage Voltage in volts (V).
* @param resistance Resistance in ohms (Ω).
* @returns Power in watts (W).
*/
function calculatePowerFromVoltageAndResistance(voltage, resistance) {
return Math.pow(voltage, 2) / resistance;
}
/**
* Energy Consumption: Calculate energy consumed over time.
* E = P × t
* @param power Power in watts (W).
* @param time Time in seconds (s).
* @returns Energy in joules (J).
*/
function calculateEnergy(power, time) {
return power * time;
}
/**
* Voltage Drop Calculation for single-phase circuits.
* VD = (2 × K × I × L) / CM
* @param current Current in amperes (A).
* @param length One-way length of the circuit in feet.
* @param crossSectionalArea Conductor's cross-sectional area in circular mils.
* @param materialConstant Constant based on conductor material (default: 12.9 for copper).
* @returns Voltage drop in volts (V).
*/
function calculateVoltageDrop(current, length, crossSectionalArea, materialConstant = 12.9) {
return (2 * materialConstant * current * length) / crossSectionalArea;
}
//# sourceMappingURL=electrical.js.map
;