Function template

  • Effectively creates a template literal out of an existing template string and wraps it in a function which can be called multiple times to 'render' the template with the given arguments.

    Parameters

    • templateStr: string

      the template string

    • Optional argNames: string[]

      The names of the parameters of the returned function (which can be 'seen' inside the template string). Defaults to: ['arg'].

    Returns ((...args) => string)

      • (...args): string
      • Parameters

        • Rest ...args: any[]

        Returns string

    Example

    import { template } from 'deleight/apriori';
    const t = template('I will render this ${"guy"} immediately!!!')();
    // t === 'I will render this guy immediately!!!'