Differences

This shows you the differences between two versions of the page.

Link to this comparison view

dglux5_wiki:dgscript:home [2019/10/04 07:19]
dglux5_wiki:dgscript:home [2019/07/17 19:17] (current)
Line 1: Line 1:
 +{{indexmenu_n>​11}}
  
 +====== Scripting and Syntax ======
 +This page covers DGLux5 script. ​
 +
 +Topics on this page are:
 +  * [[#​when_to_use|When to use DGLux5 script]]
 +  * [[#​differences_from_JavaScript|The differences between DGLux5 script and JavaScript]]
 +  * [[#​page_model|How to access the page model]]
 +  * [[#​debugging|How to use script for debugging]]
 +  * [[#​reuse_script|How to reuse script, or how to call a script function from another block]]
 +
 +This page also contains a reference of some available [[#​operators|operators]],​ formats, and functions in the following categories:
 +  * [[#​operators|String,​ number, logical, and bit-wise operators]]
 +  * [[#​string|String usage and functions]]
 +  * [[#​number|Number formats, number functions, math functions, and constants]]
 +  * [[#​datetime|DateTime formats and functions]]
 +  * [[#​list|List functions]]
 +  * [[#​json|JSON functions]]
 +  * [[#xml|XML functions]]
 +  * [[#​table|DGLux5 table functions]]
 +
 +Finally, this page contains examples for:
 +  * [[#​lat-long_operations|Custom latitude and longitude operations]]
 +  * [[#​custom_easing_functions|Custom easing functions]]
 +
 +See also:
 +  * [[custom_javascript|Custom JS Components]]
 +  * [[custom_div|Using Custom div Elements]]
 +
 +----
 +
 +{{anchor:​when_to_use}}===== When to Use DGLux5 Script =====
 +DGLux5 features a visual programming environment,​ the [[dglux5_wiki:​dataflow:​home|dataflow]]. However, in some situations, script is necessary or is more efficient than the dataflow.
 +
 +You can use script in these dataflow blocks:
 +
 +  * [[dglux5_wiki:​dataflow:​dataflow_blocks_reference:​logic:​script|Script]]
 +  * [[dglux5_wiki:​dataflow:​dataflow_blocks_reference:​browser_api:​javascript|JavaScript]]
 +  * [[dglux5_wiki:​dataflow:​dataflow_blocks_reference:​table_operations:​filter|Filter]] (**condition** property)
 +  * [[dglux5_wiki:​dataflow:​dataflow_blocks_reference:​table_operations:​column_mapping|Column Mapping]] (**from //n//** property)
 +
 +You can also use the page model syntax, which is described [[#​page_model|below]],​ in binding paths. See [[dglux5_wiki:​bindings:​home|Bindings]].
 +
 +Although DGLux5 script has some [[#​differences_from_javascript|differences from JavaScript]],​ JavaScript can be used in DGLux5 to accomplish many custom calculation tasks. The Internet is a good resource for finding JavaScript functions and excerpts.
 +
 +----
 +
 +{{anchor:​differences_from_javascript}}===== Differences between DGLux5 Script and JavaScript =====
 +Read this section if you are already familiar with JavaScript, ActionScript,​ or another ECMA262-based scripting language. ​
 +
 +The differences between JavaScript and DGLux5 script are as follows:
 +  * <​WRAP>​In DGLux5 script, ''​list''​ does not support dynamic properties. For example, the following code does not work in DGLux5:
 +
 +<code javascript>​
 +list = [];
 +list.name = '​mylist';​ // Error: this does not work in DGLux5.
 +</​code>​
 +</​WRAP>​
 +  * <​WRAP>​DGLux5 script uses the ''​DateTime''​ type instead of the JavaScript ''​Date''​ type. This is because January in ''​DateTime''​ corresponds to one, while January in ''​Date''​ corresponds to zero. For example, the following code demonstrates ''​DateTime''​ functioning correctly and ''​Date''​ functioning incorrectly in DGLux5.
 +
 +<code javascript>​
 +//Returns 2014-01-01.
 +d = new DateTime(2014,​1,​1); ​
 +
 +//Does not work in DGLux5. In JavaScript this would mean 2014-02-01.
 +incorrect = new Date(2014,​1,​1); ​
 +</​code>​
 +</​WRAP>​
 +
 +----
 +
 +{{anchor:​page_model}}===== Page Model =====
 +The script execution context and the block location both have an important relationship with the DGLux5 page model.
 +
 +Use the at sign (@) to access the virtual model of the page and interact with other elements in the model. For example:
 +  * ''​@''​ refers to the current block.
 +  * ''​@parent''​ refers to the logical parent of the current block or element. You can use this string more than once to refer to further ancestors, such as ''​@parent.@parent.@parent''​.
 +  * ''​@params''​ refers to the parameters of the symbol being referred to. For example, when used inside a symbol, in the symbol'​s root dataflow model, ''​@parent.@params''​ refers to the parameters of this symbol.
 +  * ''​@stage''​ refers to the first immediate ancestor [[dglux5_wiki:​widgets_and_property_inspector:​components:​group:​home|stage]] of the the current block or element.
 +     * If used in a [[dglux5_wiki:​workspace_and_workflow:​projects_and_files:​about_dg5|page]],​ ''​@stage''​ refers to the root for the page.
 +     * If used in a [[dglux5_wiki:​widgets_and_property_inspector:​components:​symbols:​home|symbol]],​ ''​@stage''​ refers to the root of the symbol.
 +  * ''​@lib''​ refers to the root of the [[dglux5_wiki:​dataflow:​project_dataflow:​home|Project Dataflow]].
 +  * In a binding, ''​@parent.@table.0_v1''​ refers to the cell in row zero, column v1, for a table that shares the same parent as the current block.
 +  * ''​@<​pageModelName>''​ refers to the page model name of the component at the specified path. For example, to refer to the **width** property of a shape component that is in a group, you  might use ''​@stage.@group1.@shape1.width''​.
 +
 +==== How to View Element Types and Page Model Names ====
 +
 +To view the page model name of any property and the property'​s parent:
 +  - Hover over the property until a blue dot appears.
 +  - <​WRAP>​Hold Option and right-click the blue dot.
 +
 +A tooltip displays all of the following:
 +  * Parent element type and property name
 +  * Parent element name in page model syntax and property name
 +  * Property name
 +
 +The following images demonstrate this tooltip.
 +
 +{{:​dglux5_wiki:​dgscript:​page_model_shape.png?​direct|}}
 +
 +{{:​dglux5_wiki:​dgscript:​page_model_block.png?​direct|}}</​WRAP>​
 +
 +==== How to Change Page Model Names ====
 +
 +To change an element name in the page model syntax:
 +  - Double-click the element name in the [[dglux5_wiki:​workspace_and_workflow:​panels_and_menus:​outline|Outline]] or the dataflow block header.
 +  - Type the new name.
 +  - Press Command + Enter on Mac or Ctrl + Enter on Windows.
 +
 +If you press only Enter, the name is changed in the DGLux5 user interface but not in the page model.
 +
 +<WRAP important>​===Important===
 +Changing an element'​s page model name breaks any scripts or bindings that already refer to that element. You must also change the name in these scripts or bindings.</​WRAP>​
 +
 +==== How to Access and Set Values via Script ====
 +
 +The following example demonstrates how to use script to access and set a value in the page model. ​
 +
 +<code javascript>​
 +//Sets the "​a"​ property of the current block to 
 +//the value of the string block located on 
 +//the parent dataflow.
 +@.a = @parent.string.value;​
 +</​code>​
 +
 +Use ''​=''​ to set a runtime value for an object property, and use ''​~=''​ to set a value that will be serialized as part of a subsequent save. The following examples demonstrate how to set both kinds of values.
 +
 +<code javascript>​
 +//Sets the runtime "​value"​ property of the 
 +//parent object'​s "​string"​ block to 
 +//"​stringValue"​.
 +@parent.string.value = "​stringValue";​
 +
 +//Sets the serialized "​value"​ property of the 
 +//parent object'​s "​string"​ block to 
 +//"​stringValue"​.
 +@parent.string.value ~= "​stringValue";​
 +</​code>​
 +
 +==== How to Create Bindings via Script ====
 +
 +To create a [[dglux5_wiki:​bindings:​home|binding]] via script, use ''<​targetPropertyPath>​ ~= ['<​sourcePropertyPath>'​]''​. The following examples demonstrate how to create bindings via script.
 +
 +<​code>​
 +//Creates a serialized binding of "​height"​ to
 +//"​width"​ of the parent component.
 +@parent.width ~= ['​height'​];​
 +
 +//Another binding example.
 +@parent.string.value ~= ['​@parent.input.value'​];​
 +</​code>​
 +
 +==== Example ====
 +The following image shows the dataflow model before invoking a script. This script sets values, creates a binding, and returns an output value.
 +
 +{{:​dglux5_wiki:​dgscript:​script_before.png?​direct|}}
 +
 +The following is the script in the example.
 +<code javascript>​
 +@parent.stringA.value = "​abc123";​
 +@parent.stringB.value = "​def456";​
 +@parent.stringC.value ~= ['​@parent.stringB.value'​];​
 +@parent.stringD.value ~= @parent.stringA.value + "​_"​ + @parent.stringB.value;​
 +return "all done";
 +</​code>​
 +
 +The following image shows the same dataflow model after invoking the script.
 +
 +{{:​dglux5_wiki:​dgscript:​script_after.png?​direct|}}
 +
 +==== How to Traverse the Page Model ====
 +
 +You can use ''​while''​ loops to traverse the page model. The following example shows how to search the parent object, then the parent'​s parent, and so on, until a symbol is found.
 +
 +<code javascript>​
 +searchObject = @parent;
 +while(searchObject != null && typeof(searchObject) != '​symbol'​){
 +  searchObject = searchObject.@parent;​
 +}
 +
 +if (searchObject != null){
 +  // set the value
 +}
 +</​code>​
 +
 +----
 +
 +===== Debugging =====
 +The following examples print script output to the block'​s **print** property or to the browser console.
 +
 +To print the results of an expression to the current block'​s **print** property:
 +
 +<code javascript>​
 +//Prints 2 + 2 = 4
 +print("​2 + 2 = ", 2 + 2);
 +</​code>​
 +
 +To print results of expressions to the browser console:
 +
 +<code javascript>​
 +/*Prints the following output to the browser'​s console:
 +1
 +2
 +3
 +4
 +5
 +*/
 +
 +json = JSON.parse("​[1,​2,​3,​4,​5]"​);​
 +for (var i = 0; i < json.length;​ i++) {
 +    printConsole(json[i]);​
 +}
 +</​code>​
 +
 +----
 +
 +{{anchor:​reuse_script}}===== How to Reuse Script =====
 +You can refer to a script from within another Script, Column Mapping, or Filter block. When you do this, you can use ''​$params'',​ which is a special list that is only available when a script is called as a function from another script.
 +
 +The following example creates a script and then calls it from a Script block and a Column Mapping block:
 +  - Create a [[dglux5_wiki:​dataflow:​dataflow_blocks_reference:​logic:​script|Script]] block, and change its [[#​page_model|page model]] name to ''​multiplyAndAdd''​.
 +  - <​WRAP>​For the **script** property of ''​multiplyAndAdd'',​ add a script that multiplies two ''​$params''​ values and adds some other variable to the product:
 +
 +<code javascript>​
 +return $params[0] * $params[1] + @.a;
 +</​code>​
 +
 +For this example, you must also add an **a** property to ''​multiplyAndAdd''​ by clicking the plus sign, and set the value of **a** as 1.</​WRAP>​
 +  - Add a second Script block, and change its name to ''​callFunction''​.
 +  - <​WRAP>​For the **script** property of ''​callFunction'',​ add a script that calls ''​multiplyAndAdd''​ and provides some parameter values:
 +
 +<code javascript>​
 +return @parent.multiplyAndAdd(2,​3); ​
 +</​code>​
 +
 +In this example, ''​callFunction''​ returns 7, as shown in the following image.
 +
 +{{:​dglux5_wiki:​dgscript:​reuse_script_example.png?​direct|}}</​WRAP>​
 +  - Add a Table block and Column Mapping block.
 +  - Bind the Table block value to the Column Mapping block input.
 +  - For **name 0**, enter ''​v4''​.
 +  - <​WRAP>​For **from 0**, enter script that calls ''​multiplyAndAdd'':​
 +
 +''​=@parent.multiplyAndAdd(v1,​v2)''​
 +
 +In each row, the new column contains the product of **v1** and **v2** in this row, plus the value of **@.a** in ''​multiplyAndAdd''​. The following image demonstrates the input and output tables.
 +
 +{{:​dglux5_wiki:​dgscript:​reuse_script_example_2.png?​direct|}}</​WRAP>​
 +
 +
 +----
 +
 +===== Operators, Formats, and Functions =====
 +
 +This section demonstrates some operators, formats, and functions that can be used in DGLux5. For example, the [[dglux5_wiki:​dataflow:​dataflow_blocks_reference:​table_operations:​column_mapping|Column Mapping]] block, [[dglux5_wiki:​dataflow:​dataflow_blocks_reference:​table_operations:​filter|Filter]] block, and [[dglux5_wiki:​dataflow:​dataflow_blocks_reference:​date_time_operations:​home|Date Time Operations]] blocks use some of these items.
 +
 +==== Operators ====
 +These operators can be used in DGLux5.
 +
 +=== String Operators ===
 +^ Operator ​     ^ Description ​              ^ Example ​            ^ Result ​ ^
 +| Plus sign (+) | Concatenates two strings. ​ | ''​%%'​a'​+'​b';​%%'' ​           | ''​ab'' ​     |
 +
 +=== Number Operators ===
 +^ Operator ​          ^ Description ​              ^ Example ​  ^ Result ​ ^
 +| Plus sign (+)      | Adds two numbers. ​         | ''​5+5;'' ​ | ''​10'' ​ |
 +| Hyphen (-)         | Subtracts two numbers. ​    | ''​10-5;''​ | ''​5'' ​  |
 +| Asterisk (*)       | Multiplies two numbers. ​   | ''​2*2;'' ​ | ''​4'' ​  |
 +| Forward slash (/)  | Divides two numbers. ​      | ''​9/​2;'' ​ | ''​4.5''​ |
 +| Percent symbol (%) | Performs a modulo operation. This operation divides two numbers and returns the remainder. ​                                      | ''​10%3;''​ | ''​1'' ​  |
 +
 +=== Logical Operators ===
 +Logical operators appear in expressions that can be evaluated to TRUE or FALSE.
 +^ Operator ​                           ^ Example ​                ^ Result ​   ^
 +| Less Than (<​) ​                      | ''​5<​10;'' ​              | ''​true'' ​ |
 +| Greater Than (>​) ​                   | ''​10>​5;'' ​              | ''​true'' ​ |
 +| Less Than or Equal To (%%<​=%%) ​     | ''​%%5<​=5;​%%'' ​          | ''​true'' ​ |
 +| Greater Than or Equal To (%%>​=%%) ​  | ''​5>​=5;'' ​              | ''​true'' ​ |
 +| Equal To (%%==%%) ​                  | ''​%%'​5'​==5%%'' ​         | ''​true'' ​ |
 +| Strictly Equal To (%%===%%) ​        | ''​5==='​5';'' ​           | ''​false''​ |
 +| Not Equal To (%%!=%%) ​              | '''​1'​!=1;'' ​            | ''​false''​ |
 +| Not Strictly Equal To (%%!==%%) ​    | ''​%%'​1'​!=='​1'​%%'' ​      | ''​true'' ​ |
 +| And (&&​) ​                           | ''​true && false;'' ​     | ''​false''​ |
 +| Or (%%||%%) ​                        | ''​true %%||%% false;'' ​ | ''​true'' ​ |
 +
 +=== Bit-Wise Operators ===
 +You can use the following bitwise operators:
 +^ Operator ​ ^ Description ​  ^
 +| %%<<​%% ​   | Shift Left    |
 +| %%>>​%% ​   | Shift Right   |
 +| &         | Bit-wise And  |
 +| %%|%%     | Bit-wise Or   |
 +| %%^%%     | Bit-wise Xor  |
 +
 +
 +{{anchor:​strings}}==== String Usage and Functions ====
 +
 +=== String Literals ===
 +The following example demonstrates string literals in DGLux5:
 +<code javascript>​
 +str1 = '​Single quotes';​
 +str2 = "​Double quotes";​
 +str3 = '​Double quotes in "​single"​ quotes';​
 +str4 = "​Single quotes in '​double'​ quotes";​
 +str5 = "​escape quote \"";​
 +</​code>​
 +
 +=== Reserved Characters ===
 +In strings, you can use a backslash (\) to escape the following reserved characters:
 +  * Single quotation mark (')
 +  * Double quotation mark (")
 +  * Backslash (\)
 +
 +For example, the following code sets the string block'​s value to ''​C:​\'':​
 +<code javascript>​
 +@parent.string.value = "​C:​\\"; ​
 +</​code>​
 +
 +=== Special Sequences ===
 +In strings, you can use the following special character sequences to create these effects:
 +
 +  * ''​\n''​ creates a new line.
 +  * ''​\r''​ creates a carriage return.
 +  * ''​\t''​ creates a tab.
 +  * ''​\uXXXX''​ uses a Unicode code point.
 +
 +{{anchor:​string}}=== String Functions ===
 +The following functions perform an operation on an input string.
 +^ Function ​                              ^ Description and Example ^
 +| ''​String(obj)'' ​                       | <​WRAP>​Takes an input object, casts the object as a string, and returns the string.
 +
 +The following example returns ''​123''​ as a string.
 +
 +<code javascript>​String(123);</​code></​WRAP>​|
 +| ''​String(num,​16)'' ​                    | <​WRAP>​Takes an input base-10 number, converts the number to base 16, and returns the base-16 number as a string.
 +
 +The following example returns the string ''​1b''​.
 +
 +<code javascript>​String(27,​16);</​code></​WRAP>​|
 +| ''​str.length'' ​                        | <​WRAP>​Counts the number of characters in an input string and returns the number.
 +
 +The following example returns the number 4.
 +
 +<code javascript>"​acbd"​.length;</​code></​WRAP>​|
 +| ''​str.charAt(pos)'' ​                   | <​WRAP>​Returns the character at the specified position in an input string. The first position is represented as 0.
 +
 +The following example returns the character ''​b''​.
 +
 +<code javascript>"​abc"​.charAt(1);</​code></​WRAP>​|
 +| ''​str.charCodeAt(pos)'' ​               | <​WRAP>​Returns the character code for the character at the specified position in an input string. The first position is represented as 0.
 +
 +The following example returns 98, the character code for the letter "​b"​.
 +
 +<code javascript>"​abc"​.charCodeAt(1);</​code></​WRAP>​|
 +| ''​str.indexOf(searchStr)'' ​            | <​WRAP>​Returns the position of the first character of the first occurrence of the search string, or returns -1 if the search string is not found. The first position is represented as 0.
 +
 +The following example returns the number 1.
 +
 +<code javascript>"​abc"​.indexOf("​bc"​);</​code></​WRAP>​|
 +| ''​str.lastIndexOf(searchStr)'' ​        | <​WRAP>​Returns the position of the first character of the last occurrence of the search string, or returns -1 if the search string is not found. The first position is represented as 0.
 +
 +The following example returns the number 2.
 +
 +<code javascript>"​abb"​.lastIndexOf("​b"​);</​code></​WRAP>​|
 +| ''​str.split(delimiter)'' ​              | <​WRAP>​Takes an input string that contains delimiters and returns an array of strings.
 +
 +The following example returns the array ''​["​1","​2","​3"​]''​.
 +
 +<code javascript>"​1,​2,​3"​.split(","​);</​code></​WRAP>​|
 +| ''​str = list.join(char)'' ​             | <​WRAP>​Takes an input list and converts it to an output string by joining items in the list with a provided delimiting character.
 +
 +The following example returns the string ''​1/​2/​3''​.
 +
 +<code javascript>​[1,​2,​3].join("/"​);</​code></​WRAP>​|
 +| ''​str.subStr(start,​ length)'' ​         | <​WRAP>​Extracts the specified number of characters starting from the specified position, and returns the substring. The first position is represented as 0.
 +
 +The following example returns the string ''​bc''​.
 +
 +<code javascript>"​abcd"​.subStr(1,​2);</​code></​WRAP>​|
 +| ''​str.subString(start,​end)'' ​          | <​WRAP>​Extracts the substring beginning with the specified start position and ending one position before the specified end value. The first position in a string is represented as 0.
 +
 +The following example returns the string ''​b''​.
 +
 +<code javascript>"​abcd"​.subString(1,​2);</​code></​WRAP>​|
 +| ''​str.replace(regexPattern,​ replace)''​ | <​WRAP>​Replaces all instances of the specified regular expression pattern with the replacement string.
 +
 +The following example returns the string ''​d d''​.
 +
 +<code javascript>"​DabcG DdefG"​.replace(/​D(\w+)/​g,​ "​d"​);</​code></​WRAP>​|
 +| ''​str.replaceAll(find,​ replace)'' ​     | <​WRAP>​Replaces all instances of the specified ''​find''​ string with the specified ''​replace''​ string.
 +
 +The following example returns the string ''​1_2_3''​.
 +
 +<code javascript>"​1#​2#​3"​.replaceAll("#","​_"​);</​code></​WRAP>​|
 +| ''​str.toLowerCase()'' ​                 | <​WRAP>​Converts all letters in a string to lowercase letters.
 +
 +The following example returns the string ''​dg''​.
 +
 +<code javascript>"​DG"​.toLowerCase();</​code></​WRAP>​|
 +| ''​str.toUpperCase()'' ​                 | <​WRAP>​Converts all letters in a string to uppercase letters.
 +
 +The following example returns the string ''​DG''​.
 +
 +<code javascript>"​dg"​.toUpperCase();</​code></​WRAP>​|
 +| ''​str.encodeUriComponent()'' ​          | <​WRAP>​Encodes an input URI component.
 +
 +The following example returns the string ''​a%20b''​.
 +
 +<code javascript>"​a b"​.encodeUriComponent();</​code></​WRAP>​|
 +| ''​str.decodeUriComponent()'' ​          | <​WRAP>​Decodes an encoded URI component string.
 +
 +The following example returns the string ''​a b''​.
 +
 +<code javascript>"​a%20b"​.decodeUriComponent();</​code></​WRAP>​|
 +| ''​str.splitQuery()'' ​                  | <​WRAP>​Splits the input query string and decodes the string into an Object.
 +
 +The following example returns the Object ''​{"​a b": "​1",​ "​c":​ "​d"​}''​.
 +
 +<code javascript>"​a%20b=1&​c=d"​.splitQuery();</​code></​WRAP>​|
 +| ''​str.encodeBase64();'' ​               | <​WRAP>​Encodes the input string, using base-64 encoding.
 +
 +The following example returns an encoded string.
 +
 +<code javascript>"​abc123"​.encodeBase64();</​code></​WRAP>​|
 +| ''​str.decodeBase64();'' ​               | <​WRAP>​Decodes a string that was encoded using ''​str.encodeBase64()''​.
 +
 +The following example returns a decoded string.
 +
 +<code javascript>"​YWJjMTQ0"​.decodeBase64();</​code></​WRAP>​|
 +| ''​str.md5();'' ​                        | <​WRAP>​Generates a 16-byte hash value that identifies the input string.
 +
 +The following example returns a 16-byte hash value.
 +
 +<code javascript>"​abc123"​.md5();</​code></​WRAP>​|
 +| ''​str.sha1();'' ​                       | <​WRAP>​Generates a 20-byte hash value that identifies the input string.
 +
 +The following example returns a 20-byte hash value.
 +
 +<code javascript>"​abc123"​.sha1();</​code></​WRAP>​|
 +| ''​str.sha256();'' ​                     | <​WRAP>​Generates an almost-unique 256-bit hash value that identifies the input string.
 +
 +The following example returns a 256-byte hash value.
 +
 +<code javascript>"​abc123"​.sha256();</​code></​WRAP>​ |
 +
 +
 +{{anchor:​number}}==== Number Formats, Functions, and Constants ====
 +<WRAP tip>​===Tip===
 +To quickly check whether a value is number, add zero to the value, and then test whether the value has changed. If the value is a number, it does not change; if the value is a string, the zero is concatenated.
 +
 +<code javascript>​
 +val = "​123";​
 +if (0+val == val) return "​It'​s Numeric!";​
 +</​code>​
 +</​WRAP>​
 +
 +=== Number Format Patterns ===
 +
 +You can specify a number format using the following subset of ICU formatting patterns:
 +
 +^Formatting Pattern ​          ^ Description ​                                                                                                   ^
 +| Zero (0)                    | Represents a single digit and is included even if the digit is a non-significant zero.                         |
 +| Number sign (#)             | Represents a single digit and is omitted if the digit is a non-significant zero.                               |
 +| Decimal (.)                 | Represents the decimal separator. ​                                                                             |
 +| Hyphen (-)                  | Represents a minus sign.                                                                                       |
 +| Comma (,)                   | Represents the grouping separator. ​                                                                            |
 +| The letter E                | Separates a number and that number’s exponent. ​                                                                |
 +| Plus sign (+)               | When used before an exponent, indicates to prefix a positive exponent with a plus sign.                        |
 +| Percent symbol (%)          | When used in a prefix or suffix, indicates to multiply the number by 100 and show the number as a percentage. ​ |
 +| Per mile sign (‰ or \u2030) | Indicates to multiply the number by 1000 and show the number as per mile.                                      |
 +| Currency sign (¤ or \u00A4) | Gets replaced by the currency name.                                                                            |
 +| Single quotes ('​) ​          | Used to quote special characters. ​                                                                             |
 +| Semicolon (;)               | Separates the positive and negative patterns if both are present. ​                                             |
 +
 +=== Number Functions ===
 +^ Function ​                             ^ Description and Example ​ ^
 +| ''​Number(str)'' ​                      | <​WRAP>​Takes an input string, converts the string to a number, and returns the number.
 +
 +The following example returns the number 12.12.
 +
 +<code javascript>​Number("​12.12"​);</​code></​WRAP>​|
 +| ''​isNaN(str)'' ​                       | <​WRAP>​Returns TRUE if the string is not a number.
 +
 +The following example returns the boolean value TRUE.
 +
 +<code javascript>​isNaN(Number("​abc"​));</​code></​WRAP>​|
 +| ''​num = parseNumber(str)'' ​           | <​WRAP>​Parses a number from a string and returns the number.
 +
 +The following example returns the number 12.11.
 +
 +<code javascript>​parseNumber('​$12.11'​);</​code></​WRAP>​|
 +| ''​str = numberFormat(num,​ pattern)'' ​ | <​WRAP>​Formats the input number using the input number format pattern.
 +
 +The following example returns the string ''​$123.46''​.
 +
 +<code javascript>​numberFormat(123.456789,"​$#​.00"​);</​code></​WRAP>​|
 +
 +{{anchor:​math}}=== Math Functions ===
 +
 +^ Function ​                    ^ Description and Example ​ ^
 +| ''​Math.abs(num)'' ​           | <​WRAP>​Returns the absolute value of ''​num''​.
 +
 +The following example returns 47.
 +
 +<code javascript>​Math.abs(-47);</​code></​WRAP>​|
 +| ''​Math.min(num1,​num2,​...)'' ​ | <​WRAP>​Returns the smallest input number.
 +
 +The following example returns -2.
 +
 +<code javascript>​Math.min(-2,​-1,​0,​1,​2);</​code></​WRAP>​|
 +| ''​Math.max(num1,​num2,​...)'' ​ | <​WRAP>​Returns the greatest input number.
 +
 +The following example returns 2.
 +
 +<code javascript>​Math.max(-2,​-1,​0,​1,​2);</​code></​WRAP>​|
 +| ''​Math.sin(num)'' ​           | <​WRAP>​Returns the sine of ''​num'',​ where ''​num''​ is given in radians.
 +
 +The following example returns 1.
 +
 +<code javascript>​Math.sin(Math.PI / 2);</​code></​WRAP>​|
 +| ''​Math.cos(num)'' ​           | <​WRAP>​Returns the cosine of ''​num'',​ where ''​num''​ is given in radians.
 +
 +The following example returns -1.
 +
 +<code javascript>​Math.cos(Math.PI);</​code></​WRAP>​|
 +| ''​Math.tan(num)'' ​           | <​WRAP>​Returns the tangent of ''​num'',​ where ''​num''​ is given in radians.
 +
 +The following example returns 1.5574077246549023.
 +
 +<code javascript>​Math.tan(1);</​code></​WRAP>​|
 +| ''​Math.asin(num)'' ​          | <​WRAP>​Returns the arcsine in radians of ''​num''​.
 +
 +The following example returns TRUE.
 +
 +<code javascript>​Math.asin(1) == Math.PI / 2;</​code></​WRAP>​|
 +| ''​Math.acos(num)'' ​          | <​WRAP>​Returns the arccosine of ''​num''​.
 +
 +The following example returns TRUE.
 +
 +<code javascript>​Math.acos(-1) == Math.PI;</​code></​WRAP>​|
 +| ''​Math.atan(num)'' ​          | <​WRAP>​Returns the arctangent of ''​num''​.
 +
 +The following example returns 1.
 +
 +<code javascript>​Math.atan(1.5574077246549023);</​code></​WRAP>​|
 +| ''​Math.atan2(y,​ x)'' ​        | <​WRAP>​Returns the arctangent of the quotient of ''​y''​ divided by ''​x''​.
 +
 +The following example returns 1.4056476493802699.
 +
 +<code javascript>​Math.atan2(90,​15);</​code></​WRAP>​|
 +| ''​Math.ceil(num)'' ​          | <​WRAP>​Rounds up ''​num''​ to the nearest integer.
 +
 +The following example returns 2.
 +
 +<code javascript>​Math.ceil(1.2);</​code></​WRAP>​|
 +| ''​Math.floor(num)'' ​         | <​WRAP>​Rounds down ''​num''​ to the nearest integer.
 +
 +The following example returns 1.
 +
 +<code javascript>​Math.floor(1.7);</​code></​WRAP>​|
 +| ''​Math.round(num)'' ​         | <​WRAP>​Rounds num up or down to the nearest integer.
 +
 +The following example returns 2.
 +
 +<code javascript>​Math.round(1.7);</​code></​WRAP>​|
 +| ''​Math.exp(num)'' ​           | <​WRAP>​Returns the result of raising the mathematical constant //e// to the value of ''​num''​.
 +
 +The following example returns TRUE.
 +
 +<code javascript>​Math.exp(2) == Math.pow(Math.E,​2);</​code></​WRAP>​|
 +| ''​Math.log(num)'' ​           | <​WRAP>​Returns the natural (base-//​e//​) logarithm of ''​num''​.
 +
 +The following example returns 2.302585092994046 .
 +
 +<code javascript>​Math.log(10);</​code></​WRAP>​|
 +| ''​Math.sqrt(num)'' ​          | <​WRAP>​Returns the square root of ''​num''​.
 +
 +The following example returns 3.
 +
 +<code javascript>​Math.sqrt(9);</​code></​WRAP>​|
 +| ''​Math.pow(num,​ exponent)'' ​ | <​WRAP>​Returns the result of raising ''​num''​ to the value of ''​exponent''​.
 +
 +The following example returns 8.
 +
 +<code javascript>​Math.pow(2,​3);</​code></​WRAP>​|
 +| ''​Math.random()'' ​           | <​WRAP>​Returns a random number between zero and one.
 +
 +The following example returns a random number.
 +
 +<code javascript>​Math.random();</​code></​WRAP>​|
 +
 +
 +=== Number Constants ===
 +
 +^ Constant ​     ^ Value                                                           ^
 +| Math.PI ​      | 3.141592653589793,​ the constant pi                              |
 +| Math.E ​       | 2.718281828459045,​ the constant //e//                           |
 +| Math.LN2 ​     | 0.6931471805599453,​ the natural (base-//​e//​) logarithm of two   |
 +| Math.LN10 ​    | 2.302585092994046,​ the natural (base-//​e//​) logarithm of ten    |
 +| Math.LOG2E ​   | 1.4426950408889634,​ the base-2 logarithm of the constant //e//  |
 +| Math.LOG10E ​  | 0.4342944819032518,​ the base-10 logarithm of the constant //e// |
 +| Math.SQRT2 ​   | 1.4142135623730951,​ the square root of two                      |
 +| Math.SQRT1_2 ​ | 0.7071067811865476,​ the square root of one-half ​                |
 +
 +<WRAP tip>​===Tip===
 +The following example gets a random value within a certain range:
 +<code javascript>​
 +function getRandom(min,​ max) {
 +    return Math.random() * (max - min) + min;
 +}
 +
 +getRandom(50,​75);​
 +</​code>​
 +</​WRAP>​
 +
 +{{anchor:​datetime}}==== DateTime Formats and Functions ====
 +
 +=== Examples of supported new DateTime (dateString) formats ===
 +The following are examples of date and time strings that have been formatted using date and time formatting strings:
 +
 +   * 2012-02-27 13:27:00
 +   * 2012-02-27 13:​27:​00.123456z
 +   * 20120227 13:27:00
 +   * 20120227T132700
 +   * 20120227
 +   * +20120227
 +   * 2012-02-27T14Z
 +   * 2012-02-27T14+00:​00
 +
 +<WRAP info>​===Note===
 +The string 2002-02-27T14:​00:​00-0500 represents the same date and time as the string 2002-02-27T19:​00:​00Z.
 +</​WRAP>​
 +
 +{{anchor:​supported_dateformat_patterns}}=== Supported dateFormat patterns ===
 +The following table lists date and time pattern components. These components can be included within a date and time format string.
 +
 +<WRAP info>​===Notes===
 +  * Date and time strings are affected by locale.
 +  * In some languages, the month of a year, or the day of a week, is a different word or declension from a standalone month or day.
 +</​WRAP>​
 +
 +^ Symbol ​ ^ Meaning ​                                                          ^ Example ​               ^
 +| G       | Era designator ​                                                   | AD                     |
 +| y       | Year                                                              | 2017                   |
 +| M       | Month in year, number ​                                            | 8                      |
 +| MM      | Month in year, number as two digits ​                              | 08                     |
 +| MMM     | Month in year, abbreviated name                                   | Aug                    |
 +| MMMM    | Month in year, full name                                          | August ​                |
 +| L       | Standalone month, number ​                                         | 0                      |
 +| LL      | Standalone month, number as two digits ​                           | 08                     |
 +| LLL     | Standalone month, abbreviated name                                | Aug                    |
 +| LLLL    | Standalone month, full name                                       | August ​                |
 +| d       | Day in month                                                      | 10                     |
 +| c       | Standalone day                                                    | 10                     |
 +| h       | Hour in 12-hour time (1–12) ​                                      | 12                     |
 +| H       | Hour in 24-hour time (0–23) ​                                      | 0                      |
 +| m       | Minute in hour                                                    | 30                     |
 +| s       | Second in minute ​                                                 | 55                     |
 +| S       | Fractional second ​                                                | 978                    |
 +| E       | Day of week, abbreviated name                                     | Fri                    |
 +| EEEE    | Day of week, full name                                            | Friday ​                |
 +| D       | Day of year                                                       | 189                    |
 +| a       | AM or PM designator ​                                              | PM                     |
 +| k       | Hour of day, in 24-hour time (0–23) ​                              | 24                     |
 +| K       | Hour of day, in 12-hour time (0–11) ​                              | 0                      |
 +| z       | General time zone                                                 | -8                     |
 +| Z       | Time zone, RFC 822                                                | -800                   |
 +| v       | Time zone, generic name                                           | PDT                    |
 +| Q       | Quarter ​                                                          | Q3                     |
 +|Single quotation mark ('​) ​  | Escapes a character or encloses a string ​      | %%'​o''​clock'​%%,​ %%'​Date='​%% ​ |
 +
 +=== Supported ICU/​dateFormat skeletons ===
 +The following table lists ICU date and time skeleton components. These components can be combined to create an ICU dateFormat skeleton, which can format DateTime values.
 +<WRAP info>​===Note===
 +  * Date and time strings are affected by locale.
 +  * You can use two vertical bar characters separated by a space (| |) to join two dateFormat skeletons. For example, the string ''​yMd| |Hms''​ produces the string ''​8/​24/​2015 15:​38:​00''​.
 +</​WRAP>​
 +
 +^ String ​     ^ Meaning ​                                           ^ Example (en_US locale) ​    ^
 +| d           | Day                                                | 24                         |
 +| E           | Day of week                                        | Thu                        |
 +| EEEE        | Day of week                                        | Thursday ​                  |
 +| LLL         | Standalone month                                   | Aug                        |
 +| LLLL        | Standalone month                                   | August ​                    |
 +| M           | Month                                              | 8                          |
 +| Md          | Month and day                                      | 8/24                       |
 +| MEd         | Month, day, and day of week                        | Thu, 8/24                  |
 +| MMM         | Month                                              | Aug                        |
 +| MMMd        | Month and day                                      | Aug 24                     |
 +| MMMEd       | Month, day, and day of week                        | Thu, Aug 24                |
 +| MMMM        | Month                                              | August ​                    |
 +| MMMMd       | Month and day                                      | August 24                  |
 +| MMMMEEEEd ​  | Month, day, and day of week                        | Thursday, August 24        |
 +| QQQ         | Quarter ​                                           | Q3                         |
 +| QQQQ        | Quarter ​                                           | 3rd quarter ​               |
 +| y           | Year                                               | 2015                       |
 +| yM          | Year and month                                     | 8/​2017 ​                    |
 +| yMd         | Year, month, and day                               | 8/​1/​2017 ​                  |
 +| yMEd        | Year, month, day, and day of week                  | Thu, 8/​24/​2017 ​            |
 +| yMMM        | Year and month                                     | Aug 2017                   |
 +| yMMMd       | Year, month, and day                               | August 1, 2017             |
 +| yMMMEd ​     | Year, month, day, and day of week                  | Thu, Aug 24, 2017          |
 +| yMMMM       | Year and month                                     | August 2017                |
 +| yMMMMd ​     | Year, month, and day                               | August 24, 2017            |
 +| yMMMMEEEEd ​ | Year, month, day, and day of week                  | Thursday, August 24, 2017  |
 +| yQQQ        | Year and quarter ​                                  | Q3 2017                    |
 +| yQQQQ       | Year and quarter ​                                  | 3rd quarter 2017           |
 +| H           | Hour in day (24-hour time)                         | 15                         |
 +| Hm          | Hour and minute (24-hour time)                     | 15:38                      |
 +| Hms         | Hour, minute, and second (24-hour time)            | 15:​38:​00 ​                  |
 +| j           | Hour (12-hour time)                                | 3 PM                       |
 +| jm          | Hour and minute (12-hour time)                     | 3:38 PM                    |
 +| jms         | Hour, minute, and second (12-hour time)            | 3:38:00 PM                 |
 +| m           | Minute ​                                            | 38                         |
 +| ms          | Minute and second ​                                 | 38:00                      |
 +| s           | Second ​                                            | 0                          |
 +
 +==== DateTime Functions ====
 +<WRAP info>​===Note===
 +If a ''​DateTime''​ object is sent to an output property of the Script dataflow block, the object is converted to a string, and the block property holds a string.
 +</​WRAP>​
 +
 +^ Function ​                                 ^ Description and Example^
 +| ''​new DateTime()'' ​                       | <​WRAP>​Returns a ''​DateTime''​ object that is initialized with the current date and time.
 +
 +The following function returns a year, such as 2017.
 +
 +<code javascript>​new DateTime().year;</​code></​WRAP>​|
 +| ''​new DateTime(millisecondsSinceEpoch)'' ​ | <​WRAP>​Returns a ''​DateTime''​ object that is initialized with the specified value. ​                                                                     ​
 +
 +The following function returns 1969-12-31T16:​00:​00.000.
 +
 +<code javascript>​new DateTime(0);</​code></​WRAP>​|
 +| ''​new DateTime(dateString)'' ​             | <​WRAP>​Returns a ''​DateTime''​ object that is initialized with the parsed date and time string. ​                                                         ​
 +
 +The following function returns 2017-02-27T13:​27:​00.000.
 +
 +<code javascript>​new DateTime('​2017-02-27 13:​27:​00'​);</​code></​WRAP>​|
 +| ''​new DateTime(y,​m,​d,​h,​m,​s,​ms)'' ​         | <​WRAP>​Returns a ''​DateTime''​ object that is initialized with the specified values.
 +
 +The following function returns 2017-01-01 00:​00:​00.000.
 +
 +<code javascript>​new DateTime(2017,​1,​1,​0,​0,​0,​0);</​code></​WRAP>​|
 +| ''​day'' ​                                  | <​WRAP>​Returns a day of the month.
 +
 +The following function returns 1.
 +
 +<code javascript>​new DateTime(2017,​1,​1).day;</​code></​WRAP>​|
 +| ''​month'' ​                                | <​WRAP>​Returns a month of the year. January is represented as 1.
 +
 +The following function returns 2.
 +
 +<code javascript>​new DateTime('​2017-02-27 13:​27:​00'​).month;</​code></​WRAP>​|
 +| ''​year'' ​                                 | <​WRAP>​Returns a year.
 +
 +The following function returns a year, such as 2016.
 +
 +<code javascript>​new DateTime().year;</​code></​WRAP>​|
 +| ''​hour'' ​                                 | <​WRAP>​Returns an hour.
 +
 +The following function returns 13.
 +
 +<code javascript>​new DateTime('​2017-02-27 13:​27:​00'​).hour;</​code></​WRAP>​|
 +| ''​minute'' ​                               | <​WRAP>​Returns a minute.
 +
 +The following function returns 27.
 +
 +<code javascript>​new DateTime('​2017-02-27 13:​27:​00'​).minute;</​code></​WRAP>​|
 +| ''​second'' ​                               | <​WRAP>​Returns a second.
 +
 +The following function returns 0.
 +
 +<code javascript>​new DateTime('​2017-02-27 13:​27:​00'​).second;</​code></​WRAP>​|
 +| ''​millisecond'' ​                          | <​WRAP>​Returns a millisecond. ​
 +
 +The following function returns 798.
 +
 +<code javascript>​new DateTime('​2017-01-01T13:​27:​00.798'​).millisecond;</​code></​WRAP>​|
 +| ''​millisecondsSinceEpoch'' ​               | <​WRAP>​Returns the milliseconds since the start of the Unix epoch.
 +
 +The following function returns the millisecondsSinceEpoch,​ such as 1466113382710.
 +
 +<code javascript>​new DateTime().millisecondsSinceEpoch;</​code></​WRAP>​ |
 +| ''​weekday'' ​                              | <​WRAP>​Returns a day of the week. Monday is represented as 1, and Sunday is represented as 7.
 +
 +The following function returns the weekday, such as 4.
 +
 +<code javascript>​new DateTime().weekday;</​code></​WRAP>​|
 +| ''​isUtc'' ​                                | <​WRAP>​Returns whether the date is UTC.
 +
 +The following function returns false.
 +
 +<code javascript>​new DateTime(2017,​1,​1).isUtc;</​code></​WRAP>​|
 +| ''​dateNow()'' ​                            | <​WRAP>​Returns the millisecondsSinceEpoch of the current date and time.
 +
 +The following function returns the millisecondsSinceEpoch,​ such as 1466113699717.
 +
 +<code javascript>​dateNow();</​code>​ </​WRAP>​ |
 +| ''​dateParse(str)'' ​                       | <​WRAP>​Parses a date from a string and then returns ''​int(millisecondsSinceEpoch)''​ of that date. ''​dateParse''​ supports a super-set of formats supported by ''​DateTime(dateString)''​.
 +
 +The following function returns 1293868800000.
 +
 +<code javascript>​dateParse('​1/​1/​2011'​);</​code></​WRAP>​|
 +| ''​dateFormat(date,​ dateFormat)'' ​         | <​WRAP>​Parses date string or uses millisecondsSinceEpoch and returns the string in the specified dateFormat.
 +
 +The following function returns a string, such as 06/2016.
 +
 +<code javascript>​dateFormat(dateNow(),"​MM/​yyyy"​);</​code></​WRAP>​ |
 +
 +
 +=== DateTime Function Examples ===
 +
 +The following example quickly finds the number of days in the previous month.
 +
 +<code javascript>​
 +dt = new DateTime();
 +lastMonth = new DateTime(dt.year,​dt.month,​ 0, dt.hour, dt.minute, dt.second, dt.millisecond);​
 +print (lastMonth.day);​
 +</​code>​
 +The following example returns the most recent Sunday before the current date.
 +
 +<code javascript>​
 +dt = new DateTime(); ​
 +lastSunday = new DateTime(dt.year,​ dt.month, dt.day - dt.weekday);​
 +</​code>​
 +
 +{{anchor:​list}}==== List Functions ====
 +
 +^ Function ​                                    ^ Description and Example ^
 +| ''​length'' ​                                  | <​WRAP>​Returns the number of items in a list.
 + 
 +The following example returns the number 3.        ​
 +
 +<code javascript>​[1,​2,​3].length;</​code></​WRAP>​ |
 +| ''​push'' ​                                    | <​WRAP>​Adds an item to the end of a list. 
 +
 +The following example returns the list ''​[1,​2,​3]''​. ​
 +
 +<code javascript>​row = [1,2];
 +row.push(3);​
 +return row;</​code></​WRAP> ​                     |
 +| ''​pop'' ​                                     | <​WRAP>​Removes an item from the end of a list and returns the item.
 +
 +In the following example, the value of ''​a''​ is 3, and the value of ''​b''​ is ''​[1,​2]''​.
 +
 +<code javascript>​row = [1,2,3];
 +@.a = row.pop();
 +@.b = row;</​code></​WRAP> ​                      |
 +| ''​indexOf(searchObject)'' ​                   | <​WRAP>​Returns the position of the first character of the first occurrence of the search string. Returns –1 if the search string is not found. The first position is represented as 0.
 +
 +The following example returns the number 1.
 +
 +<code javascript>​["​a","​b","​c"​].indexOf("​b"​);</​code></​WRAP>​ |
 +| ''​join(delimiter)'' ​                         | <​WRAP>​Returns a delimited string of items in the list. 
 +
 +The following example returns the string ''​a and b and c''​.
 +
 +<code javascript>​["​a","​b","​c"​].join("​ and "​);</​code></​WRAP>​ |
 +| ''​splice(start,​len,​newItem1,​newItem2,​...)'' ​ | <​WRAP>​Removes //n// items beginning at the start position, where //n// = ''​len''​. Then, inserts new items into the same position and returns the items that are removed. The first position is represented with 0.
 +
 +In the following example, the value of ''​a''​ is ''​[2,​3]'',​ and the value of ''​b''​ is ''​[1,​0,​0,​4]''​.
 +
 +<code javascript>​row = [1,2,3,4];
 +@.a = row.splice(1,​2,​0,​0);​
 +@.b = row;</​code></​WRAP>​ |
 +
 +{{anchor:​json}}==== JSON Functions ====
 +
 +^ Function ​                ^ Description and Example ^
 +| ''​JSON.parse(str)'' ​     | <​WRAP>​Converts a string to a JSON object.
 +
 +<code javascript>​JSON.parse('​{"​a":​1}'​);</​code>​
 +
 +The above example returns the JSON object ''​{"​a":​1}''​. If this object is sent to an output property of the Script dataflow block, the object is converted to a string, and the block property holds a string.</​WRAP>​ |
 +| ''​JSON.stringify(obj)'' ​ | <​WRAP>​Converts a JSON object to a string.
 +
 +The following example returns the string ''​{"​a":​1}''​.
 +
 +<code javascript>​
 +var json = JSON.parse('​{"​a":​1}'​);​
 +JSON.stringify(json);</​code></​WRAP> ​ |
 +
 +=== JSON Function Example ===
 +The following example uses a ''​for''​ loop to print the ''​id''​ values for each item in a JSON object and to print rows of dashes to represent null items.
 +
 +<code javascript>​
 +json = {"​menu":​ {
 +    "​header":​ "SVG Viewer",​
 +    "​items":​ [
 +        {"​id":​ "​Open"​},​
 +        {"​id":​ "​OpenNew",​ "​label":​ "Open New"},
 +        null,
 +        {"​id":​ "​ZoomIn",​ "​label":​ "Zoom In"},
 +        {"​id":​ "​ZoomOut",​ "​label":​ "Zoom Out"},
 +        {"​id":​ "​OriginalView",​ "​label":​ "​Original View"​},​
 +        null,
 +        {"​id":​ "​Quality"​},​
 +        {"​id":​ "​Pause"​},​
 +        {"​id":​ "​Mute"​},​
 +        null,
 +        {"​id":​ "​Find",​ "​label":​ "​Find..."​},​
 +        {"​id":​ "​FindAgain",​ "​label":​ "Find Again"​},​
 +        {"​id":​ "​Copy"​},​
 +        {"​id":​ "​CopyAgain",​ "​label":​ "Copy Again"​},​
 +        {"​id":​ "​CopySVG",​ "​label":​ "Copy SVG"},
 +        {"​id":​ "​ViewSVG",​ "​label":​ "View SVG"},
 +        {"​id":​ "​ViewSource",​ "​label":​ "View Source"​},​
 +        {"​id":​ "​SaveAs",​ "​label":​ "Save As"},
 +        null,
 +        {"​id":​ "​Help"​},​
 +        {"​id":​ "​About",​ "​label":​ "About SVG Viewer..."​}
 +    ]
 +}};
 +
 +print(json.menu.header);​
 +
 +for (var i = 0; i < json.menu.items.length;​ i++) {
 +    if (json.menu.items[i] == null)
 +    {
 +        print("​----"​);​
 +    }
 +    else
 +    {
 +        print(json.menu.items[i].id);​
 +    }
 +}
 +</​code>​
 +The output for this example is the following:
 +<​code>​
 +SVG ViewerOpenOpenNew----ZoomInZoomOutOriginalView----QualityPauseMute----FindFindAgainCopyCopyAgainCopySVGViewSVGViewSourceSaveAs----HelpAbout
 +</​code>​
 +{{anchor:​xml}}==== XML Functions ====
 +
 +^ Function ^ Description and Example ^
 +| ''​XML.parse(str)'' ​            | <​WRAP>​Converts an XML string into XML elements.
 +
 +<code javascript>​var xml = XML.parse('<​p id=\"​a\">​b<​\/​p>'​);</​code>​
 +
 +In the above example, the value of ''​var''​ is the XML object ''<​p id="​a">​b</​p>''​. If this object is sent to an output property of the Script dataflow block, the object is converted to a string, and the block property holds a string.</​WRAP>​ |
 +| ''​XML.stringify(xmlElement)'' ​ | <​WRAP>​Converts XML elements into an XML string ​
 +
 +The following example returns the string ''<​p id="​a">​b</​p>''​. ​
 +
 +<code javascript>​var xml = XML.parse('<​p id=\"​a\">​b<​\/​p>'​);​
 +@.a = XML.stringify(xml);</​code></​WRAP>​|
 +| ''​query(str)'' ​                | <​WRAP>​Returns the first matching element. ​
 +
 +The following example returns ''<​item>​ITEM 1</​item>''​.
 +
 +<code javascript>​var xml = XML.parse('​\<​items\>​\<​item\>​ITEM 1\</​item\>​\<​item\>​ITEM 2\</​item\>​\</​items\>'​);​
 +xml.query('​item'​);</​code></​WRAP>​|
 +| ''​queryAll(str)'' ​             | <​WRAP>​Returns a List of matching elements.
 +
 +The following example returns ''<​item>​ITEM 1</​item>,​ <​item>​ITEM 2</​item>''​.
 +
 +<code javascript>​var xml = XML.parse('​\<​items\>​\<​item\>​ITEM 1\</​item\>​\<​item\>​ITEM 2\</​item\>​\</​items\>'​);​
 +var items = xml.queryAll('​item'​);​
 +@.a = items.join(',​ '​);</​code></​WRAP>​ |
 +| ''​children'' ​                  | <​WRAP>​Returns a List of all children. ​
 +
 +The following example returns ''​B 1,<​c>​C 1</​c>''​.
 +
 +<code javascript>​var xml = XML.parse('​\<​a\>​\<​b\>​B 1\<​c\>​C 1\</​c\>​\</​b\>​\<​b\>​B 2\</​b\>​\</​a\>'​);​
 +var ch = xml.query('​b'​).children;​
 +return ch.join(','​);</​code></​WRAP>​ |
 +| ''​elements'' ​                  | <​WRAP>​Returns a list of children elements.
 +
 +The following example returns ''<​c>​C 1</​c>''​.
 +
 +<code javascript>​var xml = XML.parse('​\<​a\>​\<​b\>​B 1\<​c\>​C 1\</​c\>​\</​b\>​\<​b\>​B 2\</​b\>​\</​a\>'​);​
 +var el = xml.query('​b'​).elements;​
 +return el.join(','​);</​code></​WRAP>​|
 +| ''​name'' ​                      | <​WRAP>​Returns the name of an element.
 +
 +The following example returns ''​a''​. ​
 +
 +<code javascript>​var xml = XML.parse('​\<​a b=\"​1\"​\>​A\</​a\>'​);​
 +return xml.name;</​code></​WRAP> ​  |
 +| ''​data'' ​                      | <​WRAP>​Returns the data of an element, when the element is a data node. The ''​text''​ function is strongly recommended instead of the ''​data''​ function.
 +
 +The following example returns ''​A''​.
 +
 +<code javascript>​var xml = XML.parse('​\<​a b=\"​1\"​\>​A\</​a\>'​);​
 +return xml.children[0].data;</​code></​WRAP> ​                                    |
 +| ''​text'' ​                      | <​WRAP>​Returns the text of an element. Checks whether the node is a data node or has a data node as a child.
 +
 +The following example returns ''​A''​. ​
 +
 +<code javascript>​var xml = XML.parse('​\<​a b=\"​1\"​\>​A\</​a\>'​);​
 +return xml.text;</​code></​WRAP>​ |
 +| ''​getAttribute(str)'' ​         | <​WRAP>​Returns an attribute value.
 +
 +The following example returns ''​1''​.
 +
 +<code javascript>​var xml = XML.parse('​\<​items\>​\<​item att=\"​1\"​\>​A\</​item\>​\</​items\>'​);​
 +var item = xml.query('​item'​);​
 +var att = item.getAttribute('​att'​);​
 +return att;</​code></​WRAP>​ |
 +| ''​remove'' ​                    ​| ​                                      |
 +
 +
 +{{anchor:​table}}==== Table Functions ====
 +
 +^ Function ^ Description and Example ^
 +| ''​tableGetRows(table)'' ​ | <​WRAP>​Gets a list of rows from a table object.
 +
 +The following example returns a list, such as ''​%%[[0,​1,​4,"​v"​],​[1,​3,​2,"​a"​],​[2,​2,​6,"​k"​]]%%''​.
 +
 +<code javascript>​tableGetRows(@parent.table);</​code></​WRAP>​|
 +| ''​tableGetColumns(table)''​ | <​WRAP>​Gets a list of information about columns in a table object. ​
 +
 +The following function returns a list, such as ''​[...{"​name":"​v1","​type":"​string","​width":​100,"​formula":​null,"​meta":​{"​name":"​v1"​}}...]''​.
 +
 +<code javascript>​tableGetColumns(@parent.table);</​code></​WRAP>​|
 +| ''​tableSet(table,​rows,​[columns],​ serialize=true)''​ | <​WRAP>​Sets data in the specified table. The ''​row''​ column is added automatically and contains automatically generated row IDs. 
 +
 +The following function erases all data in the table, adds two new rows, and adds the specified column headers. A ''​row''​ column is also automatically created.
 +
 +<code javascript>​tableSet(@parent.table,​[["​a","​b"​],​["​c","​d"​]],​["​col1","​col2"​]);</​code></​WRAP>​ |
 +| ''​tableAddRows(table,​ rows)''​ | <​WRAP>​Adds rows to a table object. A dummy value must be passed as the first item in any row. This dummy value will always be overriden by the automatically generated row ID in the ''​row''​ column.
 +
 +The following function adds two rows to the table.
 +
 +<code javascript>​tableAddRows(@parent.table,​[["","​a","​b"​],​["","​c","​d"​]]);</​code></​WRAP>​|
 +| ''​tableRemoveRows(table,​ start, [count=1])''​ | <​WRAP>​Removes a number of rows from table object. ​
 +
 +The following function removes two rows from a table, beginning with the row at index 0. 
 +
 +<code javascript>​tableRemoveRows(@parent.table,​ 0, 2);</​code></​WRAP>​|
 +| ''​tableClear(table)''​ | <​WRAP>​Clears the table.
 +
 +The following function removes all rows from a table. Columns remain.
 +
 +<code javascript>​tableClear(@parent.table);</​code></​WRAP>​ |
 +| ''​$thisRow['​column Name'​]''​ | <​WRAP>​Selects the column value from the current row being iterated on by a Filter or Column Mapping block. If the column name contains no spaces, the column name alone can be used in place of ''​$thisRow['​column Name'​]''​. For more examples, see [[dglux5_wiki:​dataflow:​dataflow_blocks_reference:​table_operations:​column_mapping|Column Mapping]] and [[dglux5_wiki:​dataflow:​dataflow_blocks_reference:​table_operations:​filter|Filter]].
 +
 +The following example demonstrates how to use ''​$thisRow'':​
 +
 +''​=$thisRow['​Energy Usage'​].indexOf("​History"​) > -1''​
 +
 +The new column contains a TRUE value in each row where the string "​History"​ appears in the Energy Usage column and a FALSE value in each row where the string "​History"​ does not appear.</​WRAP>​ |
 +
 +----
 +
 +===== Examples =====
 +This section contains some custom functions that can be used in script.
 +==== Lat-Long Operations ====
 +The following example contains some custom latitude and longitude functions.
 +<code javascript>​
 +function toRad(num) {return num * Math.PI / 180;}
 +function toDeg(num) {return num * 180 / Math.PI;}
 +
 +function calcDistance(lat1,​ lon1, lat2, lon2) {
 +  var R = 6371; // Radius of the earth in km
 +  var dLat = (lat2 - lat1) * Math.PI / 180;  // deg2rad below
 +  var dLon = (lon2 - lon1) * Math.PI / 180;
 +  var a = 
 +     0.5 - Math.cos(dLat)/​2 + 
 +     ​Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) * 
 +     (1 - Math.cos(dLon))/​2;​
 +
 +  return R * 2 * Math.asin(Math.sqrt(a));​
 +}
 +
 +function calcBearing (lat1,​lng1,​lat2,​lng2) ​
 +{
 +    var dLon = (lng2-lng1);​
 +    var y = Math.sin(dLon) * Math.cos(lat2);​
 +    var x = Math.cos(lat1)*Math.sin(lat2) - Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);​
 +    var brng = toDeg(Math.atan2(y,​ x));
 +    return 360 - ((brng + 360) % 360);
 +}
 +
 +function calcSpeed(lat1,​lon1,​lat2,​lon2,​time1,​time2)
 +{
 + var d = calcDistance(lat1,​lon1,​lat2,​lon2);​
 + var time = dateParse(time2)-dateParse(time1);​
 + return d/​(time/​1000/​60/​60);​
 +}
 +</​code>​
 +
 +
 +==== Custom Easing Functions ====
 +The following example contains some custom easing functions.
 +
 +<code javascript>​
 +easing =
 +{
 + // t: current time, b: begInnIng value, c: change In value, d: duration
 +
 + swing: function (t, b, c, d) {
 + return easing[easeOutQuad](t,​ b, c, d);
 + },
 + easeInQuad:​ function (t, b, c, d) {
 + return c*(t/=d)*t + b;
 + },
 + easeOutQuad:​ function (t, b, c, d) {
 + return -c *(t/​=d)*(t-2) + b;
 + },
 + easeInOutQuad:​ function (t, b, c, d) {
 + if ((t/=d/2) < 1) return c/2*t*t + b;
 + return -c/2 * ((--t)*(t-2) - 1) + b;
 + },
 + easeInCubic:​ function (t, b, c, d) {
 + return c*(t/​=d)*t*t + b;
 + },
 + easeOutCubic:​ function (t, b, c, d) {
 + return c*((t=t/​d-1)*t*t + 1) + b;
 + },
 + easeInOutCubic:​ function (t, b, c, d) {
 + if ((t/=d/2) < 1) return c/2*t*t*t + b;
 + return c/​2*((t-=2)*t*t + 2) + b;
 + },
 + easeInQuart:​ function (t, b, c, d) {
 + return c*(t/​=d)*t*t*t + b;
 + },
 + easeOutQuart:​ function (t, b, c, d) {
 + return -c * ((t=t/​d-1)*t*t*t - 1) + b;
 + },
 + easeInOutQuart:​ function (t, b, c, d) {
 + if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
 + return -c/2 * ((t-=2)*t*t*t - 2) + b;
 + },
 + easeInQuint:​ function (t, b, c, d) {
 + return c*(t/​=d)*t*t*t*t + b;
 + },
 + easeOutQuint:​ function (t, b, c, d) {
 + return c*((t=t/​d-1)*t*t*t*t + 1) + b;
 + },
 + easeInOutQuint:​ function (t, b, c, d) {
 + if ((t/=d/2) < 1) return c/​2*t*t*t*t*t + b;
 + return c/​2*((t-=2)*t*t*t*t + 2) + b;
 + },
 + easeInSine:​ function (t, b, c, d) {
 + return -c * Math.cos(t/​d * (Math.PI/​2)) + c + b;
 + },
 + easeOutSine:​ function (t, b, c, d) {
 + return c * Math.sin(t/​d * (Math.PI/​2)) + b;
 + },
 + easeInOutSine:​ function (t, b, c, d) {
 + return -c/2 * (Math.cos(Math.PI*t/​d) - 1) + b;
 + },
 + easeInExpo:​ function (t, b, c, d) {
 + return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
 + },
 + easeOutExpo:​ function (t, b, c, d) {
 + return (t==d) ? b+c : c * (-Math.pow(2,​ -10 * t/d) + 1) + b;
 + },
 + easeInOutExpo:​ function (t, b, c, d) {
 + if (t==0) return b;
 + if (t==d) return b+c;
 + if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
 + return c/2 * (-Math.pow(2,​ -10 * --t) + 2) + b;
 + },
 + easeInCirc:​ function (t, b, c, d) {
 + return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
 + },
 + easeOutCirc:​ function (t, b, c, d) {
 + return c * Math.sqrt(1 - (t=t/​d-1)*t) + b;
 + },
 + easeInOutCirc:​ function (t, b, c, d) {
 + if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
 + return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
 + },
 + easeInElastic:​ function (t, b, c, d) {
 + var s=1.70158;​var p=0;var a=c;
 + if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
 + if (a < Math.abs(c)) { a=c; var s=p/4; }
 + else var s = p/​(2*Math.PI) * Math.asin (c/a);
 + return -(a*Math.pow(2,​10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/​p )) + b;
 + },
 + easeOutElastic:​ function (t, b, c, d) {
 + var s=1.70158;​var p=0;var a=c;
 + if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
 + if (a < Math.abs(c)) { a=c; var s=p/4; }
 + else var s = p/​(2*Math.PI) * Math.asin (c/a);
 + return a*Math.pow(2,​-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/​p ) + c + b;
 + },
 + easeInOutElastic:​ function (t, b, c, d) {
 + var s=1.70158;​var p=0;var a=c;
 + if (t==0) return b;  if ((t/​=d/​2)==2) return b+c;  if (!p) p=d*(.3*1.5);​
 + if (a < Math.abs(c)) { a=c; var s=p/4; }
 + else var s = p/​(2*Math.PI) * Math.asin (c/a);
 + if (t < 1) return -.5*(a*Math.pow(2,​10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/​p )) + b;
 + return a*Math.pow(2,​-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/​p )*.5 + c + b;
 + },
 + easeInBack:​ function (t, b, c, d, s) {
 + if (s == undefined) s = 1.70158;
 + return c*(t/​=d)*t*((s+1)*t - s) + b;
 + },
 + easeOutBack:​ function (t, b, c, d, s) {
 + if (s == undefined) s = 1.70158;
 + return c*((t=t/​d-1)*t*((s+1)*t + s) + 1) + b;
 + },
 + easeInOutBack:​ function (t, b, c, d, s) {
 + if (s == undefined) s = 1.70158; ​
 + if ((t/=d/2) < 1) return c/​2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
 + return c/​2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
 + },
 + easeInBounce:​ function (t, b, c, d) {
 + return c - easing.easeOutBounce (d-t, 0, c, d) + b;
 + },
 + easeOutBounce:​ function (t, b, c, d) {
 + if ((t/=d) < (1/2.75)) {
 + return c*(7.5625*t*t) + b;
 + } else if (t < (2/2.75)) {
 + return c*(7.5625*(t-=(1.5/​2.75))*t + .75) + b;
 + } else if (t < (2.5/2.75)) {
 + return c*(7.5625*(t-=(2.25/​2.75))*t + .9375) + b;
 + } else {
 + return c*(7.5625*(t-=(2.625/​2.75))*t + .984375) + b;
 + }
 + },
 + easeInOutBounce:​ function (t, b, c, d) {
 + if (t < d/2) return easing.easeInBounce (t*2, 0, c, d) * .5 + b;
 + return easing.easeOutBounce (t*2-d, 0, c, d) * .5 + c*.5 + b;
 + }
 +};
 +return easing[@.a](0+@.b,​0,​1,​1,​0+@.e)*@.c+@.d;​
 +</​code>​
 +
 +----
 +<WRAP left>​[[dglux5_wiki:​dataflow:​dataflow_blocks_reference:​constants:​log10e|Previous:​ LOG10E]]</​WRAP>​
 +<WRAP right>​[[custom_javascript|Next:​ Custom JS Components]]</​WRAP>​