SL Functions and Properties

In this Page

sl.ensureArray

DescriptionTakes an argument and returns that argument unchanged if it is an array, otherwise it should return the argument in an array.
Syntax
sl.ensureArray(arg)
Example

Expression: sl.ensureArray([1,2,3])

Result: [1,2,3]


sl.gethostbyname

DescriptionReturns an array of IPv4 or IPv6 addresses for the given hostname or IP address.
Syntax
sl.gethostbyname(host)
Example

Expression: sl.gethostbyname("www.snaplogic.com")

Result:

[
      {
        "address": "54.214.241.155",
        "family": "ipv4",
        "hostname": "www.snaplogic.com"
      }
    ]

sl.range

Description

This function returns an array of numbers for the given range.  If given a single
numeric argument, it will return an array containing the numbers from zero up to the
given number. Like the Python range() function, you can supply:

  • a stopping point,
  • a stopping point and a starting point, or
  • a starting point, stopping point and a step
Syntax
sl.range(stop)
sl.range(start, stop)
sl.range(start, stop, step)
Example

Expression: sl.range(5)

Result:

[
      0,
      1,
      2,
      3,
      4
    ]


Expression: sl.range(1,6)

Result:

[
      1,
      2,
      3,
      4,
	  5	
    ]


Expression: sl.range(0,10,2)

Result:

[
      0,
      2,
      4,
      6,
      8
    ]

sl.zip

DescriptionThis function takes arrays of the same length and returns an array of tuples that contain the values from the input arrays at the same indexes. This works similar to the Python zip() function.
Syntax
sl.zip([array1], [array2],...)

You can also use field parameters if they contain arrays of the same length, such as sl.zip($Alpha,$Beta).

Example

Expression: sl.zip([1, 2, 3], ['a', 'b', 'c'])

Result:

[
      [
        1,
        "a"
      ],
      [
        2,
        "b"
      ],
      [
        3,
        "c"
      ]
    ]

sl.zipObject

DescriptionThis function returns an object composed from key-value pairs that accepts two arrays, the first with the properties and the second with values. This works similar to the Lodash zipObject function.
Syntax
sl.zipObject([props=[]], [values=[]])

You can also use field parameters if they contain arrays of the different lengths, but extra key values are set to null.

Examples

Expression: sl.zipObject([1, 2], ['a', 'b'])

Result:

{'1': 'a', '2': 'b'}

Expression: sl.zipObject ([1,2],['a'])

Result: 

{'1': 'a', '2': null}