@supuwoerc/toolkit
    Preparing search index...

    Function ensurePrefix

    • 确保字符串以指定前缀开始;若未以该前缀开始则添加之。

      Ensure a string starts with the specified prefix; if not, prepend it.

      Parameters

      • prefix: string

        要确保的前缀 / prefix to ensure

      • str: string

        待处理的字符串 / input string

      Returns string

      如果 str 已以 prefix 开头则返回原字符串,否则返回加上前缀后的新字符串 / original string if it already starts with prefix, otherwise the string with prefix prepended

      // ensurePrefix('pre-', 'fix') -> 'pre-fix'