trim the trailing forward-slashes at the end of a string, except for those that are preceded by a dotslash ("/./") or a dotdotslash ("/../")
import { assertEquals } from "jsr:@std/assert"// aliasing our functions for brevityconst eq = assertEquals, fn = trimEndSlasheseq(fn("///a/b.zip///"), "///a/b.zip")eq(fn("///a/b.zip/.///"), "///a/b.zip/./")eq(fn("///a/b.zip/..///"), "///a/b.zip/../")eq(fn("///a/b.zip/...///"), "///a/b.zip/...")eq(fn("///a/b.zip/wut.///"), "///a/b.zip/wut.")eq(fn("///a/b.zip/wut..///"), "///a/b.zip/wut..")eq(fn("///a/b.zip/wut...///"), "///a/b.zip/wut...")eq(fn(".///../a/b.zip/"), ".///../a/b.zip")eq(fn("file:///a/b.zip//c.txt"), "file:///a/b.zip//c.txt") Copy
import { assertEquals } from "jsr:@std/assert"// aliasing our functions for brevityconst eq = assertEquals, fn = trimEndSlasheseq(fn("///a/b.zip///"), "///a/b.zip")eq(fn("///a/b.zip/.///"), "///a/b.zip/./")eq(fn("///a/b.zip/..///"), "///a/b.zip/../")eq(fn("///a/b.zip/...///"), "///a/b.zip/...")eq(fn("///a/b.zip/wut.///"), "///a/b.zip/wut.")eq(fn("///a/b.zip/wut..///"), "///a/b.zip/wut..")eq(fn("///a/b.zip/wut...///"), "///a/b.zip/wut...")eq(fn(".///../a/b.zip/"), ".///../a/b.zip")eq(fn("file:///a/b.zip//c.txt"), "file:///a/b.zip//c.txt")
trim the trailing forward-slashes at the end of a string, except for those that are preceded by a dotslash ("/./") or a dotdotslash ("/../")
Example