Pacote
    Preparing search index...

    Function interpolate

    • Creates a renderer that substitutes placeholders in a template with values provided at call time.

      The returned function accepts either an object keyed by placeholder names or an array of values, in which case placeholders are numeric indices. Only raw substitution is performed—no escaping, looping, or conditional logic.

      Parameters

      • template: string

        Template containing placeholders to replace.

      • pattern: string | RegExp = ...

        Pattern describing the placeholder delimiters. Defaults to /{{([\s\S]+?)}}/. May be a string or RegExp and must contain exactly one capture group for the placeholder key.

      Returns (data?: ReplaceMap<string | number | null | undefined>) => string

      Function that receives replacement data and yields the interpolated string.

      const render = interpolate('Hello, {{ name }}!')

      render({ name: 'world' }) // => 'Hello, world!'
      const render = interpolate('Hello, {{0}} and {{1}}!')

      render(['Alice', 'Bob']) // => 'Hello, Alice and Bob!'
      const render = interpolate('Hello, %{name}!', /%{([\s\S]+?)}/)

      render({ name: 'world' }) // => 'Hello, world!'