Skip to content

Add Format-Toml function for normalization #3

@MariusStorhaug

Description

Hand-written or machine-generated TOML files often have inconsistent indentation, key-quoting, and table-section ordering. A Format-Toml function normalizes the text without changing semantics — equivalent to ConvertFrom-Toml | ConvertTo-Toml but expressed as a single ergonomic call. Sister modules already follow this pattern: Format-Json and Format-Hashtable.

Request

Desired capability

Get-Content Cargo.toml -Raw | Format-Toml
Format-Toml -Path Cargo.toml -Indent 4

Parameters

Parameter Description
-InputObject String to format (ValueFromPipeline, default set)
-Path File path to read and format
-LiteralPath Literal file path
-Indent Spaces per level (default: 2)

Acceptance criteria

  • Format-Toml $s produces canonical-form TOML for $s
  • Idempotent: Format-Toml (Format-Toml $s) equals Format-Toml $s
  • -Indent controls spacing between nested table levels
  • Output remains parseable by ConvertFrom-Toml

Technical decisions

Implementation: Parses input with ConvertFrom-Toml and re-emits with ConvertTo-Toml using the requested indentation. Reuses existing logic — no new parser or emitter.

Function placement: src/functions/public/Format-Toml.ps1.

Parameter sets: InputObject (default, pipeline) and Path / LiteralPath for file input.

Alias: Format-Tml, matching the planned alias pattern in #2.


Implementation plan

  • Add Format-Toml in src/functions/public/Format-Toml.ps1 with Format-Tml alias
  • Add Pester tests — basic format, custom -Indent, idempotent round-trip
  • Update README and examples/General.ps1

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions