{"library":"resolve-pathname","title":"URL Pathname Resolver","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install resolve-pathname"],"cli":null},"imports":["import resolvePathname from 'resolve-pathname';","const resolvePathname = require('resolve-pathname');","window.resolvePathname;"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import resolvePathname from 'resolve-pathname';\n\n// Example 1: Resolving a relative path from a specific base path.\nconst resolved1 = resolvePathname('about', '/company/jobs');\nconsole.log(`'/company/jobs' + 'about' -> ${resolved1}`); // Expected: /company/about\n\n// Example 2: Resolving a parent path from a nested base path.\nconst resolved2 = resolvePathname('../jobs', '/company/team/ceo');\nconsole.log(`'/company/team/ceo' + '../jobs' -> ${resolved2}`); // Expected: /company/jobs\n\n// Example 3: Resolving a path when no base path is provided (defaults to '/').\nconst resolved3 = resolvePathname('about');\nconsole.log(`'/' + 'about' -> ${resolved3}`); // Expected: /about\n\n// Example 4: Resolving an absolute path (base path is ignored).\nconst resolved4 = resolvePathname('/about');\nconsole.log(`'/company/info/some-path' + '/about' -> ${resolved4}`); // Expected: /about\n\n// Example 5: Index paths (trailing slash on base) are supported, similar to browsers.\nconst resolved5 = resolvePathname('new-page', '/company/info/');\nconsole.log(`'/company/info/' + 'new-page' -> ${resolved5}`); // Expected: /company/info/new-page\n\n// Simulating browser environment with window.location.pathname\n// Assume window.location.pathname is '/company/team/ceo'\nconst mockLocationPathname = '/company/team/ceo';\nconst resolvedBrowser1 = resolvePathname('cto', mockLocationPathname);\nconsole.log(`'${mockLocationPathname}' + 'cto' -> ${resolvedBrowser1}`); // Expected: /company/team/cto\n\nconst resolvedBrowser2 = resolvePathname('../jobs', mockLocationPathname);\nconsole.log(`'${mockLocationPathname}' + '../jobs' -> ${resolvedBrowser2}`); // Expected: /company/jobs","lang":"javascript","description":"Demonstrates various pathname resolution scenarios, including relative and absolute paths, handling of base paths, and browser-like behavior with trailing slashes.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}