Function insert

  • Negative indices count backwards from the beginning of the string.

    Remarks

    Non-integer or out of bounds indices return the string unchanged. If the index equals the length of the string, then the string will be appended to the end.

    Example

    import * as S from "flurp/string";

    const f = S.insert(2, "__");
    const g = S.insert(6, "__");
    const h = S.insert(-2, "__");
    f("weasel"); // "we__asel"
    g("weasel"); // "weasel__"
    h("weasel"); // "weas__el"

    Parameters

    • index: number
    • s: string

    Returns ((str: string) => string)

      • (str: string): string
      • Parameters

        • str: string

        Returns string