unitsnet-js
Version:
A better way to hold unit variables and easily convert to the destination unit
279 lines (278 loc) • 13.8 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ElectricReactiveEnergy = exports.ElectricReactiveEnergyUnits = void 0;
const base_unit_1 = require("../base-unit");
/** ElectricReactiveEnergyUnits enumeration */
var ElectricReactiveEnergyUnits;
(function (ElectricReactiveEnergyUnits) {
/** */
ElectricReactiveEnergyUnits["VoltampereReactiveHours"] = "VoltampereReactiveHour";
/** */
ElectricReactiveEnergyUnits["KilovoltampereReactiveHours"] = "KilovoltampereReactiveHour";
/** */
ElectricReactiveEnergyUnits["MegavoltampereReactiveHours"] = "MegavoltampereReactiveHour";
})(ElectricReactiveEnergyUnits = exports.ElectricReactiveEnergyUnits || (exports.ElectricReactiveEnergyUnits = {}));
/** The volt-ampere reactive hour (expressed as varh) is the reactive power of one Volt-ampere reactive produced in one hour. */
class ElectricReactiveEnergy extends base_unit_1.BaseUnit {
/**
* Create a new ElectricReactiveEnergy.
* @param value The value.
* @param fromUnit The ‘ElectricReactiveEnergy’ unit to create from.
* The default unit is VoltampereReactiveHours
*/
constructor(value, fromUnit = ElectricReactiveEnergyUnits.VoltampereReactiveHours) {
super();
this.voltamperereactivehoursLazy = null;
this.kilovoltamperereactivehoursLazy = null;
this.megavoltamperereactivehoursLazy = null;
if (value === undefined || value === null || Number.isNaN(value)) {
throw new TypeError('invalid unit value ‘' + value + '’');
}
this.value = this.convertToBase(value, fromUnit);
}
/**
* The base value of ElectricReactiveEnergy is VoltampereReactiveHours.
* This accessor used when needs a value for calculations and it's better to use directly the base value
*/
get BaseValue() {
return this.value;
}
/** Gets the default unit used when creating instances of the unit or its DTO */
get baseUnit() {
return ElectricReactiveEnergyUnits.VoltampereReactiveHours;
}
/** */
get VoltampereReactiveHours() {
if (this.voltamperereactivehoursLazy !== null) {
return this.voltamperereactivehoursLazy;
}
return this.voltamperereactivehoursLazy = this.convertFromBase(ElectricReactiveEnergyUnits.VoltampereReactiveHours);
}
/** */
get KilovoltampereReactiveHours() {
if (this.kilovoltamperereactivehoursLazy !== null) {
return this.kilovoltamperereactivehoursLazy;
}
return this.kilovoltamperereactivehoursLazy = this.convertFromBase(ElectricReactiveEnergyUnits.KilovoltampereReactiveHours);
}
/** */
get MegavoltampereReactiveHours() {
if (this.megavoltamperereactivehoursLazy !== null) {
return this.megavoltamperereactivehoursLazy;
}
return this.megavoltamperereactivehoursLazy = this.convertFromBase(ElectricReactiveEnergyUnits.MegavoltampereReactiveHours);
}
/**
* Create a new ElectricReactiveEnergy instance from a VoltampereReactiveHours
*
* @param value The unit as VoltampereReactiveHours to create a new ElectricReactiveEnergy from.
* @returns The new ElectricReactiveEnergy instance.
*/
static FromVoltampereReactiveHours(value) {
return new ElectricReactiveEnergy(value, ElectricReactiveEnergyUnits.VoltampereReactiveHours);
}
/**
* Create a new ElectricReactiveEnergy instance from a KilovoltampereReactiveHours
*
* @param value The unit as KilovoltampereReactiveHours to create a new ElectricReactiveEnergy from.
* @returns The new ElectricReactiveEnergy instance.
*/
static FromKilovoltampereReactiveHours(value) {
return new ElectricReactiveEnergy(value, ElectricReactiveEnergyUnits.KilovoltampereReactiveHours);
}
/**
* Create a new ElectricReactiveEnergy instance from a MegavoltampereReactiveHours
*
* @param value The unit as MegavoltampereReactiveHours to create a new ElectricReactiveEnergy from.
* @returns The new ElectricReactiveEnergy instance.
*/
static FromMegavoltampereReactiveHours(value) {
return new ElectricReactiveEnergy(value, ElectricReactiveEnergyUnits.MegavoltampereReactiveHours);
}
/**
* Gets the base unit enumeration associated with ElectricReactiveEnergy
* @returns The unit enumeration that can be used to interact with this type
*/
static getUnitEnum() {
return ElectricReactiveEnergyUnits;
}
/**
* Gets the default unit used when creating instances of the unit or its DTO
* @returns The unit enumeration value used as a default parameter in constructor and DTO methods
*/
static getBaseUnit() {
return ElectricReactiveEnergyUnits.VoltampereReactiveHours;
}
/**
* Create API DTO represent a ElectricReactiveEnergy unit.
* @param holdInUnit The specific ElectricReactiveEnergy unit to be used in the unit representation at the DTO
*/
toDto(holdInUnit = ElectricReactiveEnergyUnits.VoltampereReactiveHours) {
return {
value: this.convert(holdInUnit),
unit: holdInUnit
};
}
/**
* Create a ElectricReactiveEnergy unit from an API DTO representation.
* @param dtoElectricReactiveEnergy The ElectricReactiveEnergy API DTO representation
*/
static FromDto(dtoElectricReactiveEnergy) {
return new ElectricReactiveEnergy(dtoElectricReactiveEnergy.value, dtoElectricReactiveEnergy.unit);
}
/**
* Convert ElectricReactiveEnergy to a specific unit value.
* @param toUnit The specific unit to convert to
* @returns The value of the specific unit provided.
*/
convert(toUnit) {
switch (toUnit) {
case ElectricReactiveEnergyUnits.VoltampereReactiveHours: return this.VoltampereReactiveHours;
case ElectricReactiveEnergyUnits.KilovoltampereReactiveHours: return this.KilovoltampereReactiveHours;
case ElectricReactiveEnergyUnits.MegavoltampereReactiveHours: return this.MegavoltampereReactiveHours;
default:
break;
}
return Number.NaN;
}
convertFromBase(toUnit) {
if (base_unit_1.areAnyOperatorsOverridden())
switch (toUnit) {
case ElectricReactiveEnergyUnits.VoltampereReactiveHours: return this.value;
case ElectricReactiveEnergyUnits.KilovoltampereReactiveHours: return super.internalDivide(this.value, 1000);
case ElectricReactiveEnergyUnits.MegavoltampereReactiveHours: return super.internalDivide(this.value, 1000000);
default: return Number.NaN;
}
switch (toUnit) {
case ElectricReactiveEnergyUnits.VoltampereReactiveHours: return this.value;
case ElectricReactiveEnergyUnits.KilovoltampereReactiveHours: return (this.value) / 1000;
case ElectricReactiveEnergyUnits.MegavoltampereReactiveHours: return (this.value) / 1000000;
default: return Number.NaN;
}
}
convertToBase(value, fromUnit) {
if (base_unit_1.areAnyOperatorsOverridden())
switch (fromUnit) {
case ElectricReactiveEnergyUnits.VoltampereReactiveHours: return value;
case ElectricReactiveEnergyUnits.KilovoltampereReactiveHours: return super.internalMultiply(value, 1000);
case ElectricReactiveEnergyUnits.MegavoltampereReactiveHours: return super.internalMultiply(value, 1000000);
default: return Number.NaN;
}
switch (fromUnit) {
case ElectricReactiveEnergyUnits.VoltampereReactiveHours: return value;
case ElectricReactiveEnergyUnits.KilovoltampereReactiveHours: return (value) * 1000;
case ElectricReactiveEnergyUnits.MegavoltampereReactiveHours: return (value) * 1000000;
default: return Number.NaN;
}
}
/**
* Format the ElectricReactiveEnergy to string.
* Note! the default format for ElectricReactiveEnergy is VoltampereReactiveHours.
* To specify the unit format set the 'unit' parameter.
* @param unit The unit to format the ElectricReactiveEnergy.
* @param options The ToString options, it also can be the number of fractional digits to keep that deprecated and moved to the options object. support in number will be dropped in the upcoming versions.
* @returns The string format of the ElectricReactiveEnergy.
*/
toString(unit = ElectricReactiveEnergyUnits.VoltampereReactiveHours, options) {
if (typeof options === 'number') {
console.warn('The number parameter is deprecated and moved to the options object. support in number will be dropped in the upcoming versions.');
options = { fractionalDigits: options };
}
switch (unit) {
case ElectricReactiveEnergyUnits.VoltampereReactiveHours:
return super.truncateFractionDigits(this.VoltampereReactiveHours, options) + ` varh`;
case ElectricReactiveEnergyUnits.KilovoltampereReactiveHours:
return super.truncateFractionDigits(this.KilovoltampereReactiveHours, options) + ` kvarh`;
case ElectricReactiveEnergyUnits.MegavoltampereReactiveHours:
return super.truncateFractionDigits(this.MegavoltampereReactiveHours, options) + ` Mvarh`;
default:
break;
}
return this.value.toString();
}
/**
* Get ElectricReactiveEnergy unit abbreviation.
* Note! the default abbreviation for ElectricReactiveEnergy is VoltampereReactiveHours.
* To specify the unit abbreviation set the 'unitAbbreviation' parameter.
* @param unitAbbreviation The unit abbreviation of the ElectricReactiveEnergy.
* @returns The abbreviation string of ElectricReactiveEnergy.
*/
getUnitAbbreviation(unitAbbreviation = ElectricReactiveEnergyUnits.VoltampereReactiveHours) {
switch (unitAbbreviation) {
case ElectricReactiveEnergyUnits.VoltampereReactiveHours:
return `varh`;
case ElectricReactiveEnergyUnits.KilovoltampereReactiveHours:
return `kvarh`;
case ElectricReactiveEnergyUnits.MegavoltampereReactiveHours:
return `Mvarh`;
default:
break;
}
return '';
}
/**
* Check if the given ElectricReactiveEnergy are equals to the current ElectricReactiveEnergy.
* @param electricReactiveEnergy The other ElectricReactiveEnergy.
* @returns True if the given ElectricReactiveEnergy are equal to the current ElectricReactiveEnergy.
*/
equals(electricReactiveEnergy) {
return super.internalEquals(this.value, electricReactiveEnergy.BaseValue);
}
/**
* Compare the given ElectricReactiveEnergy against the current ElectricReactiveEnergy.
* @param electricReactiveEnergy The other ElectricReactiveEnergy.
* @returns 0 if they are equal, -1 if the current ElectricReactiveEnergy is less then other, 1 if the current ElectricReactiveEnergy is greater then other.
*/
compareTo(electricReactiveEnergy) {
return super.internalCompareTo(this.value, electricReactiveEnergy.BaseValue);
}
/**
* Add the given ElectricReactiveEnergy with the current ElectricReactiveEnergy.
* @param electricReactiveEnergy The other ElectricReactiveEnergy.
* @returns A new ElectricReactiveEnergy instance with the results.
*/
add(electricReactiveEnergy) {
return new ElectricReactiveEnergy(super.internalAdd(this.value, electricReactiveEnergy.BaseValue));
}
/**
* Subtract the given ElectricReactiveEnergy with the current ElectricReactiveEnergy.
* @param electricReactiveEnergy The other ElectricReactiveEnergy.
* @returns A new ElectricReactiveEnergy instance with the results.
*/
subtract(electricReactiveEnergy) {
return new ElectricReactiveEnergy(super.internalSubtract(this.value, electricReactiveEnergy.BaseValue));
}
/**
* Multiply the given ElectricReactiveEnergy with the current ElectricReactiveEnergy.
* @param electricReactiveEnergy The other ElectricReactiveEnergy.
* @returns A new ElectricReactiveEnergy instance with the results.
*/
multiply(electricReactiveEnergy) {
return new ElectricReactiveEnergy(super.internalMultiply(this.value, electricReactiveEnergy.BaseValue));
}
/**
* Divide the given ElectricReactiveEnergy with the current ElectricReactiveEnergy.
* @param electricReactiveEnergy The other ElectricReactiveEnergy.
* @returns A new ElectricReactiveEnergy instance with the results.
*/
divide(electricReactiveEnergy) {
return new ElectricReactiveEnergy(super.internalDivide(this.value, electricReactiveEnergy.BaseValue));
}
/**
* Modulo the given ElectricReactiveEnergy with the current ElectricReactiveEnergy.
* @param electricReactiveEnergy The other ElectricReactiveEnergy.
* @returns A new ElectricReactiveEnergy instance with the results.
*/
modulo(electricReactiveEnergy) {
return new ElectricReactiveEnergy(super.internalModulo(this.value, electricReactiveEnergy.BaseValue));
}
/**
* Pow the given ElectricReactiveEnergy with the current ElectricReactiveEnergy.
* @param electricReactiveEnergy The other ElectricReactiveEnergy.
* @returns A new ElectricReactiveEnergy instance with the results.
*/
pow(electricReactiveEnergy) {
return new ElectricReactiveEnergy(super.internalPow(this.value, electricReactiveEnergy.BaseValue));
}
}
exports.ElectricReactiveEnergy = ElectricReactiveEnergy;