@pengzhanbo/utils - v3.5.0
    Preparing search index...

    Function template

    • String template interpolation

      字符串模板插值,支持 {{variable}} 形式的占位符

      Parameters

      • str: string

        The template string. 模板字符串

      • values: Record<string, unknown>

        An object containing values to interpolate. 包含要插值的值对象

      • options: { prefix?: string; suffix?: string } = {}

        Options. 选项

        • Optionalprefix?: string

          Prefix for placeholders. Default is '{{'. 占位符前缀,默认为 '{{'

        • Optionalsuffix?: string

          Suffix for placeholders. Default is '}}'. 占位符后缀,默认为 '}}'

      Returns string

      The interpolated string. 插值后的字符串

      template('Hello, {{name}}!', { name: 'World' }) // => 'Hello, World!'
      template('{{greeting}}, {{name}}', { greeting: 'Hi', name: 'there' }) // => 'Hi, there'
      template('{{a}} + {{b}} = {{c}}', { a: 1, b: 2, c: 3 }) // => '1 + 2 = 3'

      Custom prefix/suffix:

      template('<%name%>', { name: 'World' }, { prefix: '<%', suffix: '%>' }) // => 'World'