Skip to content

Commit 1035edf

Browse files
Add comment-based help and inline parameter docs to ConvertTo-Yaml private helpers
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent b304dd3 commit 1035edf

21 files changed

Lines changed: 333 additions & 0 deletions

src/functions/private/Confirm-YamlScalarLength.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,27 @@ function Confirm-YamlScalarLength {
22
<#
33
.SYNOPSIS
44
Enforces the configured length limit for an emission scalar.
5+
6+
.DESCRIPTION
7+
Checks a scalar node against the active serializer length budget before
8+
emission. This prevents generated YAML from silently exceeding the
9+
configured maximum scalar size.
10+
11+
.EXAMPLE
12+
Confirm-YamlScalarLength -Node ([pscustomobject]@{ Value = 'name' }) -State ([pscustomobject]@{ MaxScalarLength = 1024 })
13+
14+
Returns nothing because the scalar value is within the configured limit.
15+
16+
.LINK
17+
https://psmodule.io/Yaml/Functions/ConvertTo-Yaml/
518
#>
619
[CmdletBinding()]
720
param (
21+
# The scalar node whose text length must fit the emission budget.
822
[Parameter(Mandatory)]
923
[pscustomobject] $Node,
1024

25+
# The serializer state that carries the configured maximum scalar length.
1126
[Parameter(Mandatory)]
1227
[pscustomobject] $State
1328
)

src/functions/private/ConvertTo-YamlFlowText.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@ function ConvertTo-YamlFlowText {
22
<#
33
.SYNOPSIS
44
Iteratively renders one emission graph in flow form.
5+
6+
.DESCRIPTION
7+
Renders an emission node graph as a single flow-style YAML fragment for
8+
scalar values, empty collections, implicit keys, and aliases. It tracks
9+
already-emitted references so repeated nodes become aliases when needed.
10+
11+
.EXAMPLE
12+
ConvertTo-YamlFlowText -Node $entry.Key -EmittedReferences $emittedReferences
13+
14+
Returns flow-style text for the mapping key, using an alias when already emitted.
15+
16+
.LINK
17+
https://psmodule.io/Yaml/Functions/ConvertTo-Yaml/
518
#>
619
[CmdletBinding()]
720
[OutputType([string])]
821
param (
22+
# The emission node that must be rendered inline as flow YAML.
923
[Parameter(Mandatory)]
1024
[pscustomobject] $Node,
1125

26+
# Tracks reference ids already written so aliases are emitted correctly.
1227
[Parameter(Mandatory)]
1328
[AllowEmptyCollection()]
1429
[System.Collections.Generic.HashSet[long]] $EmittedReferences

src/functions/private/ConvertTo-YamlNode.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,39 @@ function ConvertTo-YamlNode {
22
<#
33
.SYNOPSIS
44
Iteratively normalizes a supported PowerShell value to an emission graph.
5+
6+
.DESCRIPTION
7+
Walks a supported PowerShell object graph without recursion and produces
8+
the internal emission nodes consumed by the YAML writer. The state object
9+
enforces resource limits, reference identity, anchors, and duplicate-key checks.
10+
11+
.EXAMPLE
12+
ConvertTo-YamlNode -Value $inputObject -State $serializationState -Depth 1 -EnumsAsStrings
13+
14+
Returns the root emission node for the input object graph, using enum names when requested.
15+
16+
.LINK
17+
https://psmodule.io/Yaml/Functions/ConvertTo-Yaml/
518
#>
619
[CmdletBinding()]
720
[OutputType([pscustomobject])]
821
param (
22+
# The PowerShell value that needs a YAML-safe emission representation.
923
[Parameter(Mandatory)]
1024
[AllowNull()]
1125
[object] $Value,
1226

27+
# Carries serialization limits, reference tracking, and shared caches.
1328
[Parameter(Mandatory)]
1429
[pscustomobject] $State,
1530

31+
# Current graph depth used to enforce the configured maximum depth.
1632
[Parameter(Mandatory)]
1733
[ValidateRange(1, 2147483647)]
1834
[int] $Depth,
1935

36+
# Allows enum values to be emitted by name instead of underlying number.
37+
[Parameter()]
2038
[switch] $EnumsAsStrings
2139
)
2240

src/functions/private/ConvertTo-YamlQuotedText.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,24 @@ function ConvertTo-YamlQuotedText {
22
<#
33
.SYNOPSIS
44
Encodes a string as a YAML double-quoted scalar.
5+
6+
.DESCRIPTION
7+
Escapes string content for a YAML double-quoted scalar, including control
8+
characters and invalid UTF-16 surrogate detection. It is used when plain
9+
scalar output would be ambiguous or unsafe.
10+
11+
.EXAMPLE
12+
ConvertTo-YamlQuotedText -Value "line`nbreak"
13+
14+
Returns a YAML double-quoted scalar with required escape sequences.
15+
16+
.LINK
17+
https://psmodule.io/Yaml/Functions/ConvertTo-Yaml/
518
#>
619
[CmdletBinding()]
720
[OutputType([string])]
821
param (
22+
# The scalar content to quote while preserving empty strings exactly.
923
[Parameter(Mandatory)]
1024
[AllowEmptyString()]
1125
[string] $Value

src/functions/private/ConvertTo-YamlRepresentationNode.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@ function ConvertTo-YamlRepresentationNode {
22
<#
33
.SYNOPSIS
44
Converts one representation graph to a lossless emission graph.
5+
6+
.DESCRIPTION
7+
Copies a parsed representation graph into the emission graph shape expected
8+
by the writer while preserving node identity, tags, anchors, and aliases.
9+
It assigns deterministic anchor names so formatted YAML remains stable.
10+
11+
.EXAMPLE
12+
ConvertTo-YamlRepresentationNode -Node $document.Root -State $emissionState
13+
14+
Returns an emission node graph for the representation document.
15+
16+
.LINK
17+
https://psmodule.io/Yaml/Functions/ConvertTo-Yaml/
518
#>
619
[CmdletBinding()]
720
[OutputType([pscustomobject])]
821
param (
22+
# The representation graph root that must be copied for emission.
923
[Parameter(Mandatory)]
1024
[pscustomobject] $Node,
1125

26+
# Carries anchor numbering so names stay unique across emitted documents.
1227
[Parameter(Mandatory)]
1328
[pscustomobject] $State
1429
)

src/functions/private/ConvertTo-YamlRepresentationText.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,29 @@ function ConvertTo-YamlRepresentationText {
22
<#
33
.SYNOPSIS
44
Emits representation documents as deterministic LF-normalized YAML.
5+
6+
.DESCRIPTION
7+
Converts composed representation documents into deterministic YAML text
8+
without projecting through public PowerShell values. It supports
9+
representation-preserving commands that must retain tags, anchors, and aliases.
10+
11+
.EXAMPLE
12+
ConvertTo-YamlRepresentationText -Documents $documents -Indent 2
13+
14+
Returns the formatted YAML stream for all supplied representation documents.
15+
16+
.LINK
17+
https://psmodule.io/Yaml/Functions/ConvertTo-Yaml/
518
#>
619
[CmdletBinding()]
720
[OutputType([string])]
821
param (
22+
# The representation document roots to emit in their original stream order.
923
[Parameter(Mandatory)]
1024
[AllowEmptyCollection()]
1125
[object[]] $Documents,
1226

27+
# Number of spaces per nesting level for deterministic block output.
1328
[Parameter(Mandatory)]
1429
[ValidateRange(2, 9)]
1530
[int] $Indent

src/functions/private/ConvertTo-YamlTagText.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,24 @@ function ConvertTo-YamlTagText {
22
<#
33
.SYNOPSIS
44
Encodes an effective tag as canonical YAML tag text.
5+
6+
.DESCRIPTION
7+
Escapes an expanded effective tag as YAML tag presentation text, using
8+
standard shorthand when possible. This keeps representation graph output
9+
deterministic while preserving local and application tags verbatim.
10+
11+
.EXAMPLE
12+
ConvertTo-YamlTagText -Tag 'tag:yaml.org,2002:str'
13+
14+
Returns !!str for the standard YAML string tag.
15+
16+
.LINK
17+
https://psmodule.io/Yaml/Functions/ConvertTo-Yaml/
518
#>
619
[CmdletBinding()]
720
[OutputType([string])]
821
param (
22+
# The expanded effective tag URI that must be encoded for YAML output.
923
[Parameter(Mandatory)]
1024
[string] $Tag
1125
)

src/functions/private/ConvertTo-YamlText.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,34 @@ function ConvertTo-YamlText {
22
<#
33
.SYNOPSIS
44
Emits an internal node graph as LF-normalized YAML text.
5+
6+
.DESCRIPTION
7+
Serializes a normalized emission node graph to a YAML document using LF
8+
line endings and the configured indentation. It centralizes final text
9+
assembly so document markers, anchors, and aliases are emitted consistently.
10+
11+
.EXAMPLE
12+
ConvertTo-YamlText -Node $emissionNode -Indent 2 -ExplicitDocumentStart
13+
14+
Returns YAML text for the emission graph with an explicit document start marker.
15+
16+
.LINK
17+
https://psmodule.io/Yaml/Functions/ConvertTo-Yaml/
518
#>
619
[CmdletBinding()]
720
[OutputType([string])]
821
param (
22+
# The root emission graph to write as one YAML document.
923
[Parameter(Mandatory)]
1024
[pscustomobject] $Node,
1125

26+
# Number of spaces per nesting level for deterministic block output.
1227
[Parameter(Mandatory)]
1328
[ValidateRange(2, 9)]
1429
[int] $Indent,
1530

31+
# Allows callers to include the YAML document-start marker when required.
32+
[Parameter()]
1633
[switch] $ExplicitDocumentStart
1734
)
1835

src/functions/private/ConvertTo-YamlTimestampText.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,24 @@ function ConvertTo-YamlTimestampText {
22
<#
33
.SYNOPSIS
44
Formats a representable CLR timestamp for YAML emission.
5+
6+
.DESCRIPTION
7+
Formats DateTime and DateTimeOffset values with invariant timestamp text
8+
accepted by the YAML emitter. It preserves explicit or local offsets when
9+
representable and normalizes unspecified timestamps to UTC-style text.
10+
11+
.EXAMPLE
12+
ConvertTo-YamlTimestampText -Value ([datetimeoffset] '2026-07-26T20:51:03+00:00')
13+
14+
Returns invariant YAML timestamp text for the supplied CLR timestamp.
15+
16+
.LINK
17+
https://psmodule.io/Yaml/Functions/ConvertTo-Yaml/
518
#>
619
[CmdletBinding()]
720
[OutputType([string])]
821
param (
22+
# The CLR timestamp value to validate and format for YAML output.
923
[Parameter(Mandatory)]
1024
[object] $Value
1125
)

src/functions/private/Get-YamlEmissionImplicitKeyLength.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,24 @@ function Get-YamlEmissionImplicitKeyLength {
22
<#
33
.SYNOPSIS
44
Gets an emitted implicit key length in Unicode scalar values.
5+
6+
.DESCRIPTION
7+
Counts Unicode scalar values in the already rendered key text. The emitter uses this to
8+
enforce YAML 1.2 implicit key length limits before choosing implicit or explicit key
9+
presentation.
10+
11+
.EXAMPLE
12+
Get-YamlEmissionImplicitKeyLength -RenderedText 'name'
13+
14+
Returns the number of Unicode scalar values that the rendered implicit key would occupy.
15+
16+
.LINK
17+
https://psmodule.io/Yaml/Functions/ConvertTo-Yaml/
518
#>
619
[CmdletBinding()]
720
[OutputType([int])]
821
param (
22+
# The rendered key text is measured after escaping so the limit matches emitted YAML.
923
[Parameter(Mandatory)]
1024
[AllowEmptyString()]
1125
[string] $RenderedText

0 commit comments

Comments
 (0)