Tweakr
    Preparing search index...

    Function interpolate

    • Interpolates placeholders in a string with values from a given object.

      Placeholders are in the format {key}. If the key exists in vars, it will be replaced with the corresponding value. Otherwise, the placeholder remains unchanged.

      Parameters

      • str: string

        The string containing placeholders.

      • vars: Record<string, any>

        An object mapping keys to values for interpolation.

      Returns string

      The interpolated string.

      1.1.0

      interpolate("Hello, {name}!", { name: "Alice" }); // "Hello, Alice!"
      interpolate("Age: {age}", { }); // "Age: {age}"