platform-bible-utils
    Preparing search index...

    Function formatReplacementString

    • Replaces each {key} in str with replacers[key], coerces every part to a string, and joins them. An unknown key is replaced by the key text itself, and empty braces {} drop out leaving the surrounding text. See formatReplacementStringToArray to keep non-string replacers intact — a React element coerced through this function becomes [object Object].

      Parameters

      • str: string

        String containing {key} placeholders

      • replacers: object | { [key: string | number]: unknown }

        Object whose keys are placeholder names and whose values are the replacements

      Returns string

      The formatted string

      An unknown key (food) is left as its own text rather than raising.

      formatReplacementString(
      'Hi, this is {name}! I like \\{curly braces\\}. I have a {carColor} car. Food: {food}.',
      { name: 'Bill', carColor: 'blue' },
      );
      // 'Hi, this is Bill! I like {curly braces}. I have a blue car. Food: food.'