Function templates

  • 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 because only 1 rendering function is called.

    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' Defaults to the empty string.

    Returns ITemplates

    Example

    import { templates } from 'deleight/apriori';
    const t = arrayTemplate('I will render this ${it}/${other} immediately!!!', ['other'], 'it')([1, 2, 3, 4, 5], '(shared)').join(' & ');
    // 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!!!'