### Installation Source: https://github.com/anodynos/upath/blob/master/readme.md Install the upath package using npm. ```bash npm install upath ``` -------------------------------- ### upath.defaultExt examples Source: https://github.com/anodynos/upath/blob/master/readme.md Examples showing how to ensure a filename has a default extension using upath.defaultExt, with cases for adding extensions, keeping existing ones, and ignoring specific extensions. ```typescript upath.defaultExt('file', '.js') // 'file.js' upath.defaultExt('file.ts', '.js') // 'file.ts' (already has extension) upath.defaultExt('file.min', '.js', ['min'], 8) // 'file.min.js' (.min ignored) ``` -------------------------------- ### upath.toUnix Examples Source: https://github.com/anodynos/upath/blob/master/docs/API.md Demonstrates the conversion of various path formats to Unix-style paths using upath.toUnix. ```javascript upath.toUnix(".//windows\\//unix/\\/mixed////") ``` ```javascript upath.toUnix("..///windows\\..\\\\unix/mixed") ``` ```javascript upath.toUnix("") ``` ```javascript upath.toUnix("/") ``` ```javascript upath.toUnix("\\\\server\\share") ``` ```javascript upath.toUnix("already/forward/slashes") ``` ```javascript upath.toUnix("\\") ``` ```javascript upath.toUnix("////multiple///slashes") ``` ```javascript upath.toUnix("mixed\\back//and///slashes") ``` ```javascript upath.toUnix("a\\b\\c") ``` ```javascript upath.toUnix("C:\\Users\\test") ``` -------------------------------- ### upath.changeExt examples Source: https://github.com/anodynos/upath/blob/master/readme.md Examples demonstrating how to change a filename's extension using upath.changeExt, including cases with existing extensions, no extensions, and ignored extensions. ```typescript upath.changeExt('module.coffee', '.js') // 'module.js' upath.changeExt('my/module', '.js') // 'my/module.js' (had no ext, adds it) upath.changeExt('file.min', '.js', ['min'], 8) // 'file.min.js' (.min ignored) ``` -------------------------------- ### Contributing commands Source: https://github.com/anodynos/upath/blob/master/readme.md Commands to clone the upath repository, install dependencies, and run tests. ```bash git clone https://github.com/anodynos/upath.git cd upath npm install npm test # 421 tests npm run test:integration # CJS/ESM integration tests ``` -------------------------------- ### upath.join Examples Source: https://github.com/anodynos/upath/blob/master/docs/API.md Shows examples of how upath.join concatenates path segments. ```javascript upath.join(["some/nodejs/deep","../path"]) ``` ```javascript upath.join(["some/nodejs\\windows","../path"]) ``` ```javascript upath.join(["some\\windows\\only","..\\path"]) ``` -------------------------------- ### upath.joinSafe Examples Source: https://github.com/anodynos/upath/blob/master/docs/API.md Demonstrates how upath.joinSafe handles various path inputs, including mixed slashes and relative paths. ```javascript upath.joinSafe(["some/nodejs/deep","../path"]) ``` ```javascript upath.joinSafe(["./some/local/unix/","../path"]) ``` ```javascript upath.joinSafe(["./some\\current\\mixed","..\\path"]) ``` ```javascript upath.joinSafe(["../some/relative/destination","..\\path"]) ``` ```javascript upath.joinSafe(["\\\\server\\share\\file","..\\path"]) ``` ```javascript upath.joinSafe(["\\\\.\\c:\\temp\\file","..\\path"]) ``` ```javascript upath.joinSafe(["//server/share/file","../path"]) ``` ```javascript upath.joinSafe(["//./c:/temp/file","../path"]) ``` ```javascript upath.joinSafe(["",""]) ``` ```javascript upath.joinSafe(["./foo","","bar"]) ``` -------------------------------- ### upath.normalize Examples Source: https://github.com/anodynos/upath/blob/master/docs/API.md Illustrates the behavior of upath.normalize with different path formats, including Windows and Unix style. ```javascript upath.normalize("c:/windows/nodejs/path") ``` ```javascript upath.normalize("c:/windows/../nodejs/path") ``` ```javascript upath.normalize("c:\\windows\\nodejs\\path") ``` ```javascript upath.normalize("c:\\windows\\..\\nodejs\\path") ``` ```javascript upath.normalize("/windows\\unix/mixed") ``` ```javascript upath.normalize("\\windows//unix/mixed") ``` ```javascript upath.normalize("\\windows\\..\\unix/mixed/") ``` -------------------------------- ### upath.isAbsolute Examples (backslash normalization) Source: https://github.com/anodynos/upath/blob/master/docs/API.md Shows how upath.isAbsolute determines if a path is absolute, considering backslash normalization. ```javascript upath.isAbsolute("\\foo") ``` ```javascript upath.isAbsolute("\\\\server\\share") ``` ```javascript upath.isAbsolute("foo\\bar") ``` -------------------------------- ### upath.join Source: https://github.com/anodynos/upath/blob/master/readme.md Demonstrates how upath.join correctly handles mixed path separators and relative paths, unlike path.join. ```javascript upath.join('some/nodejs\\windows', '../path') ✓ 'some/nodejs/path' path.join → 'some/path' ← WRONG upath.join('some\\windows\\only', '..\\path') ✓ 'some/windows/path' path.join → 'some\\windows\\only/..\\path' ← BROKEN ``` -------------------------------- ### Import upath Source: https://github.com/anodynos/upath/blob/master/readme.md Use exactly like path — but it always works ```typescript import upath from 'upath' // use exactly like path — but it always works ``` -------------------------------- ### upath.parse Source: https://github.com/anodynos/upath/blob/master/readme.md Shows how upath.parse correctly parses Windows-style paths, unlike path.parse. ```javascript upath.parse('c:\\Windows\\dir\\file.ext') ✓ { root: '', dir: 'c:/Windows/dir', base: 'file.ext', ext: '.ext', name: 'file' } path.parse('c:\\Windows\\dir\\file.ext') ✗ { root: '', dir: '', base: 'c:\\Windows\\dir\\file.ext', ext: '.ext', name: 'c:\\Windows\\dir\\file' } ``` -------------------------------- ### upath.joinSafe Source: https://github.com/anodynos/upath/blob/master/readme.md Joins paths while preserving leading './' and '//'. ```javascript upath.joinSafe('./some/local/unix/', '../path') ✓ './some/local/path' path.join → 'some/local/path' ← lost ./ upath.joinSafe('//server/share/file', '../path') ✓ '//server/share/path' path.join → '/server/share/path' ← lost / (broken UNC) ``` -------------------------------- ### Problem: path vs upath on Windows Source: https://github.com/anodynos/upath/blob/master/readme.md Demonstrates how Node.js path behaves differently on Windows compared to upath, which normalizes paths to use forward slashes. ```typescript // On Windows, path gives you this: path.normalize('c:\windows\..\nodejs\path') // 'c:\nodejs\path' ← backslashes everywhere path.join('some/nodejs\windows', '../path') // 'some/path' ← WRONG result path.parse('c:\Windows\dir\file.ext') // { dir: '', base: 'c:\Windows\dir\file.ext' } ← BROKEN // upath gives you this — on ALL platforms: upath.normalize('c:\windows\..\nodejs\path') // 'c:/nodejs/path' ✓ upath.join('some/nodejs\windows', '../path') // 'some/nodejs/path' ✓ upath.parse('c:\Windows\dir\file.ext') // { dir: 'c:/Windows/dir', base: 'file.ext' } ✓ ``` -------------------------------- ### upath.toUnix Source: https://github.com/anodynos/upath/blob/master/readme.md Converts Windows-style paths to Unix-style paths. ```typescript upath.toUnix('.//windows\\//unix//mixed////') // './windows/unix/mixed/' upath.toUnix('\\server\share') // '//server/share' upath.toUnix('C:\\Users\\test') // 'C:/Users/test' ``` -------------------------------- ### upath.addExt Source: https://github.com/anodynos/upath/blob/master/readme.md Adds a file extension if it's missing. ```typescript upath.addExt('myfile', '.js') // 'myfile.js' upath.addExt('myfile.js', '.js') // 'myfile.js' (unchanged — already has it) upath.addExt('myfile.txt', '.js') // 'myfile.txt.js' ``` -------------------------------- ### Proxied functions -- path vs upath Source: https://github.com/anodynos/upath/blob/master/readme.md Illustrates the difference in path normalization between Node.js path and upath for various scenarios. ```typescript upath.normalize('c:\windows\nodejs\path') ✓ 'c:/windows/nodejs/path' path.normalize → 'c:\windows\nodejs\path' upath.normalize('/windows\unix/mixed') ✓ '/windows/unix/mixed' path.normalize → '/windows\unix/mixed' upath.normalize('\windows\..\unix/mixed/') ✓ '/unix/mixed/' path.normalize → '\windows\..\unix/mixed/' ``` -------------------------------- ### Usage Source: https://github.com/anodynos/upath/blob/master/readme.md Import upath in your project using either ESM or CJS syntax. ```typescript // ESM import upath from 'upath' // or import specific functions import { normalize, joinSafe, addExt } from 'upath' // CJS const upath = require('upath') ``` -------------------------------- ### upath.normalizeSafe Source: https://github.com/anodynos/upath/blob/master/readme.md Normalizes paths while preserving meaningful leading './' and '//'. ```javascript upath.normalizeSafe('./dep') ✓ './dep' path.normalize → 'dep' ← lost ./ upath.normalizeSafe('./path/../dep') ✓ './dep' path.normalize → 'dep' ← lost ./ upath.normalizeSafe('//server/share/file') ✓ '//server/share/file' path.normalize → '/server/share/file' ← lost / (broken UNC) upath.normalizeSafe('//./c:/temp/file') ✓ '//./c:/temp/file' path.normalize → '/c:/temp/file' ← lost //. (broken UNC) ``` -------------------------------- ### upath.normalizeTrim Source: https://github.com/anodynos/upath/blob/master/readme.md Normalizes paths and trims trailing slashes. ```typescript upath.normalizeTrim('./../dep/') // '../dep' upath.normalizeTrim('.//windows\unix/mixed/') // './windows/unix/mixed' ``` -------------------------------- ### upath.trimExt Source: https://github.com/anodynos/upath/blob/master/readme.md Trims the extension from a filename, with options for ignored extensions and maximum extension length. ```javascript upath.trimExt('my/file.min.js') // 'my/file.min' upath.trimExt('my/file.min', ['min'], 8) // 'my/file.min' (.min ignored) upath.trimExt('../my/file.longExt') // '../my/file.longExt' (too long, not an ext) ``` -------------------------------- ### upath.removeExt Source: https://github.com/anodynos/upath/blob/master/readme.md Removes a specific extension from a filename. ```javascript upath.removeExt('file.js', '.js') // 'file' upath.removeExt('file.txt', '.js') // 'file.txt' (unchanged — different ext) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.