Keine Explizite Temperatur-Umrechungs-Logik mehr im generischen JavaScript
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
image: umrechner:v1.0.3
|
||||
image: umrechner:v1.0.4
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- POCKETBASE_URL={$POCKETBASE_URL}
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
{{ define "main" }}
|
||||
{{ $catData := index hugo.Data .Params.category }}
|
||||
{{ $config := "" }}
|
||||
{{ if eq .Params.engine "linear" }}
|
||||
{{ $config = dict "fromFactor" .Params.from_factor
|
||||
"toFactor" .Params.to_factor | jsonify }}
|
||||
{{ else if eq .Params.engine "intermediate" }}
|
||||
{{ $config = dict "fromUnit" .Params.from_unit
|
||||
"toUnit" .Params.to_unit | jsonify }}
|
||||
{{ $toExpr := index $catData.to_intermediate
|
||||
.Params.from | default "v" }}
|
||||
{{ $fromExpr := index $catData.from_intermediate
|
||||
.Params.to | default "v" }}
|
||||
{{ $config = printf
|
||||
"{ toIntermediate: v => %s, fromIntermediate: v => %s }"
|
||||
$toExpr $fromExpr }}
|
||||
{{ else if eq .Params.engine "runtime" }}
|
||||
{{ $config = dict "fromCurrency" .Params.from
|
||||
"toCurrency" .Params.to | jsonify }}
|
||||
{{ end }}
|
||||
|
||||
{{ $catData := index hugo.Data .Params.category }}
|
||||
{{ $availableUnits := partial "available-units.html"
|
||||
(dict "category" .Params.category "units" $catData.units) }}
|
||||
|
||||
|
||||
@@ -152,11 +152,10 @@ function createConverter(engine, config) {
|
||||
rawResult = value.times(fromFactor)
|
||||
.dividedBy(toFactor);
|
||||
} else if (engine === 'intermediate') {
|
||||
rawResult = convertTemperature(
|
||||
value,
|
||||
config.fromUnit,
|
||||
config.toUnit
|
||||
);
|
||||
let v = value.toNumber();
|
||||
v = config.toIntermediate(v);
|
||||
v = config.fromIntermediate(v);
|
||||
rawResult = new Decimal(v);
|
||||
} else {
|
||||
this.result = '';
|
||||
return;
|
||||
@@ -176,36 +175,6 @@ function createConverter(engine, config) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Temperature conversion via Celsius intermediate.
|
||||
* @param {Decimal} value
|
||||
* @param {string} fromUnit
|
||||
* @param {string} toUnit
|
||||
* @returns {number}
|
||||
*/
|
||||
function convertTemperature(value, fromUnit, toUnit) {
|
||||
let v = value.toNumber();
|
||||
if (fromUnit === 'fahrenheit') {
|
||||
v = (v - 32) * 5 / 9;
|
||||
} else if (fromUnit === 'kelvin') {
|
||||
v = v - 273.15;
|
||||
} else if (fromUnit === 'rankine') {
|
||||
v = (v - 491.67) * 5 / 9;
|
||||
} else if (fromUnit === 'reaumur') {
|
||||
v = v * 5 / 4;
|
||||
}
|
||||
if (toUnit === 'fahrenheit') {
|
||||
v = v * 9 / 5 + 32;
|
||||
} else if (toUnit === 'kelvin') {
|
||||
v = v + 273.15;
|
||||
} else if (toUnit === 'rankine') {
|
||||
v = (v + 273.15) * 9 / 5;
|
||||
} else if (toUnit === 'reaumur') {
|
||||
v = v * 4 / 5;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a number as plain digits with dot as decimal separator.
|
||||
* @param {Decimal|string|number} num
|
||||
|
||||
Reference in New Issue
Block a user