
Product
Introducing Webhook Events for Pull Request Scans
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
path-to-from-params
Advanced tools
Friendlier wrapper for path-to-regexp that converts paths to/from plain objects.
Convert a path, e.g. places/france/paris/
, that matches a pattern with Express-style placeholders, e.g. 'places/:country/:city'
to/from an array of parameters, e.g. {country:'france',city:'paris'}
A a friendlier/easier wrapper for path-to-regexp. Built regexes are internally cached for performance and everything is fully unit tested with Jest.
npm install path-to-from-params
const { pathToParams } = require('path-to-from-params');
const params = pathToParams('places/:country/:city', 'places/france/paris');
console.log(params); // {country:'france',city:'paris'}
const { pathFromParams } = require('path-to-from-params');
const path = pathFromParams('places/:country/:city', {country:'france',city:'paris'});
console.log(path); // 'places/france/paris'
const { pathToParams } = require('path-to-from-params');
const params = pathToParams('places/:country/:city?', 'places/brazil');
console.log(params); // {country:'france',city:undefined}
const { pathFromParams } = require('path-to-from-params');
const path = pathFromParams('places/:country/:city?', {country:'brazil'});
console.log(path); // 'places/brazil'
pathToParams(pattern, path)
Convert a path to a plain object of parameters. Returns an array any parameters named in the pattern that were found in the path, e.g. {country:'china',city:'shanghai'}
pattern
(string)
The pattern for the path, e.g. 'places/:country/:city?'
path
(string)
The path itself, e.g. 'places/china/shanghai'
pathFromParams(pattern, params)
Build a path from a pattern and an array of parameters. Returns the path string that was built, e.g. 'places/china/shanghai'
pattern
(string)
The pattern for the path, e.g. 'places/:country/:city?'
params
(object)
The object containing the parameters, e.g. {country:'china',city:'shanghai'}
FAQs
Friendlier wrapper for path-to-regexp that converts paths to/from plain objects.
The npm package path-to-from-params receives a total of 9 weekly downloads. As such, path-to-from-params popularity was classified as not popular.
We found that path-to-from-params 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
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
Research
The Socket Threat Research Team uncovered malicious NuGet packages typosquatting the popular Nethereum project to steal wallet keys.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.