unitsnet-js
Version:
A better way to hold unit variables and easily convert to the destination unit
251 lines (250 loc) • 11.3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThermalResistance = exports.ThermalResistanceUnits = void 0;
const base_unit_1 = require("../base-unit");
/** ThermalResistanceUnits enumeration */
var ThermalResistanceUnits;
(function (ThermalResistanceUnits) {
/** */
ThermalResistanceUnits["KelvinsPerWatt"] = "KelvinPerWatt";
/** */
ThermalResistanceUnits["DegreesCelsiusPerWatt"] = "DegreeCelsiusPerWatt";
})(ThermalResistanceUnits = exports.ThermalResistanceUnits || (exports.ThermalResistanceUnits = {}));
/** Thermal resistance (R) measures the opposition to the heat current in a material or system. It is measured in units of kelvins per watt (K/W) and indicates how much temperature difference (in kelvins) is required to transfer a unit of heat current (in watts) through the material or object. It is essential to optimize the building insulation, evaluate the efficiency of electronic devices, and enhance the performance of heat sinks in various applications. */
class ThermalResistance extends base_unit_1.BaseUnit {
/**
* Create a new ThermalResistance.
* @param value The value.
* @param fromUnit The ‘ThermalResistance’ unit to create from.
* The default unit is KelvinsPerWatt
*/
constructor(value, fromUnit = ThermalResistanceUnits.KelvinsPerWatt) {
super();
this.kelvinsperwattLazy = null;
this.degreescelsiusperwattLazy = 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 ThermalResistance is KelvinsPerWatt.
* 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 ThermalResistanceUnits.KelvinsPerWatt;
}
/** */
get KelvinsPerWatt() {
if (this.kelvinsperwattLazy !== null) {
return this.kelvinsperwattLazy;
}
return this.kelvinsperwattLazy = this.convertFromBase(ThermalResistanceUnits.KelvinsPerWatt);
}
/** */
get DegreesCelsiusPerWatt() {
if (this.degreescelsiusperwattLazy !== null) {
return this.degreescelsiusperwattLazy;
}
return this.degreescelsiusperwattLazy = this.convertFromBase(ThermalResistanceUnits.DegreesCelsiusPerWatt);
}
/**
* Create a new ThermalResistance instance from a KelvinsPerWatt
*
* @param value The unit as KelvinsPerWatt to create a new ThermalResistance from.
* @returns The new ThermalResistance instance.
*/
static FromKelvinsPerWatt(value) {
return new ThermalResistance(value, ThermalResistanceUnits.KelvinsPerWatt);
}
/**
* Create a new ThermalResistance instance from a DegreesCelsiusPerWatt
*
* @param value The unit as DegreesCelsiusPerWatt to create a new ThermalResistance from.
* @returns The new ThermalResistance instance.
*/
static FromDegreesCelsiusPerWatt(value) {
return new ThermalResistance(value, ThermalResistanceUnits.DegreesCelsiusPerWatt);
}
/**
* Gets the base unit enumeration associated with ThermalResistance
* @returns The unit enumeration that can be used to interact with this type
*/
static getUnitEnum() {
return ThermalResistanceUnits;
}
/**
* 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 ThermalResistanceUnits.KelvinsPerWatt;
}
/**
* Create API DTO represent a ThermalResistance unit.
* @param holdInUnit The specific ThermalResistance unit to be used in the unit representation at the DTO
*/
toDto(holdInUnit = ThermalResistanceUnits.KelvinsPerWatt) {
return {
value: this.convert(holdInUnit),
unit: holdInUnit
};
}
/**
* Create a ThermalResistance unit from an API DTO representation.
* @param dtoThermalResistance The ThermalResistance API DTO representation
*/
static FromDto(dtoThermalResistance) {
return new ThermalResistance(dtoThermalResistance.value, dtoThermalResistance.unit);
}
/**
* Convert ThermalResistance 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 ThermalResistanceUnits.KelvinsPerWatt: return this.KelvinsPerWatt;
case ThermalResistanceUnits.DegreesCelsiusPerWatt: return this.DegreesCelsiusPerWatt;
default:
break;
}
return Number.NaN;
}
convertFromBase(toUnit) {
if (base_unit_1.areAnyOperatorsOverridden())
switch (toUnit) {
case ThermalResistanceUnits.KelvinsPerWatt: return this.value;
case ThermalResistanceUnits.DegreesCelsiusPerWatt: return this.value;
default: return Number.NaN;
}
switch (toUnit) {
case ThermalResistanceUnits.KelvinsPerWatt: return this.value;
case ThermalResistanceUnits.DegreesCelsiusPerWatt: return this.value;
default: return Number.NaN;
}
}
convertToBase(value, fromUnit) {
if (base_unit_1.areAnyOperatorsOverridden())
switch (fromUnit) {
case ThermalResistanceUnits.KelvinsPerWatt: return value;
case ThermalResistanceUnits.DegreesCelsiusPerWatt: return value;
default: return Number.NaN;
}
switch (fromUnit) {
case ThermalResistanceUnits.KelvinsPerWatt: return value;
case ThermalResistanceUnits.DegreesCelsiusPerWatt: return value;
default: return Number.NaN;
}
}
/**
* Format the ThermalResistance to string.
* Note! the default format for ThermalResistance is KelvinsPerWatt.
* To specify the unit format set the 'unit' parameter.
* @param unit The unit to format the ThermalResistance.
* @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 ThermalResistance.
*/
toString(unit = ThermalResistanceUnits.KelvinsPerWatt, 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 ThermalResistanceUnits.KelvinsPerWatt:
return super.truncateFractionDigits(this.KelvinsPerWatt, options) + ` K/W`;
case ThermalResistanceUnits.DegreesCelsiusPerWatt:
return super.truncateFractionDigits(this.DegreesCelsiusPerWatt, options) + ` °C/W`;
default:
break;
}
return this.value.toString();
}
/**
* Get ThermalResistance unit abbreviation.
* Note! the default abbreviation for ThermalResistance is KelvinsPerWatt.
* To specify the unit abbreviation set the 'unitAbbreviation' parameter.
* @param unitAbbreviation The unit abbreviation of the ThermalResistance.
* @returns The abbreviation string of ThermalResistance.
*/
getUnitAbbreviation(unitAbbreviation = ThermalResistanceUnits.KelvinsPerWatt) {
switch (unitAbbreviation) {
case ThermalResistanceUnits.KelvinsPerWatt:
return `K/W`;
case ThermalResistanceUnits.DegreesCelsiusPerWatt:
return `°C/W`;
default:
break;
}
return '';
}
/**
* Check if the given ThermalResistance are equals to the current ThermalResistance.
* @param thermalResistance The other ThermalResistance.
* @returns True if the given ThermalResistance are equal to the current ThermalResistance.
*/
equals(thermalResistance) {
return super.internalEquals(this.value, thermalResistance.BaseValue);
}
/**
* Compare the given ThermalResistance against the current ThermalResistance.
* @param thermalResistance The other ThermalResistance.
* @returns 0 if they are equal, -1 if the current ThermalResistance is less then other, 1 if the current ThermalResistance is greater then other.
*/
compareTo(thermalResistance) {
return super.internalCompareTo(this.value, thermalResistance.BaseValue);
}
/**
* Add the given ThermalResistance with the current ThermalResistance.
* @param thermalResistance The other ThermalResistance.
* @returns A new ThermalResistance instance with the results.
*/
add(thermalResistance) {
return new ThermalResistance(super.internalAdd(this.value, thermalResistance.BaseValue));
}
/**
* Subtract the given ThermalResistance with the current ThermalResistance.
* @param thermalResistance The other ThermalResistance.
* @returns A new ThermalResistance instance with the results.
*/
subtract(thermalResistance) {
return new ThermalResistance(super.internalSubtract(this.value, thermalResistance.BaseValue));
}
/**
* Multiply the given ThermalResistance with the current ThermalResistance.
* @param thermalResistance The other ThermalResistance.
* @returns A new ThermalResistance instance with the results.
*/
multiply(thermalResistance) {
return new ThermalResistance(super.internalMultiply(this.value, thermalResistance.BaseValue));
}
/**
* Divide the given ThermalResistance with the current ThermalResistance.
* @param thermalResistance The other ThermalResistance.
* @returns A new ThermalResistance instance with the results.
*/
divide(thermalResistance) {
return new ThermalResistance(super.internalDivide(this.value, thermalResistance.BaseValue));
}
/**
* Modulo the given ThermalResistance with the current ThermalResistance.
* @param thermalResistance The other ThermalResistance.
* @returns A new ThermalResistance instance with the results.
*/
modulo(thermalResistance) {
return new ThermalResistance(super.internalModulo(this.value, thermalResistance.BaseValue));
}
/**
* Pow the given ThermalResistance with the current ThermalResistance.
* @param thermalResistance The other ThermalResistance.
* @returns A new ThermalResistance instance with the results.
*/
pow(thermalResistance) {
return new ThermalResistance(super.internalPow(this.value, thermalResistance.BaseValue));
}
}
exports.ThermalResistance = ThermalResistance;