normalize a path by reducing and removing redundant dot-slash ("./" and "../") path navigators from a path.
if you provide the optional config with the keepRelative set to false, then in the output, there will no be leading dot-slashes ("./").
read more about the option here: NormalizePathConfig.keepRelative.
but note that irrespective of what you set this option to be, leading leading dotdot-slashes ("../") and leading slashes ("/") will not be trimmed.
even though config should be of NormalizePathConfig type, it also accepts number so that the function's signature becomes compatible with the Array.prototype.map method,
however, unless you pass the correct config object type, only the default action will be taken.
[!warning]
you MUST provide a posix path (i.e. use "/" for dir-separator).
there will not be any implicit conversion of windows "\" dir-separator.
Example
import { assertEquals } from"jsr:@std/assert"
// aliasing our functions for brevity consteq = assertEquals, fn = normalizePosixPath // aliasing the config for disabling the preservation of leading "./" constremove_rel: NormalizePathConfig = { keepRelative:false }
normalize a path by reducing and removing redundant dot-slash ("./" and "../") path navigators from a path.
if you provide the optional
config
with thekeepRelative
set tofalse
, then in the output, there will no be leading dot-slashes ("./"). read more about the option here: NormalizePathConfig.keepRelative. but note that irrespective of what you set this option to be, leading leading dotdot-slashes ("../") and leading slashes ("/") will not be trimmed.even though
config
should be of NormalizePathConfig type, it also acceptsnumber
so that the function's signature becomes compatible with theArray.prototype.map
method, however, unless you pass the correct config object type, only the default action will be taken.Example