{"name":"upath","description":"A drop-in replacement / proxy to Node.js path, replacing \\\\ with / for all results & adding file extension functions.","version":"3.0.8","homepage":"https://github.com/anodynos/upath/","author":{"name":"Angelos Pikoulas","email":"agelos.pikoulas@gmail.com"},"license":"MIT","funding":[{"type":"github","url":"https://github.com/sponsors/anodynos"},{"type":"polar","url":"https://polar.sh/anodynos"},{"type":"tidelift","url":"https://tidelift.com/subscription/pkg/npm-upath"}],"keywords":["path","unix","windows","cross-platform","extension","file extension","replace extension","change extension","trim extension","add extension","default extension","UNC paths","typescript","esm","forward-slash"],"repository":{"type":"git","url":"git+https://github.com/anodynos/upath.git"},"bugs":{"url":"https://github.com/anodynos/upath/issues"},"type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"engines":{"node":">=20"},"scripts":{"dev":"npx tsup --watch","build":"npx tsup","test":"npx jest","test:coverage":"npx jest --coverage","lint":"npx eslint src","lint:types":"npx tsc --noEmit","prepublishOnly":"npm run build","test:integration":"npm run build && node test/integration/cjs-test.cjs && node test/integration/esm-test.mjs","prepare":"git config core.hooksPath .husky && chmod +x .husky/pre-commit 2>/dev/null || true","changeset":"changeset","version-packages":"changeset version","release":"npm run build && changeset publish","format":"prettier --write \"**/*.{ts,js,json}\""},"lint-staged":{"*.{ts,tsx,js,jsx,mjs,cjs,json,css,scss,yaml,yml,html}":"prettier --write"},"devDependencies":{"@changesets/cli":"^2.30.0","@eslint/js":"^10.0.1","@types/jest":"^29.5.0","@types/node":">=20.0.0","eslint":"^10.1.0","eslint-config-prettier":"^10.1.8","husky":"^9.1.7","jest":"^29.7.0","lint-staged":"^16.4.0","prettier":"^3.8.1","ts-jest":"^29.2.0","ts-node":"^10.9.2","tsup":"^8.0.0","typescript":"^5.5.0","typescript-eslint":"^8.58.0"},"gitHead":"ef9377ff82bb6d56904df6824a91be843f2ece2c","_id":"upath@3.0.8","_nodeVersion":"24.18.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-YAsrLMIlhfSCm9rga5TZsJ1mXgahs7N0qOTokzU8mFz35hUrYMvVkaEPefI3rEb/vkAWAOj1Km/qdije9RC1kQ==","shasum":"4c072fbbe04ef2d88d9ec1923457497bc46dc545","tarball":"http://registry-npm.ywwl.com/upath/download/upath-3.0.8.tgz","fileCount":10,"unpackedSize":67073,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/upath@3.0.8","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIF+mFl2a4Lq92eFabhzCphgYwNseV5Yv76BsmVlj8P50AiEAhdSZ+g/X5hFSURgQuvoUwDTpTly5qOREcjreaUoKxvw="}],"size":14726,"noattachment":false,"key":"/upath/-/upath-3.0.8.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:273ea1f6-7559-4a1d-8213-4c3194a726fa"}},"directories":{},"maintainers":[{"name":"anodynos","email":"agelos.pikoulas@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/upath_3.0.8_1783286731780_0.12699276435323137"},"_hasShrinkwrap":false,"readme":"# upath v3\n\n**The battle-tested path library that just works -- everywhere.**\n\n[![npm version](https://img.shields.io/npm/v/upath.svg)](https://www.npmjs.com/package/upath)\n[![npm downloads](https://img.shields.io/npm/dw/upath.svg)](https://www.npmjs.com/package/upath)\n[![CI](https://img.shields.io/github/actions/workflow/status/anodynos/upath/ci.yml?branch=master&label=CI)](https://github.com/anodynos/upath/actions/workflows/ci.yml)\n[![TypeScript](https://img.shields.io/badge/TypeScript-5.5+-blue.svg)](https://www.typescriptlang.org/)\n[![Node.js](https://img.shields.io/node/v/upath.svg)](https://nodejs.org/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)\n[![Zero Dependencies](https://img.shields.io/badge/dependencies-0-brightgreen.svg)](https://www.npmjs.com/package/upath)\n[![Bundle Size](https://img.shields.io/bundlephobia/minzip/upath)](https://bundlephobia.com/package/upath)\n[![GitHub Sponsors](https://img.shields.io/github/sponsors/anodynos?label=Sponsors)](https://github.com/sponsors/anodynos)\n\nA drop-in replacement for Node.js `path` that normalizes all backslashes to forward slashes, adds safe path manipulation and file extension utilities, and stays in sync with every Node.js release automatically.\n\nTrusted for over a decade. **20 million downloads per week.** Zero runtime dependencies. 100% tested against NodeJS's own path tests. One import and every path in your project is consistent -- no more `\\` vs `/` headaches across Windows, Linux, and macOS.\n\n```typescript\nimport upath from 'upath' // use exactly like path — but it always works\n```\n\n## The Problem\n\nNode.js `path` is platform-dependent. Run the same code on Windows and you get `\\` separators that break everything:\n\n```typescript\n// On Windows, path gives you this:\npath.normalize('c:\\\\windows\\\\..\\\\nodejs\\\\path') // 'c:\\\\nodejs\\\\path'    ← backslashes everywhere\npath.join('some/nodejs\\\\windows', '../path') // 'some/path'           ← WRONG result\npath.parse('c:\\\\Windows\\\\dir\\\\file.ext') // { dir: '', base: 'c:\\\\Windows\\\\dir\\\\file.ext' } ← BROKEN\n\n// upath gives you this — on ALL platforms:\nupath.normalize('c:\\\\windows\\\\..\\\\nodejs\\\\path') // 'c:/nodejs/path'      ✓\nupath.join('some/nodejs\\\\windows', '../path') // 'some/nodejs/path'    ✓\nupath.parse('c:\\\\Windows\\\\dir\\\\file.ext') // { dir: 'c:/Windows/dir', base: 'file.ext' }  ✓\n```\n\nThe irony? Windows works perfectly fine with forward slashes inside Node.js. The `\\` convention is purely cosmetic -- and it breaks everything downstream: path comparisons, URLs, template literals, config files, CI pipelines, globs.\n\n**upath fixes this.** It wraps every `path` function to normalize `\\` to `/` in all results. Same API, same behavior, zero surprises.\n\n## How It Works\n\nupath is a **thin dynamic proxy** over Node's built-in `path` module. Zero runtime dependencies -- its only import is `node:path` itself.\n\n1. At load time, iterates over every export of `path` via `Object.entries()`\n2. Functions get wrapped: string arguments are normalized on the way in, string results on the way out\n3. Non-function properties are copied as-is (except `sep`, which is forced to `'/'`)\n4. New `path` functions added in future Node versions are **automatically wrapped** -- no code changes needed\n\nThis means upath is always in sync with your Node.js version. It adds nothing, removes nothing -- just normalizes. Its test suite includes 421 tests, with test vectors extracted directly from [Node.js's own `path` test suite](https://github.com/nodejs/node/tree/main/test/parallel/) to verify identical behavior.\n\n## Installation\n\n```bash\nnpm install upath\n```\n\n## Usage\n\n```typescript\n// ESM\nimport upath from 'upath'\n// or import specific functions\nimport { normalize, joinSafe, addExt } from 'upath'\n\n// CJS\nconst upath = require('upath')\n```\n\n## API\n\nupath proxies **all** functions and properties from Node.js `path` (`basename`, `dirname`, `extname`, `format`, `isAbsolute`, `join`, `normalize`, `parse`, `relative`, `resolve`, `toNamespacedPath`, `matchesGlob`), converting any `\\` in results to `/`.\n\nAdditionally, `upath.sep` is always `'/'` and `upath.VERSION` provides the package version string.\n\n### Proxied functions -- `path` vs `upath`\n\nEvery `path` function works the same, but with `\\` → `/` normalization. Here's where it matters:\n\n#### `upath.normalize(path)`\n\n```\nupath.normalize('c:\\\\windows\\\\nodejs\\\\path')     ✓ 'c:/windows/nodejs/path'\n                                 path.normalize → 'c:\\\\windows\\\\nodejs\\\\path'\n\nupath.normalize('/windows\\\\unix/mixed')          ✓ '/windows/unix/mixed'\n                                 path.normalize → '/windows\\\\unix/mixed'\n\nupath.normalize('\\\\windows\\\\..\\\\unix/mixed/')    ✓ '/unix/mixed/'\n                                 path.normalize → '\\\\windows\\\\..\\\\unix/mixed/'\n```\n\n#### `upath.join(paths...)`\n\n```\nupath.join('some/nodejs\\\\windows', '../path')    ✓ 'some/nodejs/path'\n                                     path.join → 'some/path'              ← WRONG\n\nupath.join('some\\\\windows\\\\only', '..\\\\path')    ✓ 'some/windows/path'\n                                     path.join → 'some\\\\windows\\\\only/..\\\\path'  ← BROKEN\n```\n\n#### `upath.parse(path)`\n\n```\nupath.parse('c:\\\\Windows\\\\dir\\\\file.ext')\n  ✓ { root: '', dir: 'c:/Windows/dir', base: 'file.ext', ext: '.ext', name: 'file' }\n\npath.parse('c:\\\\Windows\\\\dir\\\\file.ext')\n  ✗ { root: '', dir: '', base: 'c:\\\\Windows\\\\dir\\\\file.ext', ext: '.ext', name: 'c:\\\\Windows\\\\dir\\\\file' }\n```\n\n### Extra functions\n\nThese solve real pain points that `path` ignores entirely. See [`docs/API.md`](docs/API.md) for full input/output tables.\n\n#### `upath.toUnix(path)`\n\nConverts all `\\` to `/` and consolidates duplicate slashes, without performing any normalization.\n\n```typescript\nupath.toUnix('.//windows\\\\//unix//mixed////') // './windows/unix/mixed/'\nupath.toUnix('\\\\\\\\server\\\\share') // '//server/share'\nupath.toUnix('C:\\\\Users\\\\test') // 'C:/Users/test'\n```\n\n#### `upath.normalizeSafe(path)`\n\n**The pain:** `path.normalize()` silently strips leading `./` from relative paths and `//` from UNC paths. Your `./src/index.ts` becomes `src/index.ts`, breaking ESM imports, webpack configs, and anything that depends on the explicit relative prefix.\n\n`normalizeSafe` normalizes the path but **preserves meaningful leading `./` and `//`**:\n\n```\nupath.normalizeSafe('./dep')                 ✓ './dep'\n                             path.normalize → 'dep'                      ← lost ./\n\nupath.normalizeSafe('./path/../dep')         ✓ './dep'\n                             path.normalize → 'dep'                      ← lost ./\n\nupath.normalizeSafe('//server/share/file')   ✓ '//server/share/file'\n                             path.normalize → '/server/share/file'       ← lost / (broken UNC)\n\nupath.normalizeSafe('//./c:/temp/file')      ✓ '//./c:/temp/file'\n                             path.normalize → '/c:/temp/file'            ← lost //. (broken UNC)\n```\n\n#### `upath.normalizeTrim(path)`\n\n**The pain:** Normalized paths often end with `/` -- which breaks string comparisons and some file-system APIs. `'./src/' !== './src'` even though they're the same directory.\n\nLike `normalizeSafe()`, but also trims any trailing `/`:\n\n```typescript\nupath.normalizeTrim('./../dep/') // '../dep'\nupath.normalizeTrim('.//windows\\\\unix/mixed/') // './windows/unix/mixed'\n```\n\n#### `upath.joinSafe([path1][, path2][, ...])`\n\n**The pain:** `path.join()` has the same `./` and `//` stripping problem as `path.normalize()`. Your `'./config'` becomes `'config'` after joining, silently breaking the relative import semantics you needed.\n\n`joinSafe` works like `path.join()` but preserves leading `./` and `//`:\n\n```\nupath.joinSafe('./some/local/unix/', '../path')   ✓ './some/local/path'\n                                      path.join → 'some/local/path'      ← lost ./\n\nupath.joinSafe('//server/share/file', '../path')  ✓ '//server/share/path'\n                                      path.join → '/server/share/path'   ← lost / (broken UNC)\n```\n\n#### `upath.addExt(filename, [ext])`\n\n**The pain:** `if (!file.endsWith('.js')) file += '.js'` scattered across your codebase -- and it still has the bug where `file.json` doesn't get `.js` appended but `file.cjs` does.\n\nAdds `.ext` to `filename`, but only if it doesn't already have the exact extension:\n\n```typescript\nupath.addExt('myfile', '.js') // 'myfile.js'\nupath.addExt('myfile.js', '.js') // 'myfile.js' (unchanged — already has it)\nupath.addExt('myfile.txt', '.js') // 'myfile.txt.js'\n```\n\n#### `upath.trimExt(filename, [ignoreExts], [maxSize=7])`\n\n**The pain:** `path` has no function to strip an extension while keeping the directory. `path.basename(f, ext)` loses the directory. And what counts as an \"extension\" when your file is `app.config.local.js`?\n\nTrims the extension from a filename. Extensions longer than `maxSize` chars (including the dot) are not considered valid. Extensions in `ignoreExts` are not trimmed:\n\n```typescript\nupath.trimExt('my/file.min.js') // 'my/file.min'\nupath.trimExt('my/file.min', ['min'], 8) // 'my/file.min' (.min ignored)\nupath.trimExt('../my/file.longExt') // '../my/file.longExt' (too long, not an ext)\n```\n\n#### `upath.removeExt(filename, ext)`\n\n**The pain:** `path.basename('file.json', '.js')` turns `'file.json'` into `'file.json'`? Actually no -- it turns `'file.js'` into `'file'` but it also corrupts `'file.json'` into... wait, it depends on the platform. Just use `removeExt`.\n\nRemoves the specific `ext` from `filename`, if present -- and *only* that exact extension:\n\n```typescript\nupath.removeExt('file.js', '.js') // 'file'\nupath.removeExt('file.txt', '.js') // 'file.txt' (unchanged — different ext)\n```\n\n#### `upath.changeExt(filename, [ext], [ignoreExts], [maxSize=7])`\n\n**The pain:** Changing `.coffee` to `.js` means trimming the old extension and adding the new one -- with edge cases around dotfiles, multi-segment extensions, and files with no extension at all. Every hand-rolled version of this has bugs.\n\nChanges a filename's extension to `ext`. If it has no valid extension, the new extension is added. Extensions in `ignoreExts` are not replaced:\n\n```typescript\nupath.changeExt('module.coffee', '.js') // 'module.js'\nupath.changeExt('my/module', '.js') // 'my/module.js'  (had no ext, adds it)\nupath.changeExt('file.min', '.js', ['min'], 8) // 'file.min.js'   (.min ignored)\n```\n\n#### `upath.defaultExt(filename, [ext], [ignoreExts], [maxSize=7])`\n\n**The pain:** You want to ensure a file has an extension, but only if it doesn't already have one. And you need control over what counts as \"already having one\" -- is `.min` an extension or part of the name?\n\nAdds `.ext` only if the filename doesn't already have any valid extension. Extensions in `ignoreExts` are treated as if absent:\n\n```typescript\nupath.defaultExt('file', '.js') // 'file.js'\nupath.defaultExt('file.ts', '.js') // 'file.ts' (already has extension)\nupath.defaultExt('file.min', '.js', ['min'], 8) // 'file.min.js' (.min ignored)\n```\n\n**Note:** In all extension functions, you can use both `.ext` and `ext` -- the leading dot is always handled correctly.\n\n## Who Uses upath\n\nupath is a foundational dependency in the Node.js ecosystem, trusted by **1,300+ packages** on npm including:\n\n- [**Chokidar**](https://github.com/paulmillr/chokidar) -- the file watcher behind Webpack, Vite, Rollup, and most dev servers\n- [**Nuxt**](https://github.com/nuxt/nuxt) -- the Vue.js framework (v2)\n- [**ansi-colors**](https://github.com/doowb/ansi-colors) -- terminal color styling\n- [**renovate**](https://github.com/renovatebot/renovate) -- automated dependency update tool\n- Countless Webpack plugins, build tools, and CLI frameworks\n\nIf you run `npm ls upath` in a non-trivial Node.js project, there's a good chance it's already there.\n\n## What's New in v3\n\n- **TypeScript rewrite** -- full type safety, source-of-truth types shipped with the package. Compatible with `@types/node` v20 through v25+.\n- **Dual CJS/ESM** -- works with `import` and `require()` out of the box via package.json `exports`.\n- **Node >= 20** -- drops legacy Node support.\n- **Auto-generated API docs** -- see [`docs/API.md`](docs/API.md) for complete input/output tables generated from the test suite.\n- **UNC path support** -- carried forward from v2, with comprehensive test coverage.\n\n## Migrating from v2\n\n- **Node >= 20 required** -- v2 supported Node >= 4. Update your CI matrix.\n- **CJS usage unchanged** -- `const upath = require('upath')` works as before. All functions are available directly on the module (no `.default` needed).\n- **TypeScript: stricter params** -- `join()`, `resolve()`, and `joinSafe()` params narrowed from `any[]` to `string[]`. Add explicit casts if you pass non-string args: `join(myVar as string)`.\n- **`_makeLong` removed** -- use `toNamespacedPath` instead (available since Node 8.3).\n- **Named ESM imports now available** -- `import { normalize, join, toUnix } from 'upath'` works in addition to the default import.\n- **Boxed `String` objects rejected** -- `new String('foo')` no longer accepted; use plain string primitives.\n\nSee [CHANGELOG.md](CHANGELOG.md) for the full list of changes.\n\n## Contributing\n\nContributions are welcome! Please open an issue or pull request on [GitHub](https://github.com/anodynos/upath).\n\n```bash\ngit clone https://github.com/anodynos/upath.git\ncd upath\nnpm install\nnpm test               # 421 tests\nnpm run test:integration  # CJS/ESM integration tests\n```\n\n## Sponsor\n\nupath has been free and MIT-licensed for over a decade. If it saves you time or your company depends on it, please consider sponsoring its continued maintenance:\n\n- [GitHub Sponsors](https://github.com/sponsors/anodynos) -- recurring or one-time\n- [Polar](https://polar.sh/anodynos) -- commercial-friendly, issue bounties\n- [Tidelift](https://tidelift.com/subscription/pkg/npm-upath) -- enterprise supply-chain support\n\nRunning `npm fund` in your project will also show you if upath is in your tree.\n\n## Security contact information\n\nTo report a security vulnerability, please use the\n[Tidelift security contact](https://tidelift.com/security).\nTidelift will coordinate the fix and disclosure.\n\n## License\n\n[MIT](LICENSE) -- Copyright (c) 2014-2026 [Angelos Pikoulas](https://github.com/anodynos)\n","publish_time":1783286731910,"_cnpm_publish_time":1783286731910,"dist-tags":{"latest":"3.0.8"}}