Function replace

  • Replaces the first instance of a string or regular expression.

    Remarks

    Implemented with the built-in String.replace(), which allows for additional features documented at MDN (e.g., special patterns in the replacement strings).

    Example

    import * as S from "flurp/string";

    const underscoreForE = S.replace("e", "_");
    const vowelToUpper = S.replace(/[aeiou]/, S.toUpperCase);
    underscoreForE("weasel"); // "w_asel"
    vowelToUpper("weasel"); // "wEasel"

    Parameters

    • target: string | RegExp

      (if RegExp, must include the global flag)

    • replacement: string | ((s: string, ...args: unknown[]) => string)

    Returns ((s: string) => string)

      • (s: string): string
      • Parameters

        • s: string

        Returns string