Request
Format-Toml (added in #20) currently only expands structure into [a.b] header form and offers -Indent to control cosmetic whitespace around that expanded form. There's no way to go the other direction: collapsing structure into TOML's compact forms.
TOML supports several compact representations that are semantically equivalent to the expanded [a.b] header form:
- Inline tables:
point = { x = 1, y = 2 } instead of a [point] section (single-line only, per spec).
- Dotted keys:
physical.color = "orange" instead of a full [physical] table with a color key.
- Arrays of inline tables:
points = [{ x = 1, y = 2 }, { x = 3, y = 4 }] instead of repeated [[points]] sections.
A -Compact switch (or similar) on Format-Toml would collapse eligible tables into these forms, giving users a "canonical compact form" the same way -Indent gives a "canonical expanded form".
Desired capability
Format-Toml -InputObject $s -Compact
# [server]
# host = "localhost"
# port = 8080
#
# becomes:
# server = { host = "localhost", port = 8080 }
Technical decisions to make
- This is not a text-level post-process like
-Indent/Add-TomlIndentation — collapsing requires restructuring the serialization itself, most likely in ConvertTo-TomlTableObject / Add-TomlTableText (or a parallel emission path), since it changes which TOML construct is emitted for a given value, not just its surrounding whitespace.
- Array-of-tables (
[[x]]) sections don't have as clean a mapping to a single-line inline-table array once nesting or dotted-key children are involved — needs a defined collapsing rule (e.g. only collapse array-of-tables into inline-table arrays when every table is "leaf" — no further nested tables).
- TOML forbids multi-line inline tables, so collapsing arbitrarily deep/wide tables can produce very long single lines. May need a size/depth cutoff, or leave that entirely to the caller (no automatic fallback to expanded form).
- Decide whether this lives as
ConvertTo-Toml -Compact (so Import-Toml | ConvertTo-Toml -Compact also benefits) with Format-Toml -Compact simply passing it through, or as Format-Toml-only logic. Placing it in ConvertTo-Toml seems more consistent with the module's reuse-first design (Format-Toml is currently just ConvertFrom-Toml | ConvertTo-Toml plus indentation).
Acceptance criteria
-Compact produces valid, parseable TOML equivalent in meaning to the expanded input.
- Round-trip:
ConvertFrom-Toml (Format-Toml $s -Compact) equals ConvertFrom-Toml $s in data terms.
- Clear documentation of which structures are/aren't collapsed and why (esp. array-of-tables edge cases).
Related
Request
Format-Toml(added in #20) currently only expands structure into[a.b]header form and offers-Indentto control cosmetic whitespace around that expanded form. There's no way to go the other direction: collapsing structure into TOML's compact forms.TOML supports several compact representations that are semantically equivalent to the expanded
[a.b]header form:point = { x = 1, y = 2 }instead of a[point]section (single-line only, per spec).physical.color = "orange"instead of a full[physical]table with acolorkey.points = [{ x = 1, y = 2 }, { x = 3, y = 4 }]instead of repeated[[points]]sections.A
-Compactswitch (or similar) onFormat-Tomlwould collapse eligible tables into these forms, giving users a "canonical compact form" the same way-Indentgives a "canonical expanded form".Desired capability
Technical decisions to make
-Indent/Add-TomlIndentation— collapsing requires restructuring the serialization itself, most likely inConvertTo-TomlTableObject/Add-TomlTableText(or a parallel emission path), since it changes which TOML construct is emitted for a given value, not just its surrounding whitespace.[[x]]) sections don't have as clean a mapping to a single-line inline-table array once nesting or dotted-key children are involved — needs a defined collapsing rule (e.g. only collapse array-of-tables into inline-table arrays when every table is "leaf" — no further nested tables).ConvertTo-Toml -Compact(soImport-Toml | ConvertTo-Toml -Compactalso benefits) withFormat-Toml -Compactsimply passing it through, or asFormat-Toml-only logic. Placing it inConvertTo-Tomlseems more consistent with the module's reuse-first design (Format-Tomlis currently justConvertFrom-Toml | ConvertTo-Tomlplus indentation).Acceptance criteria
-Compactproduces valid, parseable TOML equivalent in meaning to the expanded input.ConvertFrom-Toml (Format-Toml $s -Compact)equalsConvertFrom-Toml $sin data terms.Related
Format-Tomlnormalization (this issue's-Compactis a natural follow-up, discussed during PR 🚀 [Minor]: Format-Toml normalizes TOML to canonical form #20 review).