mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
fix(admin-ui): keep sign and precision in CSV, YAML and context labels
CSV export prefixed negative numbers with an apostrophe, which corrupted the data. YAML emitted NaN and Infinity as plain strings. Context windows such as 1500 read as 2k. Numbers now skip the CSV formula guard, non-finite values use YAML float forms, and counts below 10k keep one decimal.
This commit is contained in:
@@ -148,10 +148,19 @@ export function emitYamlKey(key: string): string {
|
||||
return yamlKeyNeedsQuoting(key) ? escapeYamlUnsafeControls(JSON.stringify(key)) : key
|
||||
}
|
||||
|
||||
/** yamlNumber spells non-finite values with their YAML 1.2 float forms; String(NaN) is a plain string in YAML. */
|
||||
function yamlNumber(n: number): string {
|
||||
if (Number.isNaN(n)) return '.nan'
|
||||
if (n === Infinity) return '.inf'
|
||||
if (n === -Infinity) return '-.inf'
|
||||
return String(n)
|
||||
}
|
||||
|
||||
/** emitYamlScalar renders one leaf value in "key: <here>" position OR a flow list/map element — quoted (JSON-style) whenever needsQuoting says the plain form is unsafe, plain otherwise. Booleans/numbers/null render via their own JS literal, never through the string quoting path (a real `true`/`false`/`null`/number is safe unquoted by construction — only a STRING value can accidentally spell one of those). */
|
||||
export function emitYamlScalar(value: YamlPrimitive): string {
|
||||
if (value === null) return 'null'
|
||||
if (typeof value === 'boolean' || typeof value === 'number') return String(value)
|
||||
if (typeof value === 'number') return yamlNumber(value)
|
||||
if (typeof value === 'boolean') return String(value)
|
||||
return needsQuoting(value) ? escapeYamlUnsafeControls(JSON.stringify(value)) : value
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user