File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <#
2+ . SYNOPSIS
3+ `Turtle.js` definition
4+ . DESCRIPTION
5+ Our JavaScipt turtle is actually contained in a PowerShell object first.
6+
7+ This object has a number of properties ending with `.js`.
8+
9+ These are portions of the class.
10+
11+ To create our class, we simply join these properties together, and output a javascript object.
12+ #>
13+ param ()
14+
15+
16+
17+ @ (
18+
19+ # Since we are building a javascript object, we need to wrap everything in curly braces
20+ " {
21+ "
22+ # Indentation does not matter to most machines, but people tend to appreciate it.
23+ " "
24+ @ (foreach ($javaScriptProperty in $this.psobject.properties | Sort-Object Name) {
25+ # We only want the .js properties
26+ if ($javaScriptProperty.Name -notmatch ' \.js$' ) { continue }
27+ # If the property is a function, we need to handle it differently
28+ if ($javaScriptProperty.value -match ' ^function.+?\(' ) {
29+ # specificically, we need to remove the "function " prefix from the name
30+ $predicate , $extra = $javaScriptProperty.value -split ' \(' , 2
31+ # and then we need to reassemble it as a javascript method
32+ $functionName = $predicate -replace ' function\s{1,}'
33+ " ${functionName} :function ($extra "
34+ }
35+ else {
36+ # Otherwise, include it inline.
37+ $javaScriptProperty.value
38+ }
39+
40+ }) -join (' ,' + [Environment ]::Newline + ' ' )
41+ " }" ) -join ' '
You can’t perform that action at this time.
0 commit comments