Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wordpress/url

Package Overview
Dependencies
Maintainers
0
Versions
184
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/url

WordPress URL utilities.

  • 4.15.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
122K
increased by116.1%
Maintainers
0
Weekly downloads
 
Created

What is @wordpress/url?

@wordpress/url is a utility library for manipulating and parsing URLs in JavaScript. It provides a set of functions to handle URL strings, making it easier to work with URLs in web development, especially within the context of WordPress projects.

What are @wordpress/url's main functionalities?

Parsing URLs

The parse function allows you to break down a URL into its components, such as protocol, hostname, pathname, and query string. This is useful for analyzing or modifying specific parts of a URL.

const { parse } = require('@wordpress/url');
const url = 'https://example.com/path?query=123';
const parsedUrl = parse(url);
console.log(parsedUrl);

Building URLs

The build function allows you to construct a URL from its components. This is useful when you need to dynamically generate URLs based on certain parameters.

const { build } = require('@wordpress/url');
const urlComponents = {
  protocol: 'https',
  hostname: 'example.com',
  pathname: '/path',
  query: { query: '123' }
};
const url = build(urlComponents);
console.log(url);

Modifying Query Parameters

The addQueryArgs function lets you add or modify query parameters in a URL. This is particularly useful for updating URLs with new query parameters without manually string manipulation.

const { addQueryArgs } = require('@wordpress/url');
const url = 'https://example.com/path';
const newUrl = addQueryArgs(url, { query: '123', another: '456' });
console.log(newUrl);

Removing Query Parameters

The removeQueryArgs function allows you to remove specific query parameters from a URL. This is helpful when you need to clean up URLs by removing unnecessary parameters.

const { removeQueryArgs } = require('@wordpress/url');
const url = 'https://example.com/path?query=123&another=456';
const newUrl = removeQueryArgs(url, 'query');
console.log(newUrl);

Other packages similar to @wordpress/url

Keywords

FAQs

Package last updated on 03 Jan 2025

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc