upath API

April 9, 2026 · View on GitHub

Auto-generated from test results by doc-reporter.ts. Do not edit manually.

Note: Node.js compatibility tests (200+ vectors in node-compat.test.ts) are excluded from this document for brevity. Those tests verify that every proxied path function produces identical results to Node.js built-in path.

upath.addExt(filename, ext)

addExt(filename, 'js')

InputOutput
"myfile/addExt", 'js'"myfile/addExt.js"
"myfile/addExt.txt", 'js'"myfile/addExt.txt.js"
"myfile/addExt.js", 'js'"myfile/addExt.js"
"myfile/addExt.min.", 'js'"myfile/addExt.min..js"

addExt(filename) — no ext param

InputOutput
"myfile/addExt"unchanged
"myfile/addExt.txt"unchanged
"myfile/addExt.js"unchanged
"myfile/addExt.min."unchanged

upath.trimExt(filename, ignoreExts?, maxSize?)

trimExt(filename) — defaults

InputOutput
"my/trimedExt.txt""my/trimedExt"
"my/trimedExt""my/trimedExt"
"my/trimedExt.min""my/trimedExt"
"my/trimedExt.min.js""my/trimedExt.min"
"../my/trimedExt.longExt""../my/trimedExt.longExt"

trimExt(filename, ['min', '.dev'], 8)

InputOutput
"my/trimedExt.txt", ['min', '.dev'], 8"my/trimedExt"
"my/trimedExt.min", ['min', '.dev'], 8"my/trimedExt.min"
"my/trimedExt.dev", ['min', '.dev'], 8"my/trimedExt.dev"
"../my/trimedExt.longExt", ['min', '.dev'], 8"../my/trimedExt"
"../my/trimedExt.longRExt", ['min', '.dev'], 8"../my/trimedExt.longRExt"

upath.removeExt(filename, ext)

removeExt(filename, '.js')

InputOutput
"removedExt.js", '.js'"removedExt"
"removedExt.txt.js", '.js'"removedExt.txt"
"notRemoved.txt", '.js'"notRemoved.txt"

removeExt(filename, '.longExt')

InputOutput
"removedExt.longExt", '.longExt'"removedExt"
"removedExt.txt.longExt", '.longExt'"removedExt.txt"
"notRemoved.txt", '.longExt'"notRemoved.txt"

upath.changeExt(filename, ext?, ignoreExts?, maxSize?)

changeExt(filename, '.js')

InputOutput
"my/module.min", '.js'"my/module.js"
"my/module.coffee", '.js'"my/module.js"
"my/module", '.js'"my/module.js"
"file/withDot.", '.js'"file/withDot.js"
"file/change.longExt", '.js'"file/change.longExt.js"

changeExt(filename) — trims extension

InputOutput
"my/module.min""my/module"
"my/module.coffee""my/module"
"my/module""my/module"
"file/withDot.""file/withDot"
"file/change.longExt""file/change.longExt"

changeExt(filename, 'js', ['min', '.dev'], 8)

InputOutput
"my/module.coffee", 'js', ['min', 'dev'], 8"my/module.js"
"file/notValidExt.min", 'js', ['min', 'dev'], 8"file/notValidExt.min.js"
"file/notValidExt.dev", 'js', ['min', 'dev'], 8"file/notValidExt.dev.js"
"file/change.longExt", 'js', ['min', 'dev'], 8"file/change.js"
"file/change.longRExt", 'js', ['min', 'dev'], 8"file/change.longRExt.js"

upath.defaultExt(filename, ext?, ignoreExts?, maxSize?)

defaultExt(filename, 'js')

InputOutput
"fileWith/defaultExt", 'js'"fileWith/defaultExt.js"
"fileWith/defaultExt.js", 'js'"fileWith/defaultExt.js"
"fileWith/defaultExt.min", 'js'"fileWith/defaultExt.min"
"fileWith/defaultExt.longExt", 'js'"fileWith/defaultExt.longExt.js"

defaultExt(filename) — no ext param

InputOutput
"fileWith/defaultExt"unchanged
"fileWith/defaultExt.js"unchanged
"fileWith/defaultExt.min"unchanged
"fileWith/defaultExt.longExt"unchanged

defaultExt(filename, 'js', ['min', '.dev'], 8)

