The `resolve-pathname` package, currently at stable version 3.0.0, offers a pure JavaScript implementation for resolving URL pathnames. Its core purpose is to replicate the exact pathname resolution behavior found in web browsers when processing the `href` attribute of an `<a>` tag. This utility is distinct from Node.js's `url.resolve`, which handles full URLs, and from other browser-specific solutions like `resolve-url` that may have DOM dependencies. It prides itself on 100% compatibility with browser pathname resolution rules without relying on a DOM environment. The package is typically very stable with an infrequent release cadence for major versions, indicating a mature and well-tested codebase. It is suitable for both Node.js and browser environments, with ESM, CommonJS, and UMD builds available.
npm install resolve-pathnameVerified import paths — ran on the pinned version, not inferred.
Demonstrates various pathname resolution scenarios, including relative and absolute paths, handling of base paths, and browser-like behavior with trailing slashes.
If you need to resolve full URLs, consider `url.resolve` in Node.js or `new URL(relative, base).href` in modern browser/Node.js environments.
Always explicitly provide the `from` argument if the resolution should be relative to a specific path other than the root `/`.
Be mindful of trailing slashes in your base path; ensure consistency based on whether the base represents a directory or a file path.
Ensure you are using `import` statements for ES Modules and `require()` for CommonJS modules. If transpiling, configure your build system correctly to handle module interoperability.
For ES Modules, use `import resolvePathname from 'resolve-pathname';`. For CommonJS, use `const resolvePathname = require('resolve-pathname');`.Always provide the `from` argument, e.g., `resolvePathname('my-path', '/base');` or `resolvePathname('my-path', window.location.pathname);`.No dependency data recorded yet.