Function asyncArrayTemplate

  • Async equivalent of arrayTemplate. The async template tag ('T' by default) is applied to the template string. Use this when there are promises among the arguents that will be passed to the returned function.

    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.

    • tagName: string

      Supply a tagName argument to change the name of the tag function inside the template string if the default name (T) is present in argNames.

    Returns ArrayTemplate

    Example

    let t = asyncArrayTemplate('I will async render this ${item}')([1, 2, 3, 4, 5].map(i => Promise.resolve(i)));
    console.log(t instanceof Promise); // true
    t = await t
    // t === 'I will async render this 1I will async render this 2I will async render this 3I will async render this 4I will async render this 5'