InputOutput
"fileWith/defaultExt", 'js', ['min', '.dev'], 8"fileWith/defaultExt.js"
"fileWith/defaultExt.min", 'js', ['min', '.dev'], 8"fileWith/defaultExt.min.js"
"fileWith/defaultExt.dev", 'js', ['min', '.dev'], 8"fileWith/defaultExt.dev.js"
"fileWith/defaultExt.longExt", 'js', ['min', '.dev'], 8"fileWith/defaultExt.longExt"
"fileWith/defaultExt.longRext", 'js', ['min', '.dev'], 8"fileWith/defaultExt.longRext.js"

upath.normalizeSafe(path)

equal to path.normalize

InputOutput
"""."
".""."
"./""./"
".//""./"
".\\""./"
".\\//""./"
"./.."".."
".//.."".."
"./../""../"
".\\..\\""../"
"./../dep""../dep"
"../dep""../dep"
"../path/dep""../path/dep"
"../path/../dep""../dep"
"dep""dep"
"path//dep""path/dep"

different to path.normalize (preserves leading ./ and //)

InputOutput
"./dep""./dep"
"./path/dep""./path/dep"
"./path/../dep""./dep"
".//windows\\unix/mixed/""./windows/unix/mixed/"
"..//windows\\unix/mixed""../windows/unix/mixed"
"windows\\unix/mixed/""windows/unix/mixed/"
"..//windows\\..\\unix/mixed""../unix/mixed"

UNC paths

InputOutput
"\\\\server\\share\\file""//server/share/file"
"//server/share/file""//server/share/file"
"\\\\?\\UNC\\server\\share\\file""//?/UNC/server/share/file"
"\\\\LOCALHOST\\c$\\temp\\file""//LOCALHOST/c$/temp/file"
"\\\\?\\c:\\temp\\file""//?/c:/temp/file"
"\\\\.\\c:\\temp\\file""//./c:/temp/file"
"//./c:/temp/file""//./c:/temp/file"
"////\\.\\c:/temp\\//file""//./c:/temp/file"

upath.normalizeTrim(path)

InputOutput
"./""."
"./../"".."
"./../dep/""../dep"
"path//dep\\""path/dep"
".//windows\\unix/mixed/""./windows/unix/mixed"
"/""/"
"//""/"

upath.joinSafe(path1, path2, ...)

InputOutput
["some/nodejs/deep","../path"]"some/nodejs/path"
["./some/local/unix/","../path"]"./some/local/path"
["./some\\current\\mixed","..\\path"]"./some/current/path"
["../some/relative/destination","..\\path"]"../some/relative/path"
["\\\\server\\share\\file","..\\path"]"//server/share/path"
["\\\\.\\c:\\temp\\file","..\\path"]"//./c:/temp/path"
["//server/share/file","../path"]"//server/share/path"
["//./c:/temp/file","../path"]"//./c:/temp/path"
["",""]"."
["./foo","","bar"]"./foo/bar"

upath.normalize(path)

InputOutput
"c:/windows/nodejs/path""c:/windows/nodejs/path"
"c:/windows/../nodejs/path""c:/nodejs/path"
"c:\\windows\\nodejs\\path""c:/windows/nodejs/path"
"c:\\windows\\..\\nodejs\\path""c:/nodejs/path"
"/windows\\unix/mixed""/windows/unix/mixed"
"\\windows//unix/mixed""/windows/unix/mixed"
"\\windows\\..\\unix/mixed/""/unix/mixed/"

upath.join(paths...)

InputOutput
["some/nodejs/deep","../path"]"some/nodejs/path"
["some/nodejs\\windows","../path"]"some/nodejs/path"
["some\\windows\\only","..\\path"]"some/windows/path"

upath.toUnix(path)

InputOutput
".//windows\\//unix/\\/mixed////""./windows/unix/mixed/"
"..///windows\\..\\\\unix/mixed""../windows/../unix/mixed"
""""
"/""/"
"\\\\server\\share""//server/share"
"already/forward/slashes""already/forward/slashes"
"\\""/"
"////multiple///slashes""//multiple/slashes"
"mixed\\back//and///slashes""mixed/back/and/slashes"
"a\\b\\c""a/b/c"
"C:\\Users\\test""C:/Users/test"

upath.isAbsolute(path) — backslash normalization

InputOutput
"\\foo"true (backslash normalized)
"\\\\server\\share"true (backslash normalized)
"foo\\bar"false (backslash normalized)