Provides functional transformations for arrays within HotMesh mapping rules. Although inspired by JavaScript, these methods have been adapted to follow a functional approach. Each transformation is a function that expects one or more input parameters from the prior row in the @pipe structure.

Invoked via {@array.<method>} in YAML mapping rules.

Constructors

Methods

  • Concatenates two arrays and returns a new array containing the elements of both.

    Parameters

    • array1: any[]

      The first array

    • array2: any[]

      The second array to concatenate

    Returns any[]

    A new array containing elements from both input arrays

    concatenated_colors:
    "@pipe":
    - ["{a.output.data.colors1}", "{a.output.data.colors2}"]
    - ["{@array.concat}"]
  • Retrieves an element from an array by its index.

    Parameters

    • array: any[]

      The array from which to retrieve the element

    • index: number

      The zero-based index of the element to retrieve

    Returns any

    The element at the specified index, or undefined if the array is nullish

    second_color:
    "@pipe":
    - ["{a.output.data.colors}", 1]
    - ["{@array.get}"]
  • Returns the first index at which a given element can be found in the array, or -1 if the element is not present.

    Parameters

    • array: any[]

      The array to search

    • searchElement: any

      The element to locate in the array

    • OptionalfromIndex: number

      The index to start the search from

    Returns number

    The first index of the element, or -1 if not found

    green_index:
    "@pipe":
    - ["{a.output.data.colors}", "green"]
    - ["{@array.indexOf}"]
  • Joins all elements of an array into a string, using a specified delimiter between each element.

    Parameters

    • array: any[]

      The array whose elements are to be joined

    • separator: string

      The string used to separate each element

    Returns string

    A string with all array elements joined by the separator

    sentence:
    "@pipe":
    - ["{a.output.data.words}", " "]
    - ["{@array.join}"]
  • Returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards.

    Parameters

    • array: any[]

      The array to search

    • searchElement: any

      The element to locate in the array

    • OptionalfromIndex: number

      The index at which to start searching backwards

    Returns number

    The last index of the element, or -1 if not found

    last_green_index:
    "@pipe":
    - ["{a.output.data.colors}", "green"]
    - ["{@array.lastIndexOf}"]
  • Returns the number of elements in an array.

    Parameters

    • array: any[]

      The array whose length is to be determined

    Returns any

    The number of elements in the array

    num_colors:
    "@pipe":
    - ["{a.output.data.colors}"]
    - ["{@array.length}"]
  • Removes the last element from an array and returns that element.

    Parameters

    • array: any[]

      The array from which to remove the last element

    Returns any

    The removed element, or undefined if the array is empty

    last_color:
    "@pipe":
    - ["{a.output.data.colors}"]
    - ["{@array.pop}"]
  • Adds one or more elements to the end of an array and returns the modified array.

    Parameters

    • array: any[]

      The array to add elements to

    • Rest...items: any[]

      The elements to add to the end of the array

    Returns any[]

    The modified array with the new elements appended

    updated_colors:
    "@pipe":
    - ["{a.output.data.colors}", "yellow"]
    - ["{@array.push}"]
  • Reverses the order of the elements in an array in place and returns the reversed array.

    Parameters

    • array: any[]

      The array to reverse

    Returns any[]

    The reversed array

    reversed_numbers:
    "@pipe":
    - ["{a.output.data.numbers}"]
    - ["{@array.reverse}"]
  • Removes the first element from an array and returns that element.

    Parameters

    • array: any[]

      The array from which to remove the first element

    Returns any

    The removed element, or undefined if the array is empty

    first_color:
    "@pipe":
    - ["{a.output.data.colors}"]
    - ["{@array.shift}"]
  • Returns a shallow copy of a portion of an array selected from the start index up to, but not including, the end index.

    Parameters

    • array: any[]

      The array to slice

    • Optionalstart: number

      The beginning index of the slice (inclusive)

    • Optionalend: number

      The end index of the slice (exclusive); if omitted, slices to the end

    Returns any[]

    A new array containing the extracted elements

    numbers_slice:
    "@pipe":
    - ["{a.output.data.numbers}", 1, 3]
    - ["{@array.slice}"]
  • Sorts the elements of an array in place and returns the sorted array. Supports ascending (default) and descending sort orders. Handles null/undefined values and uses locale-aware comparison for strings.

    Parameters

    • array: any[]

      The array to sort

    • Optionalorder: "ASCENDING" | "DESCENDING" = 'ASCENDING'

      The sort order

    Returns any[]

    The sorted array

    sorted_numbers:
    "@pipe":
    - ["{a.output.data.numbers}"]
    - ["{@array.sort}"]
  • Changes the contents of an array by removing or replacing existing elements and/or adding new elements in place. Returns the array of removed elements.

    Parameters

    • array: any[]

      The array to modify

    • start: number

      The index at which to start changing the array

    • OptionaldeleteCount: number

      The number of elements to remove

    • Rest...items: any[]

      The elements to add at the start position

    Returns any[]

    An array containing the removed elements

    modified_colors:
    "@pipe":
    - ["{a.output.data.colors}", 1, 2, "orange"]
    - ["{@array.splice}"]
  • Adds one or more elements to the beginning of an array and returns the new length of the array.

    Parameters

    • array: any[]

      The array to add elements to

    • Rest...items: any[]

      The elements to add to the front of the array

    Returns number

    The new length of the array

    updated_colors:
    "@pipe":
    - ["{a.output.data.colors}", "yellow"]
    - ["{@array.unshift}"]