Skip to content

0.0.3

Latest

Choose a tag to compare

@github-actions github-actions released this 03 Aug 01:26
f8937f2

🌟 [Major]: TOML 1.0.0 reading and writing now available in PowerShell (#15)

The Toml module now provides complete TOML 1.0.0 read and write support in pure PowerShell 7.6+. Scripts and tools can parse TOML configuration files into typed PowerShell objects, modify them in memory, and write them back — with no external dependencies required.

New: Parse TOML text into PowerShell objects

ConvertFrom-Toml parses any valid TOML 1.0.0 document into a TomlDocument. The Data property is an ordered dictionary that preserves source key order. All TOML scalar types map to native PowerShell types.

TOML type PowerShell type
String [string]
Integer [long]
Float [double]
Boolean [bool]
Offset date-time [System.DateTimeOffset]
Local date-time / local date [System.DateTime]
Local time [System.TimeSpan]
Array [object[]]
Inline table / Table [System.Collections.Specialized.OrderedDictionary]
$doc = ConvertFrom-Toml -InputObject (Get-Content config.toml -Raw)
$doc.Data.database.host   # "localhost"
$doc.Data.database.port   # 5432 [long]

New: Serialize PowerShell objects to TOML text

ConvertTo-Toml converts ordered dictionaries and hashtables into valid TOML text. Nested tables emit [header] sections and arrays of tables emit [[header]] sections in the correct order.

ConvertTo-Toml -InputObject ([ordered]@{
    title  = 'My App'
    server = [ordered]@{ host = 'localhost'; port = 8080 }
})

New: Import and export TOML files directly

Import-Toml reads a .toml file from disk and returns a TomlDocument with the resolved file path attached. Export-Toml writes any object or TomlDocument to disk as UTF-8 without BOM.

$doc = Import-Toml -Path ./config.toml
$doc.Data['version'] = 2
Export-Toml -InputObject $doc -Path ./config.toml

New: Format, validate, and merge TOML documents

Format-Toml normalizes TOML text into canonical form with optional nested-table indentation. Test-Toml validates TOML without throwing — returns $true/$false. Merge-Toml deep-merges two TOML documents with configurable conflict strategies (LastWins, FirstWins, ErrorOnConflict).

# Normalize
Format-Toml -Path ./config.toml

# Validate
if (Test-Toml -Path ./config.toml) { 'valid' }

# Merge
Merge-Toml -BaseObject $base -OverrideObject $override -Strategy LastWins

Technical Details

  • Pure PowerShell implementation — 7 public functions, private helpers, one file each, no external dependencies.
  • Parser uses an index-walk tokenizer with dedicated helpers per token type: basic strings, literal strings, scalars, arrays, inline tables, dotted keys, and comments.
  • Serializer walks ordered dictionaries recursively, emitting scalar assignments, standard table headers, and array-of-tables sections.
  • Hot paths use .NET primitives: StringBuilder for output assembly, OrderedDictionary for key ordering, ArrayList for array-of-tables growth.
  • 150 Pester tests, PSScriptAnalyzer clean.
Related issues