Skip to content

Add -Compact support to Format-Toml (and/or ConvertTo-Toml) for inline table/dotted-key collapsing #23

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions