unitsnet-js
Version:
A better way to hold unit variables and easily convert to the destination unit
279 lines (278 loc) • 13.3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ElectricApparentEnergy = exports.ElectricApparentEnergyUnits = void 0;
const base_unit_1 = require("../base-unit");
/** ElectricApparentEnergyUnits enumeration */
var ElectricApparentEnergyUnits;
(function (ElectricApparentEnergyUnits) {
/** */
ElectricApparentEnergyUnits["VoltampereHours"] = "VoltampereHour";
/** */
ElectricApparentEnergyUnits["KilovoltampereHours"] = "KilovoltampereHour";
/** */
ElectricApparentEnergyUnits["MegavoltampereHours"] = "MegavoltampereHour";
})(ElectricApparentEnergyUnits = exports.ElectricApparentEnergyUnits || (exports.ElectricApparentEnergyUnits = {}));
/** A unit for expressing the integral of apparent power over time, equal to the product of 1 volt-ampere and 1 hour, or to 3600 joules. */
class ElectricApparentEnergy extends base_unit_1.BaseUnit {
/**
* Create a new ElectricApparentEnergy.
* @param value The value.
* @param fromUnit The ‘ElectricApparentEnergy’ unit to create from.
* The default unit is VoltampereHours
*/
constructor(value, fromUnit = ElectricApparentEnergyUnits.VoltampereHours) {
super();
this.voltamperehoursLazy = null;
this.kilovoltamperehoursLazy = null;
this.megavoltamperehoursLazy = 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 ElectricApparentEnergy is VoltampereHours.
* 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 ElectricApparentEnergyUnits.VoltampereHours;
}
/** */
get VoltampereHours() {
if (this.voltamperehoursLazy !== null) {
return this.voltamperehoursLazy;
}
return this.voltamperehoursLazy = this.convertFromBase(ElectricApparentEnergyUnits.VoltampereHours);
}
/** */
get KilovoltampereHours() {
if (this.kilovoltamperehoursLazy !== null) {
return this.kilovoltamperehoursLazy;
}
return this.kilovoltamperehoursLazy = this.convertFromBase(ElectricApparentEnergyUnits.KilovoltampereHours);
}
/** */
get MegavoltampereHours() {
if (this.megavoltamperehoursLazy !== null) {
return this.megavoltamperehoursLazy;
}
return this.megavoltamperehoursLazy = this.convertFromBase(ElectricApparentEnergyUnits.MegavoltampereHours);
}
/**
* Create a new ElectricApparentEnergy instance from a VoltampereHours
*
* @param value The unit as VoltampereHours to create a new ElectricApparentEnergy from.
* @returns The new ElectricApparentEnergy instance.
*/
static FromVoltampereHours(value) {
return new ElectricApparentEnergy(value, ElectricApparentEnergyUnits.VoltampereHours);
}
/**
* Create a new ElectricApparentEnergy instance from a KilovoltampereHours
*
* @param value The unit as KilovoltampereHours to create a new ElectricApparentEnergy from.
* @returns The new ElectricApparentEnergy instance.
*/
static FromKilovoltampereHours(value) {
return new ElectricApparentEnergy(value, ElectricApparentEnergyUnits.KilovoltampereHours);
}
/**
* Create a new ElectricApparentEnergy instance from a MegavoltampereHours
*
* @param value The unit as MegavoltampereHours to create a new ElectricApparentEnergy from.
* @returns The new ElectricApparentEnergy instance.
*/
static FromMegavoltampereHours(value) {
return new ElectricApparentEnergy(value, ElectricApparentEnergyUnits.MegavoltampereHours);
}
/**
* Gets the base unit enumeration associated with ElectricApparentEnergy
* @returns The unit enumeration that can be used to interact with this type
*/
static getUnitEnum() {
return ElectricApparentEnergyUnits;
}
/**
* 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 ElectricApparentEnergyUnits.VoltampereHours;
}
/**
* Create API DTO represent a ElectricApparentEnergy unit.
* @param holdInUnit The specific ElectricApparentEnergy unit to be used in the unit representation at the DTO
*/
toDto(holdInUnit = ElectricApparentEnergyUnits.VoltampereHours) {
return {
value: this.convert(holdInUnit),
unit: holdInUnit
};
}
/**
* Create a ElectricApparentEnergy unit from an API DTO representation.
* @param dtoElectricApparentEnergy The ElectricApparentEnergy API DTO representation
*/
static FromDto(dtoElectricApparentEnergy) {
return new ElectricApparentEnergy(dtoElectricApparentEnergy.value, dtoElectricApparentEnergy.unit);
}
/**
* Convert ElectricApparentEnergy 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 ElectricApparentEnergyUnits.VoltampereHours: return this.VoltampereHours;
case ElectricApparentEnergyUnits.KilovoltampereHours: return this.KilovoltampereHours;
case ElectricApparentEnergyUnits.MegavoltampereHours: return this.MegavoltampereHours;
default:
break;
}
return Number.NaN;
}
convertFromBase(toUnit) {
if (base_unit_1.areAnyOperatorsOverridden())
switch (toUnit) {
case ElectricApparentEnergyUnits.VoltampereHours: return this.value;
case ElectricApparentEnergyUnits.KilovoltampereHours: return super.internalDivide(this.value, 1000);
case ElectricApparentEnergyUnits.MegavoltampereHours: return super.internalDivide(this.value, 1000000);
default: return Number.NaN;
}
switch (toUnit) {
case ElectricApparentEnergyUnits.VoltampereHours: return this.value;
case ElectricApparentEnergyUnits.KilovoltampereHours: return (this.value) / 1000;
case ElectricApparentEnergyUnits.MegavoltampereHours: return (this.value) / 1000000;
default: return Number.NaN;
}
}
convertToBase(value, fromUnit) {
if (base_unit_1.areAnyOperatorsOverridden())
switch (fromUnit) {
case ElectricApparentEnergyUnits.VoltampereHours: return value;
case ElectricApparentEnergyUnits.KilovoltampereHours: return super.internalMultiply(value, 1000);
case ElectricApparentEnergyUnits.MegavoltampereHours: return super.internalMultiply(value, 1000000);
default: return Number.NaN;
}
switch (fromUnit) {
case ElectricApparentEnergyUnits.VoltampereHours: return value;
case ElectricApparentEnergyUnits.KilovoltampereHours: return (value) * 1000;
case ElectricApparentEnergyUnits.MegavoltampereHours: return (value) * 1000000;
default: return Number.NaN;
}
}
/**
* Format the ElectricApparentEnergy to string.
* Note! the default format for ElectricApparentEnergy is VoltampereHours.
* To specify the unit format set the 'unit' parameter.
* @param unit The unit to format the ElectricApparentEnergy.
* @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 ElectricApparentEnergy.
*/
toString(unit = ElectricApparentEnergyUnits.VoltampereHours, 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 ElectricApparentEnergyUnits.VoltampereHours:
return super.truncateFractionDigits(this.VoltampereHours, options) + ` VAh`;
case ElectricApparentEnergyUnits.KilovoltampereHours:
return super.truncateFractionDigits(this.KilovoltampereHours, options) + ` kVAh`;
case ElectricApparentEnergyUnits.MegavoltampereHours:
return super.truncateFractionDigits(this.MegavoltampereHours, options) + ` MVAh`;
default:
break;
}
return this.value.toString();
}
/**
* Get ElectricApparentEnergy unit abbreviation.
* Note! the default abbreviation for ElectricApparentEnergy is VoltampereHours.
* To specify the unit abbreviation set the 'unitAbbreviation' parameter.
* @param unitAbbreviation The unit abbreviation of the ElectricApparentEnergy.
* @returns The abbreviation string of ElectricApparentEnergy.
*/
getUnitAbbreviation(unitAbbreviation = ElectricApparentEnergyUnits.VoltampereHours) {
switch (unitAbbreviation) {
case ElectricApparentEnergyUnits.VoltampereHours:
return `VAh`;
case ElectricApparentEnergyUnits.KilovoltampereHours:
return `kVAh`;
case ElectricApparentEnergyUnits.MegavoltampereHours:
return `MVAh`;
default:
break;
}
return '';
}
/**
* Check if the given ElectricApparentEnergy are equals to the current ElectricApparentEnergy.
* @param electricApparentEnergy The other ElectricApparentEnergy.
* @returns True if the given ElectricApparentEnergy are equal to the current ElectricApparentEnergy.
*/
equals(electricApparentEnergy) {
return super.internalEquals(this.value, electricApparentEnergy.BaseValue);
}
/**
* Compare the given ElectricApparentEnergy against the current ElectricApparentEnergy.
* @param electricApparentEnergy The other ElectricApparentEnergy.
* @returns 0 if they are equal, -1 if the current ElectricApparentEnergy is less then other, 1 if the current ElectricApparentEnergy is greater then other.
*/
compareTo(electricApparentEnergy) {
return super.internalCompareTo(this.value, electricApparentEnergy.BaseValue);
}
/**
* Add the given ElectricApparentEnergy with the current ElectricApparentEnergy.
* @param electricApparentEnergy The other ElectricApparentEnergy.
* @returns A new ElectricApparentEnergy instance with the results.
*/
add(electricApparentEnergy) {
return new ElectricApparentEnergy(super.internalAdd(this.value, electricApparentEnergy.BaseValue));
}
/**
* Subtract the given ElectricApparentEnergy with the current ElectricApparentEnergy.
* @param electricApparentEnergy The other ElectricApparentEnergy.
* @returns A new ElectricApparentEnergy instance with the results.
*/
subtract(electricApparentEnergy) {
return new ElectricApparentEnergy(super.internalSubtract(this.value, electricApparentEnergy.BaseValue));
}
/**
* Multiply the given ElectricApparentEnergy with the current ElectricApparentEnergy.
* @param electricApparentEnergy The other ElectricApparentEnergy.
* @returns A new ElectricApparentEnergy instance with the results.
*/
multiply(electricApparentEnergy) {
return new ElectricApparentEnergy(super.internalMultiply(this.value, electricApparentEnergy.BaseValue));
}
/**
* Divide the given ElectricApparentEnergy with the current ElectricApparentEnergy.
* @param electricApparentEnergy The other ElectricApparentEnergy.
* @returns A new ElectricApparentEnergy instance with the results.
*/
divide(electricApparentEnergy) {
return new ElectricApparentEnergy(super.internalDivide(this.value, electricApparentEnergy.BaseValue));
}
/**
* Modulo the given ElectricApparentEnergy with the current ElectricApparentEnergy.
* @param electricApparentEnergy The other ElectricApparentEnergy.
* @returns A new ElectricApparentEnergy instance with the results.
*/
modulo(electricApparentEnergy) {
return new ElectricApparentEnergy(super.internalModulo(this.value, electricApparentEnergy.BaseValue));
}
/**
* Pow the given ElectricApparentEnergy with the current ElectricApparentEnergy.
* @param electricApparentEnergy The other ElectricApparentEnergy.
* @returns A new ElectricApparentEnergy instance with the results.
*/
pow(electricApparentEnergy) {
return new ElectricApparentEnergy(super.internalPow(this.value, electricApparentEnergy.BaseValue));
}
}
exports.ElectricApparentEnergy = ElectricApparentEnergy;