js-electrical-engineering-equations
Version:
This is an ES6/ES2015 library of Electrical Engineering Equations. It works with Typescript, es6, and es5.
196 lines (158 loc) • 6.56 kB
JavaScript
;
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; }; }();
var _utilFunctions = require('./util-functions');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Wavelength represents a wavelength for a given frequency
*
* @example
* let wavelength = new Wavelength('300');
* const quarterWavelengthInInches = wavelength.toQuarterWavelength('in');
* const quarterWavelengthInFeet = wavelength.toQuarterWavelength('f');
* const quarterWavelengthInMeters = wavelength.toQuarterWavelength('m');
* const quarterWavelengthInCentimeters = wavelength.toQuarterWavelength('cm');
*
*/
var Wavelength = function () {
/**
*
* @param {number} frequencyInMegahertz - The given frequency for the wavelength.
* @param {number} [precision = 4] - The float precision for returned values.
* @returns {Wavelength}
*
*/
function Wavelength(frequencyInMegahertz) {
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4;
_classCallCheck(this, Wavelength);
if (typeof frequencyInMegahertz === 'undefined') {
throw new Error('Need a frequency to init a Wavelength');
}
if (typeof frequencyInMegahertz !== 'number') {
throw new Error('Frequency should be a number');
}
/**
* @type {number}
*/
this.frequencyInMegahertz = frequencyInMegahertz;
/**
* @type {number}
*/
this.valueInMeters = 300 / this.frequencyInMegahertz;
this.setPrecision(precision);
}
/**
* @returns {string} - The full wavelength of the given frequency as a string.
*/
_createClass(Wavelength, [{
key: 'toString',
value: function toString() {
return (0, _utilFunctions.getFloat)(this.valueInMeters, this.precision).toString();
}
/**
* Returns the full wavelength of the given frequency in meters as a float to the specified decimal precision.
* @returns {number}
*/
}, {
key: 'toFloat',
value: function toFloat() {
return (0, _utilFunctions.getFloat)(this.valueInMeters, this.precision);
}
/**
* Sets the precision for the Wavelength object.
* @param {number} precision
*/
}, {
key: 'setPrecision',
value: function setPrecision(precision) {
/**
* @type {number}
*/
this.precision = precision;
}
/**
* Returns the full wavelength of the given frequency in centimeters as a float to the specified decimal precision.
* @returns {number}
*/
}, {
key: 'toCentimeters',
value: function toCentimeters() {
return (0, _utilFunctions.metersToCentimeters)(this.valueInMeters, this.precision);
}
/**
* Returns the full wavelength of the given frequency in feet as a float to the specified decimal precision.
* @returns {number}
*/
}, {
key: 'toFeet',
value: function toFeet() {
return (0, _utilFunctions.metersToFeet)(this.valueInMeters, this.precision);
}
/**
* Returns the full wavelength of the given frequency in inches as a float to the specified decimal precision.
* @returns {number}
*/
}, {
key: 'toInches',
value: function toInches() {
return (0, _utilFunctions.metersToInches)(this.valueInMeters, this.precision);
}
/**
* Returns 3/4 wavelength of the given frequency in the specified unit as a
* float to the specified decimal precision.
* @param {string} [unit = 'm'] - use either 'm' for meters, 'cm' for centimeters, 'f' for feet, or 'in' for inches
* @returns {number}
*/
}, {
key: 'toThreeQuartersWavelength',
value: function toThreeQuartersWavelength() {
var unit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'm';
var threeQuartersWavelength = this.valueInMeters * .75;
return (0, _utilFunctions.meterConversion)(unit, threeQuartersWavelength, this.precision);
}
/**
* Returns 5/8 wavelength of the given frequency in the specified unit as a
* float to the specified decimal precision.
* @param {string} [unit = 'm'] - use either 'm' for meters, 'cm' for centimeters, 'f' for feet, or 'in' for inches
* @returns {number}
*/
}, {
key: 'toFiveEighthsWavelength',
value: function toFiveEighthsWavelength() {
var unit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'm';
var fiveEighthsWavelength = this.valueInMeters * .625;
return (0, _utilFunctions.meterConversion)(unit, fiveEighthsWavelength, this.precision);
}
/**
* Returns 1/2 wavelength of the given frequency in the specified unit as a
* float to the specified decimal precision.
* @param {string} [unit = 'm'] - use either 'm' for meters, 'cm' for centimeters, 'f' for feet, or 'in' for inches
* @returns {number}
*/
}, {
key: 'toHalfWavelength',
value: function toHalfWavelength() {
var unit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'm';
var halfWavelength = this.valueInMeters * .5;
return (0, _utilFunctions.meterConversion)(unit, halfWavelength, this.precision);
}
/**
* Returns 1/4 wavelength of the given frequency in the specified unit as a
* float to the specified decimal precision.
* @param {string} [unit = 'm'] - use either 'm' for meters, 'cm' for centimeters, 'f' for feet, or 'in' for inches
* @returns {number}
*/
}, {
key: 'toQuarterWavelength',
value: function toQuarterWavelength() {
var unit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'm';
var quarterWavelength = this.valueInMeters * .25;
return (0, _utilFunctions.meterConversion)(unit, quarterWavelength, this.precision);
}
}]);
return Wavelength;
}();
exports.default = Wavelength;
module.exports = exports['default'];