|
1 | | -This directory and it's subdirectories contain syntax changes that enable common programming scenarios in PowerShell and PipeScript. |
| 1 | +This directory and it's subdirectories contain Transpilers that transform parameter attributes. |
2 | 2 |
|
| 3 | +Parameter Transpilers do not need to take any values from the pipeline. |
| 4 | +They will be called by the Core PipeScript Transpiler ```PipeScript.ParameterAttribute```. |
3 | 5 |
|
4 | | -|DisplayName |Synopsis | |
5 | | -|------------------------------------------------|---------------------------------------------------------| |
6 | | -|[Dot](Dot.psx.ps1) |[Dot Notation](Dot.psx.ps1) | |
7 | | -|[EqualityComparison](EqualityComparison.psx.ps1)|[Allows equality comparison.](EqualityComparison.psx.ps1)| |
8 | | -|[PipedAssignment](PipedAssignment.psx.ps1) |[Piped Assignment Transpiler](PipedAssignment.psx.ps1) | |
9 | | -|[RegexLiteral](RegexLiteral.psx.ps1) |[Regex Literal Transpiler](RegexLiteral.psx.ps1) | |
| 6 | +When Transpiling a Parameter, the Transpiler should return one of two things. |
10 | 7 |
|
| 8 | +1. An empty ```[ScriptBlock]``` preceeded by attributes or help. This will replace the Transpiled attribute with a real one. |
| 9 | +2. A ```[Collections.IDictionary]``` can be used to send arguments directly back to ```Update-PipeScript```. |
11 | 10 |
|
| 11 | +Many parameter transpilers can also apply to a ```[Management.Automation.Language.VariableExpressionAst]```. |
12 | 12 |
|
| 13 | +When this is the case it is common for the transpiler to add a ```[ValidateScript]``` attribute to the variable. This will constraint the value of that variable. |
13 | 14 |
|
14 | | -## Dot Example 1 |
| 15 | +## List Of Parameter Transpilers |
15 | 16 |
|
16 | 17 |
|
17 | | -~~~PowerShell |
18 | | - .> { |
19 | | - [DateTime]::now | .Month .Day .Year |
20 | | - } |
21 | | -~~~ |
| 18 | +|DisplayName |Synopsis | |
| 19 | +|----------------------------------------------------|---------------------------------------------------------------------| |
| 20 | +|[Aliases](Aliases.psx.ps1) |[Dynamically Defines Aliases](Aliases.psx.ps1) | |
| 21 | +|[ValidateExtension](ValidateExtension.psx.ps1) |[Validates Extensions](ValidateExtension.psx.ps1) | |
| 22 | +|[ValidatePlatform](ValidatePlatform.psx.ps1) |[Validates the Platform](ValidatePlatform.psx.ps1) | |
| 23 | +|[ValidatePropertyName](ValidatePropertyName.psx.ps1)|[Validates Property Names](ValidatePropertyName.psx.ps1) | |
| 24 | +|[ValidateScriptBlock](ValidateScriptBlock.psx.ps1) |[Validates Script Blocks](ValidateScriptBlock.psx.ps1) | |
| 25 | +|[ValidateTypes](ValidateTypes.psx.ps1) |[Validates if an object is one or more types.](ValidateTypes.psx.ps1)| |
| 26 | +|[VBN](VBN.psx.ps1) |[ValueFromPiplineByPropertyName Shorthand](VBN.psx.ps1) | |
| 27 | +|[VFP](VFP.psx.ps1) |[ValueFromPipline Shorthand](VFP.psx.ps1) | |
22 | 28 |
|
23 | | -## Dot Example 2 |
24 | 29 |
|
25 | 30 |
|
26 | | -~~~PowerShell |
27 | | - .> { |
28 | | - "abc", "123", "abc123" | .Length |
29 | | - } |
30 | | -~~~ |
31 | 31 |
|
32 | | -## Dot Example 3 |
33 | 32 |
|
34 | 33 |
|
35 | | -~~~PowerShell |
36 | | - .> { 1.99 | .ToString 'C' [CultureInfo]'gb-gb' } |
37 | | -~~~ |
38 | | - |
39 | | -## Dot Example 4 |
40 | | - |
41 | | - |
42 | | -~~~PowerShell |
43 | | - .> { 1.99 | .ToString('C') } |
44 | | -~~~ |
45 | | - |
46 | | -## Dot Example 5 |
47 | | - |
48 | | - |
49 | | -~~~PowerShell |
50 | | - .> { 1..5 | .Number { $_ } .Even { -not ($_ % 2) } .Odd { ($_ % 2) -as [bool]} } |
51 | | -~~~ |
52 | | - |
53 | | -## Dot Example 6 |
54 | | - |
55 | | - |
56 | | -~~~PowerShell |
57 | | - .> { .ID { Get-Random } .Count { 0 } .Total { 10 }} |
58 | | -~~~ |
59 | | - |
60 | | -## Dot Example 7 |
61 | | - |
62 | | - |
63 | | -~~~PowerShell |
64 | | - .> { |
65 | | - # Declare a new object |
66 | | - .Property = "ConstantValue" .Numbers = 1..100 .Double = { |
67 | | - param($n) |
68 | | - $n * 2 |
69 | | - } .EvenNumbers = { |
70 | | - $this.Numbers | Where-Object { -not ($_ % 2)} |
71 | | - } .OddNumbers = { |
72 | | - $this.Numbers | Where-Object { $_ % 2} |
73 | | - } |
74 | | - } |
75 | | -~~~ |
76 | | - |
77 | | -## EqualityComparison Example 1 |
78 | | - |
79 | | - |
80 | | -~~~PowerShell |
81 | | - Invoke-PipeScript -ScriptBlock { |
82 | | - $a = 1 |
83 | | - if ($a == 1 ) { |
84 | | - "A is $a" |
85 | | - } |
86 | | - } |
87 | | -~~~ |
88 | | - |
89 | | -## EqualityComparison Example 2 |
90 | | - |
91 | | - |
92 | | -~~~PowerShell |
93 | | - { |
94 | | - $a == "b" |
95 | | - } | .>PipeScript |
96 | | -~~~ |
97 | | - |
98 | | -## PipedAssignment Example 1 |
99 | | - |
100 | | - |
101 | | -~~~PowerShell |
102 | | - { |
103 | | - $Collection |=| Where-Object Name -match $Pattern |
104 | | - } | .>PipeScript |
105 | | -
|
106 | | - # This will become: |
107 | | -
|
108 | | - $Collection = $Collection | Where-Object Name -match $pattern |
109 | | -~~~ |
110 | | - |
111 | | -## PipedAssignment Example 2 |
112 | | - |
113 | | - |
114 | | -~~~PowerShell |
115 | | - { |
116 | | - $Collection |=| Where-Object Name -match $pattern | Select-Object -ExpandProperty Name |
117 | | - } | .>PipeScript |
118 | | -
|
119 | | - # This will become |
120 | | -
|
121 | | - $Collection = $Collection | |
122 | | - Where-Object Name -match $pattern | |
123 | | - Select-Object -ExpandProperty Name |
124 | | -~~~ |
125 | | - |
126 | | -## RegexLiteral Example 1 |
127 | | - |
128 | | - |
129 | | -~~~PowerShell |
130 | | - { |
131 | | - '/[a|b]/' |
132 | | - } | .>PipeScript |
133 | | -
|
134 | | - # This will become: |
135 | | -
|
136 | | - [regex]::new('[a|b]', 'IgnoreCase') |
137 | | -~~~ |
138 | | - |
139 | | -## RegexLiteral Example 2 |
140 | | - |
141 | | - |
142 | | -~~~PowerShell |
143 | | - Invoke-PipeScript { |
144 | | - '/[a|b]/'.Matches('ab') |
145 | | - } |
146 | | -~~~ |
147 | | - |
148 | | -## RegexLiteral Example 3 |
149 | | - |
150 | | - |
151 | | -~~~PowerShell |
152 | | - { |
153 | | - "/[$a|$b]/" |
154 | | - } | .>PipeScript |
155 | | -
|
156 | | - # This will become: |
157 | | -
|
158 | | - [regex]::new("[$a|$b]", 'IgnoreCase') |
159 | | -~~~ |
160 | | - |
161 | | -## RegexLiteral Example 4 |
162 | | - |
163 | | - |
164 | | -~~~PowerShell |
165 | | - { |
166 | | -@' |
167 | | -/ |
168 | | -# Heredocs Regex literals will have IgnorePatternWhitespace by default, which allows comments |
169 | | -^ # Match the string start |
170 | | -(?<indent>\s{0,1}) |
171 | | -/ |
172 | | -'@ |
173 | | - } | .>PipeScript |
174 | | -
|
175 | | - # This will become: |
176 | | -
|
177 | | - [regex]::new(@' |
178 | | -# Heredocs Regex literals will have IgnorePatternWhitespace by default, which allows comments |
179 | | -^ # Match the string start |
180 | | -(?<indent>\s{0,1}) |
181 | | -'@, 'IgnorePatternWhitespace,IgnoreCase') |
182 | | -~~~ |
183 | | - |
184 | | -## RegexLiteral Example 5 |
185 | | - |
186 | | - |
187 | | -~~~PowerShell |
188 | | - $Keywords = "looking", "for", "these", "words" |
189 | | -
|
190 | | - { |
191 | | -@" |
192 | | -/ |
193 | | -# Double quoted heredocs can still contain variables |
194 | | -[\s\p{P}]{0,1} # Whitespace or punctuation |
195 | | -$($Keywords -join '|') # followed by keywords |
196 | | -[\s\p{P}]{0,1} # followed by whitespace or punctuation |
197 | | -/ |
198 | | -"@ |
199 | | - } | .>PipeScript |
200 | | -
|
201 | | -
|
202 | | - # This will become: |
203 | | -
|
204 | | - [regex]::new(@" |
205 | | -# Double quoted heredocs can still contain variables |
206 | | -[\s\p{P}]{0,1} # Whitespace or punctuation |
207 | | -$($Keywords -join '|') # followed by keywords |
208 | | -[\s\p{P}]{0,1} # followed by whitespace or punctuation |
209 | | -"@, 'IgnorePatternWhitespace,IgnoreCase') |
210 | | -~~~ |
211 | | - |
0 commit comments