From 6e3e0f28c37e11781fe34b894c0f9b2042bb356b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20K=C5=82ys?= Date: Fri, 6 Mar 2026 23:07:11 +0100 Subject: [PATCH 1/5] Document locale decimal condition values --- Public/New-TableCondition.ps1 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Public/New-TableCondition.ps1 b/Public/New-TableCondition.ps1 index 87e02c4e..930c5619 100644 --- a/Public/New-TableCondition.ps1 +++ b/Public/New-TableCondition.ps1 @@ -19,7 +19,9 @@ function New-TableCondition { Specifies the comparison operator to be used. .PARAMETER Value - Specifies the value to compare against. + Specifies the value to compare against. In PowerShell decimal literals use a dot, for example 0.2. + If you want to pass locale-formatted text such as 0,2, quote it as a string. Bare 0,2 is parsed by + PowerShell as an array containing 0 and 2 before PSWriteHTML receives it. .PARAMETER Row Switch parameter to indicate if the styling should be applied to the entire row. @@ -103,7 +105,14 @@ function New-TableCondition { Specifies the text direction for fail conditions. .EXAMPLE - An example of how to use this function. + New-TableCondition -Name 'Policies_Go' -ComparisonType number -Operator le -Value 0.2 -Color SeaGreen -FailColor FireBrick + + Uses a PowerShell numeric literal with a dot decimal separator. + + .EXAMPLE + New-TableCondition -Name 'Policies_Go' -ComparisonType number -Operator le -Value '0,2' -Color SeaGreen -FailColor FireBrick + + Uses a quoted locale-formatted decimal string. Avoid bare -Value 0,2 because PowerShell treats it as an array. .NOTES Additional notes about the function. From 1fac0f0537e290241dff7cc9d703256b9ad4944d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20K=C5=82ys?= Date: Fri, 6 Mar 2026 23:07:12 +0100 Subject: [PATCH 2/5] Add locale decimal condition regression tests --- Tests/New-TableCondition.Tests.ps1 | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Tests/New-TableCondition.Tests.ps1 diff --git a/Tests/New-TableCondition.Tests.ps1 b/Tests/New-TableCondition.Tests.ps1 new file mode 100644 index 00000000..7d05f4b3 --- /dev/null +++ b/Tests/New-TableCondition.Tests.ps1 @@ -0,0 +1,59 @@ +Import-Module "$PSScriptRoot\..\PSWriteHTML.psd1" -Force + +Describe 'New-TableCondition' { + It 'Serializes dot and quoted comma thresholds into columnHighlighter rules' { + $FilePath = "$PSScriptRoot\TemporaryCondition.html" + $htmlStore = @( + [PSCustomObject] @{ + Item = 'Pass threshold' + Value = '0,17' + } + ) + $jsStore = @( + [PSCustomObject] @{ + Item = 'Pass threshold' + Value = 0.17 + } + ) + + New-HTML { + New-HTMLTable -DataTable $htmlStore -HideFooter { + New-TableCondition -Name 'Value' -ComparisonType number -Operator le -Value '0,2' -Color SeaGreen -FailColor FireBrick + } + New-HTMLTable -DataTable $jsStore -HideFooter { + New-TableCondition -Name 'Value' -ComparisonType number -Operator le -Value 0.2 -Color SeaGreen -FailColor FireBrick + } -DataStore JavaScript + } -FilePath $FilePath -Online + + $Content = Get-Content -Path $FilePath -Raw + $Content | Should -Match '"columnHighlighter"' + $Content | Should -Match '"value": "0,2"' + $Content | Should -Match '"value": 0.2' + + if (Test-Path $FilePath) { + Remove-Item -LiteralPath $FilePath + } + } + + It 'Receives bare comma decimals as an array because of PowerShell parsing' { + $FilePath = "$PSScriptRoot\TemporaryConditionArray.html" + $bareCommaValue = 0,2 + + New-HTML { + $script:conditionWithBareComma = New-TableCondition -Name 'Value' -ComparisonType number -Operator le -Value $bareCommaValue + } -FilePath $FilePath + + $bareCommaValue.GetType().FullName | Should -Be 'System.Object[]' + $bareCommaValue.Count | Should -Be 2 + $bareCommaValue[0] | Should -Be 0 + $bareCommaValue[1] | Should -Be 2 + $script:conditionWithBareComma.Output.Value.GetType().FullName | Should -Be 'System.Object[]' + $script:conditionWithBareComma.Output.Value.Count | Should -Be 2 + $script:conditionWithBareComma.Output.Value[0] | Should -Be 0 + $script:conditionWithBareComma.Output.Value[1] | Should -Be 2 + + if (Test-Path $FilePath) { + Remove-Item -LiteralPath $FilePath + } + } +} From ca582af9c24447b3ba1c9055a3af68953c5d59f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20K=C5=82ys?= Date: Fri, 6 Mar 2026 23:07:13 +0100 Subject: [PATCH 3/5] Add locale decimal condition example script --- .../Example-LocaleDecimals.ps1 | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 Examples/Example-TableColumnHighlight/Example-LocaleDecimals.ps1 diff --git a/Examples/Example-TableColumnHighlight/Example-LocaleDecimals.ps1 b/Examples/Example-TableColumnHighlight/Example-LocaleDecimals.ps1 new file mode 100644 index 00000000..32050638 --- /dev/null +++ b/Examples/Example-TableColumnHighlight/Example-LocaleDecimals.ps1 @@ -0,0 +1,120 @@ +Import-Module .\PSWriteHTML.psd1 -Force + +$htmlDot = @( + [PSCustomObject] @{ + Item = 'Pass threshold' + Value = '0.17' + } + [PSCustomObject] @{ + Item = 'Fail threshold' + Value = '0.25' + } + [PSCustomObject] @{ + Item = 'Exact threshold' + Value = '0.20' + } + [PSCustomObject] @{ + Item = 'Negative value' + Value = '-0.05' + } +) + +$htmlComma = @( + [PSCustomObject] @{ + Item = 'Pass threshold' + Value = '0,17' + } + [PSCustomObject] @{ + Item = 'Fail threshold' + Value = '0,25' + } + [PSCustomObject] @{ + Item = 'Exact threshold' + Value = '0,20' + } + [PSCustomObject] @{ + Item = 'Negative value' + Value = '-0,05' + } +) + +$jsDot = @( + [PSCustomObject] @{ + Item = 'Pass threshold' + Value = 0.17 + } + [PSCustomObject] @{ + Item = 'Fail threshold' + Value = 0.25 + } + [PSCustomObject] @{ + Item = 'Exact threshold' + Value = 0.20 + } + [PSCustomObject] @{ + Item = 'Negative value' + Value = -0.05 + } +) + +$jsComma = @( + [PSCustomObject] @{ + Item = 'Pass threshold' + Value = '0,17' + } + [PSCustomObject] @{ + Item = 'Fail threshold' + Value = '0,25' + } + [PSCustomObject] @{ + Item = 'Exact threshold' + Value = '0,20' + } + [PSCustomObject] @{ + Item = 'Negative value' + Value = '-0,05' + } +) + +$exampleCode = @' +New-TableCondition -Name "Value" -ComparisonType number -Operator le -Value 0.2 -Color SeaGreen -FailColor FireBrick +New-TableCondition -Name "Value" -ComparisonType number -Operator le -Value '0,2' -Color SeaGreen -FailColor FireBrick + +# Avoid bare -Value 0,2 in PowerShell. +# PowerShell parses it as an Object[] containing 0 and 2. +'@ + +New-HTML -TitleText 'PSWriteHTML decimal number conditions' -Online -FilePath "$PSScriptRoot\Example-LocaleDecimals.html" { + New-HTMLSection -HeaderText 'Locale decimal conditions' { + New-HTMLText -TextBlock { + 'This example proves the same decimal comparison works for HTML-backed tables and JavaScript-backed tables.' + 'Use -Value 0.2 for a numeric literal, or quote locale-formatted text with -Value ''0,2''.' + 'Do not use bare -Value 0,2 in PowerShell because it becomes an Object[] before PSWriteHTML sees it.' + } + New-HTMLCodeBlock -Code $exampleCode -Style 'PowerShell' -Theme enlighter + } + + New-HTMLSection -HeaderText 'HTML store with dot decimals' { + New-HTMLTable -DataTable $htmlDot -Buttons copyHtml5, excelHtml5, csvHtml5, pdfHtml5 -PagingLength 5 { + New-TableCondition -Name 'Value' -ComparisonType number -Operator le -Value 0.2 -Color SeaGreen -FailColor FireBrick + } + } + + New-HTMLSection -HeaderText 'HTML store with comma decimals' { + New-HTMLTable -DataTable $htmlComma -Buttons copyHtml5, excelHtml5, csvHtml5, pdfHtml5 -PagingLength 5 { + New-TableCondition -Name 'Value' -ComparisonType number -Operator le -Value '0,2' -Color SeaGreen -FailColor FireBrick + } + } + + New-HTMLSection -HeaderText 'JavaScript store with numeric values' { + New-HTMLTable -DataTable $jsDot -Buttons copyHtml5, excelHtml5, csvHtml5, pdfHtml5 -PagingLength 5 { + New-TableCondition -Name 'Value' -ComparisonType number -Operator le -Value 0.2 -Color SeaGreen -FailColor FireBrick + } -DataStore JavaScript + } + + New-HTMLSection -HeaderText 'JavaScript store with comma-formatted strings' { + New-HTMLTable -DataTable $jsComma -Buttons copyHtml5, excelHtml5, csvHtml5, pdfHtml5 -PagingLength 5 { + New-TableCondition -Name 'Value' -ComparisonType number -Operator le -Value '0,2' -Color SeaGreen -FailColor FireBrick + } -DataStore JavaScript + } +} From 74f1ab559d5ae38dfb7015ab7a7ea05e848d7840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20K=C5=82ys?= Date: Fri, 6 Mar 2026 23:07:14 +0100 Subject: [PATCH 4/5] Add generated locale decimal condition example --- .../Example-LocaleDecimals.html | 573 ++++++++++++++++++ 1 file changed, 573 insertions(+) create mode 100644 Examples/Example-TableColumnHighlight/Example-LocaleDecimals.html diff --git a/Examples/Example-TableColumnHighlight/Example-LocaleDecimals.html b/Examples/Example-TableColumnHighlight/Example-LocaleDecimals.html new file mode 100644 index 00000000..2997e8bb --- /dev/null +++ b/Examples/Example-TableColumnHighlight/Example-LocaleDecimals.html @@ -0,0 +1,573 @@ + + PSWriteHTML decimal number conditions
This example proves the same decimal comparison works for HTML-backed tables and JavaScript-backed tables.Use -Value 0.2 for a numeric literal, or quote locale-formatted text with -Value '0,2'.Do not use bare -Value 0,2 in PowerShell because it becomes an Object[] before PSWriteHTML sees it.
New-TableCondition -Name "Value" -ComparisonType number -Operator le -Value 0.2 -Color SeaGreen -FailColor FireBrick
+New-TableCondition -Name "Value" -ComparisonType number -Operator le -Value '0,2' -Color SeaGreen -FailColor FireBrick
+
+# Avoid bare -Value 0,2 in PowerShell.
+# PowerShell parses it as an Object[] containing 0 and 2.
ItemValue
Pass threshold0.17
Fail threshold0.25
Exact threshold0.20
Negative value-0.05
ItemValue
ItemValue
Pass threshold0,17
Fail threshold0,25
Exact threshold0,20
Negative value-0,05
ItemValue
ItemValue
ItemValue
ItemValue
ItemValue
From c56fb26fe60b1207dae3ccd58ecd41519dcf061a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20K=C5=82ys?= Date: Fri, 6 Mar 2026 23:14:16 +0100 Subject: [PATCH 5/5] Relax locale decimal test spacing assertions --- Tests/New-TableCondition.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/New-TableCondition.Tests.ps1 b/Tests/New-TableCondition.Tests.ps1 index 7d05f4b3..3ef27f08 100644 --- a/Tests/New-TableCondition.Tests.ps1 +++ b/Tests/New-TableCondition.Tests.ps1 @@ -27,8 +27,8 @@ Describe 'New-TableCondition' { $Content = Get-Content -Path $FilePath -Raw $Content | Should -Match '"columnHighlighter"' - $Content | Should -Match '"value": "0,2"' - $Content | Should -Match '"value": 0.2' + $Content | Should -Match '"value"\s*:\s*"0,2"' + $Content | Should -Match '"value"\s*:\s*0.2' if (Test-Path $FilePath) { Remove-Item -LiteralPath $FilePath