
Product
Rust Support in Socket Is Now Generally Available
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.
Modify URL instances cleanly and safely. Works in any environment that supports the URL API.
url-modifyModify URL instances cleanly and safely. Works in any environment that supports the URL API.
yarn add url-modify
# Or if you are using NPM:
# npm install --save url-modify
urlModify(modifications: UrlModifyModifications, base: string | URL, options?: UrlModifyOptions): URL
UrlModifyModifications{
hash?: string;
host?: string;
password?: string;
path?: string;
port?: string;
protocol?: string;
search?: string | string[][] | Record<string, string> | URLSearchParams;
username?: string;
}
UrlModifyOptions{
pathBehavior?: 'append' | 'prepend' | 'replace';
searchBehavior?: 'append' | 'clear' | 'replace';
}
pathBehaviorappend
Appends modifications.path to the base URL path. Note that the base URL path is not tampered with; it may or may not end in a trailing slash depending how you provided it.
prepend
Prepend modifications.path to the base URL path. Note that the leading slash from the base URL path is removed, so you may need to ensure modifications.path ends with a slash.
replace (default)
Replace the base URL path with modifications.path.
searchBehaviorappend
If a search key provided in modifications.search already exists in the base URL then retain it and append the values provided in modifications.search to the search string.
clear
Clear all search params provided in the base URL before appending the values provided in modifications.search to the search string.
replace (default)
If a search key provided in modifications.search already exists in the base URL then remove it before appending the values provided in modifications.search to the search string.
import { urlModify } from 'url-modify';
// Or if you are using CommonJS:
// const { urlModify } = require('url-modify');
const base = new URL('https://foo.example?foo=bar');
console.log(urlModify({ protocol: 'wss' }, base).toString())
// "wss://foo.example/?foo=bar"
console.log(urlModify({ search: { foo: 'bar2' } }, base).toString())
// "https://foo.example/?foo=bar2"
console.log(urlModify({ search: { foo: 'bar2' } }, base, { searchBehavior: 'append' }).toString())
// "https://foo.example/?foo=bar&foo=bar2"
console.log(urlModify({ search: [ [ 'foo', 'bar2' ], [ 'foo', 'bar3' ] ] }, base, { searchBehavior: 'append' }).toString())
// "https://foo.example/?foo=bar&foo=bar2&foo=bar3"
console.log(urlModify({ search: [ [ 'foo', 'bar2' ], [ 'foo', 'bar3' ] ] }, base, { searchBehavior: 'replace' }).toString())
// "https://foo.example/?foo=bar2&foo=bar3"
console.log(urlModify({ search: { abc: '123' } }, base).toString())
// "https://foo.example/?foo=bar&abc=123"
console.log(urlModify({ search: { abc: '123' } }, base, { searchBehavior: 'clear' }).toString())
// "https://foo.example/?abc=123"
While the URL API simplifies creating URL strings, it's difficult to cleanly mutate URL instances without creating excessive variables and/or risk modifying the original URL instance.
Until the spec allows you to do something like...
const base = new URL('http://foo.example');
new URL({ protocol: 'https' }, base);
...or...
const base = new URL('http://foo.example');
new URL({ ...base, protocol: 'https' });
...then this package is a helpful workaround.
FAQs
Modify URL instances cleanly and safely. Works in any environment that supports the URL API.
The npm package url-modify receives a total of 16 weekly downloads. As such, url-modify popularity was classified as not popular.
We found that url-modify 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.

Product
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.

Security News
Chrome 144 introduces the Temporal API, a modern approach to date and time handling designed to fix long-standing issues with JavaScript’s Date object.

Research
Five coordinated Chrome extensions enable session hijacking and block security controls across enterprise HR and ERP platforms.