Function asyncTemplates

  • 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'

    • 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 IAsyncTemplates

    Example

    import { asyncTemplates } from 'deleight/apriori';
    let t = asyncTemplates('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).join(' ')
    // t === 'I will async render this 1 I will async render this 2 I will async render this 3 I will async render this 4 I will async render this 5'