Socket
Socket
Sign inDemoInstall

url-value-parser

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

url-value-parser

extracts and replaces values and IDs in URLs


Version published
Weekly downloads
376K
decreased by-9.41%
Maintainers
1
Weekly downloads
 
Created

What is url-value-parser?

The url-value-parser npm package is designed to parse URLs and extract meaningful values from them. It is particularly useful for extracting parameters, paths, and other components from URLs in a structured manner.

What are url-value-parser's main functionalities?

Parse URL and extract values

This feature allows you to parse a URL and extract dynamic values from it. In the example, the URL '/user/12345/profile' is parsed to extract the user ID '12345' and replace it with a placeholder ':id'.

const UrlValueParser = require('url-value-parser');
const parser = new UrlValueParser();
const result = parser.parse('/user/12345/profile');
console.log(result); // { path: '/user/:id/profile', params: { id: '12345' } }

Custom parameter patterns

This feature allows you to define custom patterns for parameters. In the example, a custom pattern for MongoDB ObjectIDs is used to parse the URL and extract the product ID.

const UrlValueParser = require('url-value-parser');
const parser = new UrlValueParser({ parameterPattern: /[a-f0-9]{24}/i });
const result = parser.parse('/product/5f8d0d55b54764421b7156c3');
console.log(result); // { path: '/product/:id', params: { id: '5f8d0d55b54764421b7156c3' } }

Parse query strings

This feature allows you to parse URLs with query strings and extract the query parameters. In the example, the URL '/search?q=nodejs&sort=asc' is parsed to extract the query parameters 'q' and 'sort'.

const UrlValueParser = require('url-value-parser');
const parser = new UrlValueParser();
const result = parser.parse('/search?q=nodejs&sort=asc');
console.log(result); // { path: '/search', query: { q: 'nodejs', sort: 'asc' } }

Other packages similar to url-value-parser

Keywords

FAQs

Package last updated on 02 Sep 2022

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