Keine Explizite Temperatur-Umrechungs-Logik mehr im generischen JavaScript

This commit is contained in:
2026-05-29 19:57:28 +02:00
parent 3631674ee3
commit 9dff578c15
3 changed files with 13 additions and 40 deletions

View File

@@ -1,7 +1,7 @@
services: services:
web: web:
build: . build: .
image: umrechner:v1.0.3 image: umrechner:v1.0.4
restart: unless-stopped restart: unless-stopped
environment: environment:
- POCKETBASE_URL={$POCKETBASE_URL} - POCKETBASE_URL={$POCKETBASE_URL}

View File

@@ -1,17 +1,21 @@
{{ define "main" }} {{ define "main" }}
{{ $catData := index hugo.Data .Params.category }}
{{ $config := "" }} {{ $config := "" }}
{{ if eq .Params.engine "linear" }} {{ if eq .Params.engine "linear" }}
{{ $config = dict "fromFactor" .Params.from_factor {{ $config = dict "fromFactor" .Params.from_factor
"toFactor" .Params.to_factor | jsonify }} "toFactor" .Params.to_factor | jsonify }}
{{ else if eq .Params.engine "intermediate" }} {{ else if eq .Params.engine "intermediate" }}
{{ $config = dict "fromUnit" .Params.from_unit {{ $toExpr := index $catData.to_intermediate
"toUnit" .Params.to_unit | jsonify }} .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" }} {{ else if eq .Params.engine "runtime" }}
{{ $config = dict "fromCurrency" .Params.from {{ $config = dict "fromCurrency" .Params.from
"toCurrency" .Params.to | jsonify }} "toCurrency" .Params.to | jsonify }}
{{ end }} {{ end }}
{{ $catData := index hugo.Data .Params.category }}
{{ $availableUnits := partial "available-units.html" {{ $availableUnits := partial "available-units.html"
(dict "category" .Params.category "units" $catData.units) }} (dict "category" .Params.category "units" $catData.units) }}

View File

@@ -152,11 +152,10 @@ function createConverter(engine, config) {
rawResult = value.times(fromFactor) rawResult = value.times(fromFactor)
.dividedBy(toFactor); .dividedBy(toFactor);
} else if (engine === 'intermediate') { } else if (engine === 'intermediate') {
rawResult = convertTemperature( let v = value.toNumber();
value, v = config.toIntermediate(v);
config.fromUnit, v = config.fromIntermediate(v);
config.toUnit rawResult = new Decimal(v);
);
} else { } else {
this.result = ''; this.result = '';
return; 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. * Formats a number as plain digits with dot as decimal separator.
* @param {Decimal|string|number} num * @param {Decimal|string|number} num