Function arrayTemplate

  • Similar to template, but will render an iterable (such as array) of items together instead of rendering each item individually. It improves efficiency in these scenarios.

    Parameters

    • templateStr: string

      The template string

    • argNames: string[]

      The names of the parameters (after the iterable) of the returned function (which can be 'seen' inside the template string)

    • itemName: string

      The name of the current item of the iterable as seen inside the template string. Defaults to 'item'

    • itemSep: string

      The text that goes between the rendered items. Defaults to the empty string.

    Returns ArrayTemplate

    Example

    const t = arrayTemplate('I will render this ${it}/${other} immediately!!!', ['other'], 'it', ' & ')([1, 2, 3, 4, 5], '(shared)');
    // t === 'I will render this 1/(shared) immediately!!! & I will render this 2/(shared) immediately!!! & I will render this 3/(shared) immediately!!! & I will render this 4/(shared) immediately!!! & I will render this 5/(shared) immediately!!!'