unitsnet-js
Version:
A better way to hold unit variables and easily convert to the destination unit
363 lines (362 loc) • 17.5 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ElectricApparentPower = exports.ElectricApparentPowerUnits = void 0;
const base_unit_1 = require("../base-unit");
/** ElectricApparentPowerUnits enumeration */
var ElectricApparentPowerUnits;
(function (ElectricApparentPowerUnits) {
/** */
ElectricApparentPowerUnits["Voltamperes"] = "Voltampere";
/** */
ElectricApparentPowerUnits["Microvoltamperes"] = "Microvoltampere";
/** */
ElectricApparentPowerUnits["Millivoltamperes"] = "Millivoltampere";
/** */
ElectricApparentPowerUnits["Kilovoltamperes"] = "Kilovoltampere";
/** */
ElectricApparentPowerUnits["Megavoltamperes"] = "Megavoltampere";
/** */
ElectricApparentPowerUnits["Gigavoltamperes"] = "Gigavoltampere";
})(ElectricApparentPowerUnits = exports.ElectricApparentPowerUnits || (exports.ElectricApparentPowerUnits = {}));
/** Power engineers measure apparent power as the magnitude of the vector sum of active and reactive power. It is the product of the root mean square voltage (in volts) and the root mean square current (in amperes). */
class ElectricApparentPower extends base_unit_1.BaseUnit {
/**
* Create a new ElectricApparentPower.
* @param value The value.
* @param fromUnit The ‘ElectricApparentPower’ unit to create from.
* The default unit is Voltamperes
*/
constructor(value, fromUnit = ElectricApparentPowerUnits.Voltamperes) {
super();
this.voltamperesLazy = null;
this.microvoltamperesLazy = null;
this.millivoltamperesLazy = null;
this.kilovoltamperesLazy = null;
this.megavoltamperesLazy = null;
this.gigavoltamperesLazy = 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 ElectricApparentPower is Voltamperes.
* 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 ElectricApparentPowerUnits.Voltamperes;
}
/** */
get Voltamperes() {
if (this.voltamperesLazy !== null) {
return this.voltamperesLazy;
}
return this.voltamperesLazy = this.convertFromBase(ElectricApparentPowerUnits.Voltamperes);
}
/** */
get Microvoltamperes() {
if (this.microvoltamperesLazy !== null) {
return this.microvoltamperesLazy;
}
return this.microvoltamperesLazy = this.convertFromBase(ElectricApparentPowerUnits.Microvoltamperes);
}
/** */
get Millivoltamperes() {
if (this.millivoltamperesLazy !== null) {
return this.millivoltamperesLazy;
}
return this.millivoltamperesLazy = this.convertFromBase(ElectricApparentPowerUnits.Millivoltamperes);
}
/** */
get Kilovoltamperes() {
if (this.kilovoltamperesLazy !== null) {
return this.kilovoltamperesLazy;
}
return this.kilovoltamperesLazy = this.convertFromBase(ElectricApparentPowerUnits.Kilovoltamperes);
}
/** */
get Megavoltamperes() {
if (this.megavoltamperesLazy !== null) {
return this.megavoltamperesLazy;
}
return this.megavoltamperesLazy = this.convertFromBase(ElectricApparentPowerUnits.Megavoltamperes);
}
/** */
get Gigavoltamperes() {
if (this.gigavoltamperesLazy !== null) {
return this.gigavoltamperesLazy;
}
return this.gigavoltamperesLazy = this.convertFromBase(ElectricApparentPowerUnits.Gigavoltamperes);
}
/**
* Create a new ElectricApparentPower instance from a Voltamperes
*
* @param value The unit as Voltamperes to create a new ElectricApparentPower from.
* @returns The new ElectricApparentPower instance.
*/
static FromVoltamperes(value) {
return new ElectricApparentPower(value, ElectricApparentPowerUnits.Voltamperes);
}
/**
* Create a new ElectricApparentPower instance from a Microvoltamperes
*
* @param value The unit as Microvoltamperes to create a new ElectricApparentPower from.
* @returns The new ElectricApparentPower instance.
*/
static FromMicrovoltamperes(value) {
return new ElectricApparentPower(value, ElectricApparentPowerUnits.Microvoltamperes);
}
/**
* Create a new ElectricApparentPower instance from a Millivoltamperes
*
* @param value The unit as Millivoltamperes to create a new ElectricApparentPower from.
* @returns The new ElectricApparentPower instance.
*/
static FromMillivoltamperes(value) {
return new ElectricApparentPower(value, ElectricApparentPowerUnits.Millivoltamperes);
}
/**
* Create a new ElectricApparentPower instance from a Kilovoltamperes
*
* @param value The unit as Kilovoltamperes to create a new ElectricApparentPower from.
* @returns The new ElectricApparentPower instance.
*/
static FromKilovoltamperes(value) {
return new ElectricApparentPower(value, ElectricApparentPowerUnits.Kilovoltamperes);
}
/**
* Create a new ElectricApparentPower instance from a Megavoltamperes
*
* @param value The unit as Megavoltamperes to create a new ElectricApparentPower from.
* @returns The new ElectricApparentPower instance.
*/
static FromMegavoltamperes(value) {
return new ElectricApparentPower(value, ElectricApparentPowerUnits.Megavoltamperes);
}
/**
* Create a new ElectricApparentPower instance from a Gigavoltamperes
*
* @param value The unit as Gigavoltamperes to create a new ElectricApparentPower from.
* @returns The new ElectricApparentPower instance.
*/
static FromGigavoltamperes(value) {
return new ElectricApparentPower(value, ElectricApparentPowerUnits.Gigavoltamperes);
}
/**
* Gets the base unit enumeration associated with ElectricApparentPower
* @returns The unit enumeration that can be used to interact with this type
*/
static getUnitEnum() {
return ElectricApparentPowerUnits;
}
/**
* 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 ElectricApparentPowerUnits.Voltamperes;
}
/**
* Create API DTO represent a ElectricApparentPower unit.
* @param holdInUnit The specific ElectricApparentPower unit to be used in the unit representation at the DTO
*/
toDto(holdInUnit = ElectricApparentPowerUnits.Voltamperes) {
return {
value: this.convert(holdInUnit),
unit: holdInUnit
};
}
/**
* Create a ElectricApparentPower unit from an API DTO representation.
* @param dtoElectricApparentPower The ElectricApparentPower API DTO representation
*/
static FromDto(dtoElectricApparentPower) {
return new ElectricApparentPower(dtoElectricApparentPower.value, dtoElectricApparentPower.unit);
}
/**
* Convert ElectricApparentPower 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 ElectricApparentPowerUnits.Voltamperes: return this.Voltamperes;
case ElectricApparentPowerUnits.Microvoltamperes: return this.Microvoltamperes;
case ElectricApparentPowerUnits.Millivoltamperes: return this.Millivoltamperes;
case ElectricApparentPowerUnits.Kilovoltamperes: return this.Kilovoltamperes;
case ElectricApparentPowerUnits.Megavoltamperes: return this.Megavoltamperes;
case ElectricApparentPowerUnits.Gigavoltamperes: return this.Gigavoltamperes;
default:
break;
}
return Number.NaN;
}
convertFromBase(toUnit) {
if (base_unit_1.areAnyOperatorsOverridden())
switch (toUnit) {
case ElectricApparentPowerUnits.Voltamperes: return this.value;
case ElectricApparentPowerUnits.Microvoltamperes: return super.internalDivide(this.value, 0.000001);
case ElectricApparentPowerUnits.Millivoltamperes: return super.internalDivide(this.value, 0.001);
case ElectricApparentPowerUnits.Kilovoltamperes: return super.internalDivide(this.value, 1000);
case ElectricApparentPowerUnits.Megavoltamperes: return super.internalDivide(this.value, 1000000);
case ElectricApparentPowerUnits.Gigavoltamperes: return super.internalDivide(this.value, 1000000000);
default: return Number.NaN;
}
switch (toUnit) {
case ElectricApparentPowerUnits.Voltamperes: return this.value;
case ElectricApparentPowerUnits.Microvoltamperes: return (this.value) / 0.000001;
case ElectricApparentPowerUnits.Millivoltamperes: return (this.value) / 0.001;
case ElectricApparentPowerUnits.Kilovoltamperes: return (this.value) / 1000;
case ElectricApparentPowerUnits.Megavoltamperes: return (this.value) / 1000000;
case ElectricApparentPowerUnits.Gigavoltamperes: return (this.value) / 1000000000;
default: return Number.NaN;
}
}
convertToBase(value, fromUnit) {
if (base_unit_1.areAnyOperatorsOverridden())
switch (fromUnit) {
case ElectricApparentPowerUnits.Voltamperes: return value;
case ElectricApparentPowerUnits.Microvoltamperes: return super.internalMultiply(value, 0.000001);
case ElectricApparentPowerUnits.Millivoltamperes: return super.internalMultiply(value, 0.001);
case ElectricApparentPowerUnits.Kilovoltamperes: return super.internalMultiply(value, 1000);
case ElectricApparentPowerUnits.Megavoltamperes: return super.internalMultiply(value, 1000000);
case ElectricApparentPowerUnits.Gigavoltamperes: return super.internalMultiply(value, 1000000000);
default: return Number.NaN;
}
switch (fromUnit) {
case ElectricApparentPowerUnits.Voltamperes: return value;
case ElectricApparentPowerUnits.Microvoltamperes: return (value) * 0.000001;
case ElectricApparentPowerUnits.Millivoltamperes: return (value) * 0.001;
case ElectricApparentPowerUnits.Kilovoltamperes: return (value) * 1000;
case ElectricApparentPowerUnits.Megavoltamperes: return (value) * 1000000;
case ElectricApparentPowerUnits.Gigavoltamperes: return (value) * 1000000000;
default: return Number.NaN;
}
}
/**
* Format the ElectricApparentPower to string.
* Note! the default format for ElectricApparentPower is Voltamperes.
* To specify the unit format set the 'unit' parameter.
* @param unit The unit to format the ElectricApparentPower.
* @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 ElectricApparentPower.
*/
toString(unit = ElectricApparentPowerUnits.Voltamperes, 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 ElectricApparentPowerUnits.Voltamperes:
return super.truncateFractionDigits(this.Voltamperes, options) + ` VA`;
case ElectricApparentPowerUnits.Microvoltamperes:
return super.truncateFractionDigits(this.Microvoltamperes, options) + ` μVA`;
case ElectricApparentPowerUnits.Millivoltamperes:
return super.truncateFractionDigits(this.Millivoltamperes, options) + ` mVA`;
case ElectricApparentPowerUnits.Kilovoltamperes:
return super.truncateFractionDigits(this.Kilovoltamperes, options) + ` kVA`;
case ElectricApparentPowerUnits.Megavoltamperes:
return super.truncateFractionDigits(this.Megavoltamperes, options) + ` MVA`;
case ElectricApparentPowerUnits.Gigavoltamperes:
return super.truncateFractionDigits(this.Gigavoltamperes, options) + ` GVA`;
default:
break;
}
return this.value.toString();
}
/**
* Get ElectricApparentPower unit abbreviation.
* Note! the default abbreviation for ElectricApparentPower is Voltamperes.
* To specify the unit abbreviation set the 'unitAbbreviation' parameter.
* @param unitAbbreviation The unit abbreviation of the ElectricApparentPower.
* @returns The abbreviation string of ElectricApparentPower.
*/
getUnitAbbreviation(unitAbbreviation = ElectricApparentPowerUnits.Voltamperes) {
switch (unitAbbreviation) {
case ElectricApparentPowerUnits.Voltamperes:
return `VA`;
case ElectricApparentPowerUnits.Microvoltamperes:
return `μVA`;
case ElectricApparentPowerUnits.Millivoltamperes:
return `mVA`;
case ElectricApparentPowerUnits.Kilovoltamperes:
return `kVA`;
case ElectricApparentPowerUnits.Megavoltamperes:
return `MVA`;
case ElectricApparentPowerUnits.Gigavoltamperes:
return `GVA`;
default:
break;
}
return '';
}
/**
* Check if the given ElectricApparentPower are equals to the current ElectricApparentPower.
* @param electricApparentPower The other ElectricApparentPower.
* @returns True if the given ElectricApparentPower are equal to the current ElectricApparentPower.
*/
equals(electricApparentPower) {
return super.internalEquals(this.value, electricApparentPower.BaseValue);
}
/**
* Compare the given ElectricApparentPower against the current ElectricApparentPower.
* @param electricApparentPower The other ElectricApparentPower.
* @returns 0 if they are equal, -1 if the current ElectricApparentPower is less then other, 1 if the current ElectricApparentPower is greater then other.
*/
compareTo(electricApparentPower) {
return super.internalCompareTo(this.value, electricApparentPower.BaseValue);
}
/**
* Add the given ElectricApparentPower with the current ElectricApparentPower.
* @param electricApparentPower The other ElectricApparentPower.
* @returns A new ElectricApparentPower instance with the results.
*/
add(electricApparentPower) {
return new ElectricApparentPower(super.internalAdd(this.value, electricApparentPower.BaseValue));
}
/**
* Subtract the given ElectricApparentPower with the current ElectricApparentPower.
* @param electricApparentPower The other ElectricApparentPower.
* @returns A new ElectricApparentPower instance with the results.
*/
subtract(electricApparentPower) {
return new ElectricApparentPower(super.internalSubtract(this.value, electricApparentPower.BaseValue));
}
/**
* Multiply the given ElectricApparentPower with the current ElectricApparentPower.
* @param electricApparentPower The other ElectricApparentPower.
* @returns A new ElectricApparentPower instance with the results.
*/
multiply(electricApparentPower) {
return new ElectricApparentPower(super.internalMultiply(this.value, electricApparentPower.BaseValue));
}
/**
* Divide the given ElectricApparentPower with the current ElectricApparentPower.
* @param electricApparentPower The other ElectricApparentPower.
* @returns A new ElectricApparentPower instance with the results.
*/
divide(electricApparentPower) {
return new ElectricApparentPower(super.internalDivide(this.value, electricApparentPower.BaseValue));
}
/**
* Modulo the given ElectricApparentPower with the current ElectricApparentPower.
* @param electricApparentPower The other ElectricApparentPower.
* @returns A new ElectricApparentPower instance with the results.
*/
modulo(electricApparentPower) {
return new ElectricApparentPower(super.internalModulo(this.value, electricApparentPower.BaseValue));
}
/**
* Pow the given ElectricApparentPower with the current ElectricApparentPower.
* @param electricApparentPower The other ElectricApparentPower.
* @returns A new ElectricApparentPower instance with the results.
*/
pow(electricApparentPower) {
return new ElectricApparentPower(super.internalPow(this.value, electricApparentPower.BaseValue));
}
}
exports.ElectricApparentPower = ElectricApparentPower;