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

    Function commonPathTransform

    • replace the common path among all provided paths by transforming it with a custom map_fn function. all paths are initially normalized and converted into posix-style (so that no "\" windows separator is prevelent).

      the map_fn function's first argument (path_info), is a 2-tuple of the form [common_dir: string, subpath: string], where common_dir represents the directory common to all of the input paths, and the subpath represents the remaining relative path that comes after common_dir.

      • the common_dir always ends with a trailing slash ("/"), unless there is absolutely no common directory among the paths at all.
      • the subpath never begins with any slash (nor any dot-slashes), unless of course, you had initially provided a path containing two or more consecutive slashes.

      Type Parameters

      • T = string
      • PathInfo extends [common_dir: string, subpath: string] = [common_dir: string, subpath: string]

      Parameters

      • paths: string[]
      • map_fn: (path_info: PathInfo, index: number, path_infos: PathInfo[]) => T

      Returns T[]

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

      // aliasing our functions for brevity
      const eq = assertEquals, fn = commonPathTransform

      const subpath_map_fn = ([common_dir, subpath]: [string, string]) => (subpath)

      eq(fn([
      "C:/Hello/World/This/Is/An/Example/Bla.cs",
      "C:\\Hello\\World\\This\\Is\\Not/An/Example/",
      "C:/Hello/Earth/Bla/Bla/Bla",
      ], subpath_map_fn), [
      "World/This/Is/An/Example/Bla.cs",
      "World/This/Is/Not/An/Example/",
      "Earth/Bla/Bla/Bla",
      ])

      eq(fn([
      "./../././home/Hello/World/This/Used/to-be-an/example/../../../Is/An/Example/Bla.cs",
      "./././../home/Hello/World/This/Is/an/example/bla.cs",
      "./../home/Hello/World/This/Is/Not/An/Example/",
      ], subpath_map_fn), [
      "An/Example/Bla.cs",
      "an/example/bla.cs",
      "Not/An/Example/",
      ])

      eq(fn([
      "/C:/Hello///World/Users/This/Is/An/Example/Bla.cs",
      "/C:\\Hello\\World Users\\This\\Is/An\\example/bla.cs",
      "/C:/./.\\.\\././Hello/World-Users/./././././This/Is/Not/An/Example/",
      ], subpath_map_fn), [
      "//World/Users/This/Is/An/Example/Bla.cs",
      "World Users/This/Is/An/example/bla.cs",
      "World-Users/This/Is/Not/An/Example/",
      ])