@oazmi/kitchensink - v0.9.13
    Preparing search index...

    Function replaceSuffix

    • replace the suffix of of a given input string with the given replace value. if a matching suffix is not found, then undefined will be returned.

      Parameters

      • input: string

        the input string to apply the suffix replacement to.

      • suffix: string

        the suffix string of the input to replace.

      • value: string = ""

        the optional value to replace the the suffix with. defaults to "" (empty string).

      Returns undefined | string

      if a matching suffix is found in the input, then it will be replaced with the given value. otherwise, undefined will be returned if the input does not begin with the suffix.

      import { assertEquals } from "jsr:@std/assert"

      // aliasing our function for brevity
      const
      eq = assertEquals,
      fn = replaceSuffix

      eq(fn("hello-world/abc-123", "-123", "-xyz"), "hello-world/abc-xyz")
      eq(fn("hello-world/abc-123", "-123"), "hello-world/abc")
      eq(fn("hello-world/abc-123", "abc"), undefined)
      eq(fn("hello-world/abc-123", ""), "hello-world/abc-123")
      eq(fn("hello-world/abc-123", "", "-xyz"), "hello-world/abc-123-xyz")