Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
resolve-pathname
Advanced tools
The resolve-pathname npm package is a utility for resolving target URLs or file paths relative to a base URL or file path. It is particularly useful in web development for handling relative paths and ensuring that URLs are correctly formed.
Resolve Relative Path
This feature allows you to resolve a relative path against a base path. In this example, 'bar' is resolved relative to '/foo', resulting in '/foo/bar'.
const resolvePathname = require('resolve-pathname');
const resolvedPath = resolvePathname('bar', '/foo');
console.log(resolvedPath); // Output: '/foo/bar'
Resolve Path with Parent Directory
This feature handles paths that navigate up the directory tree. Here, '../bar' is resolved relative to '/foo/baz', resulting in '/bar'.
const resolvePathname = require('resolve-pathname');
const resolvedPath = resolvePathname('../bar', '/foo/baz');
console.log(resolvedPath); // Output: '/bar'
Resolve Absolute Path
This feature ensures that absolute paths are correctly resolved. In this case, '/bar' remains '/bar' regardless of the base path '/foo'.
const resolvePathname = require('resolve-pathname');
const resolvedPath = resolvePathname('/bar', '/foo');
console.log(resolvedPath); // Output: '/bar'
The 'path' module is a core Node.js module that provides utilities for working with file and directory paths. It offers similar functionalities such as resolving paths, joining paths, and normalizing paths. Unlike resolve-pathname, it is built into Node.js and does not need to be installed separately.
The 'url' module is another core Node.js module that provides utilities for URL resolution and parsing. It can be used to resolve relative URLs against base URLs, similar to resolve-pathname. However, it is more focused on URL manipulation rather than file paths.
The 'resolve-url' package is a lightweight utility for resolving relative URLs against base URLs. It is similar to resolve-pathname but is specifically designed for URL resolution rather than file paths.
resolve-pathname resolves URL pathnames identical to the way browsers resolve the pathname of an <a href>
value. The goals are:
Using npm:
$ npm install --save resolve-pathname
Then, use as you would anything else:
// using an ES6 transpiler, like babel
import resolvePathname from 'resolve-pathname'
// not using an ES6 transpiler
var resolvePathname = require('resolve-pathname').resolvePathname
The UMD build is also available on npmcdn:
<script src="https://npmcdn.com/resolve-pathname/umd/resolvePathname.min.js"></script>
You can find the library on window.resolvePathname
.
import resolvePathname from 'resolve-pathname'
// Simply pass the pathname you'd like to resolve. Second
// argument is the path we're coming from, or the current
// pathname. It defaults to "/".
resolvePathname('about', '/company/jobs') // /company/about
resolvePathname('../jobs', '/company/team/ceo') // /company/jobs
resolvePathname('about') // /about
resolvePathname('/about') // /about
// Index paths (with a trailing slash) are also supported and
// work the same way as browsers.
resolvePathname('about', '/company/info/') // /company/info/about
// In browsers, it's easy to resolve a URL pathname relative to
// the current page. Just use window.location! e.g. if
// window.location.pathname == '/company/team/ceo' then
resolvePathname('cto', window.location.pathname) // /company/team/cto
resolvePathname('../jobs', window.location.pathname) // /company/jobs
FAQs
Resolve URL pathnames using JavaScript
The npm package resolve-pathname receives a total of 3,604,696 weekly downloads. As such, resolve-pathname popularity was classified as popular.
We found that resolve-pathname demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.