Skip to content

Commit 486f6b3

Browse files
committed
optimizations, adaptive line ending
1 parent c9f12b3 commit 486f6b3

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

ConvertTo-CSON.ps1

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
.PARAMETER EnumsAsStrings
1313
A switch that specifies an alternate serialization option that converts all enumerations to their string representations.
1414
.EXAMPLE
15-
$grammar_json | ConvertTo-Plist -Indent "`t" -StateEncodingAs 'UTF-8' | Set-Content 'out\PowerShellSyntax.tmLanguage' -Encoding 'UTF8'
15+
$grammar_json | ConvertTo-Cson -Indent `t -Depth 100 | Set-Content out\PowerShell.cson -Encoding UTF8
1616
.INPUTS
1717
[object] - any PowerShell object.
1818
.OUTPUTS
@@ -27,14 +27,13 @@
2727
#>
2828
function ConvertTo-Cson {
2929
param(
30-
[Parameter(Mandatory = $true,
31-
ValueFromPipeline = $true,
32-
ValueFromPipelineByPropertyName = $true)]
30+
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
3331
[AllowEmptyCollection()]
3432
[AllowEmptyString()]
3533
[AllowNull()]
3634
[object]$InputObject,
3735

36+
[PSDefaultValue(Help = 'Tab')]
3837
[string]$Indent = "`t",
3938

4039
[ValidateRange(1, 100)]
@@ -118,13 +117,13 @@ function ConvertTo-Cson {
118117
}
119118
}
120119
elseif ($item -isnot [enum]) {
121-
"$item"
120+
$item
122121
}
123122
elseif ($EnumsAsStrings) {
124123
writeStringValue ($item.ToString())
125124
}
126125
else {
127-
"$($item.value__)"
126+
$item.value__
128127
}
129128
}
130129
)"
@@ -179,5 +178,5 @@ function ConvertTo-Cson {
179178
}
180179

181180
# start writing the property list, the property list should be an object, has no name, and starts at base level
182-
(writeProperty $null $InputObject '' (-1)) -join "`r`n"
181+
(writeProperty $null $InputObject '' (-1)) -join $(if (-not $IsCoreCLR -or $IsWindows) {"`r`n"} else {"`n"})
183182
}

0 commit comments

Comments
 (0)