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

urlpattern-polyfill

Package Overview
Dependencies
Maintainers
3
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

urlpattern-polyfill

Polyfill for the URLPattern API

  • 10.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.9M
decreased by-12.44%
Maintainers
3
Weekly downloads
 
Created

What is urlpattern-polyfill?

The urlpattern-polyfill npm package provides a polyfill for the URLPattern API, which is a web standard for parsing and matching URLs against patterns. It is useful for routing in web applications, validating URLs, and extracting parts of URLs based on a predefined pattern.

What are urlpattern-polyfill's main functionalities?

Parsing and matching URLs

This feature allows you to define a URL pattern and then match URLs against it. If the URL matches, you can extract parts of it, such as path segments or query parameters.

const pattern = new URLPattern({ pathname: '/books/:id' });
const result = pattern.exec('/books/123');
console.log(result.pathname.groups.id); // '123'

Pattern matching with wildcards and modifiers

This feature enables the use of wildcards (*) and other modifiers to create flexible URL patterns that can match a variety of URL structures.

const pattern = new URLPattern({ pathname: '/books/*' });
const isMatch = pattern.test('/books/sci-fi');
console.log(isMatch); // true

Compatibility with the URLPattern API

The polyfill aims to be compatible with the URLPattern API, providing the same methods and properties that would be available in environments where the API is natively supported.

const pattern = new URLPattern('https://example.com/books/:id');
const isCompatible = 'exec' in pattern && 'test' in pattern;
console.log(isCompatible); // true

Other packages similar to urlpattern-polyfill

FAQs

Package last updated on 23 Jan 2024

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