Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
path-parser
Advanced tools
A small utility to parse and build paths. It can be used to partially or fully match paths against a defined pattern.
Partial match allows to determine if a given path starts with the defined pattern. It is used by route-node
import Path from 'path-parser';
// Defining a new path
const p = new Path('/users/profile/:id');
// Matching
p.match('/users/profile/00123') // => {id: "00123"}
// Partial matching: does this path
// starts with that pattern?
p.partialMatch('/users/profile/00123/orders') // => {id: "00123"}
p.partialMatch('/profile/00123/orders') // => null
// Building
p.build({id: '00123'}) // => "users/profile/00123"
Without new
:
import Path from 'path-parser';
const p = Path.createPath('/users/profile/:id');
:param
: for URL parameters;param
: for matrix parameters*splat
: for parameters spanning over multiple segments. Handle with care?param1¶m2
or ?:param1&:param2
: for query parameters. Colons :
are optional.?param1=a¶m1=b
will result in {param1: ['a', 'b']}
?param1[]=a
and ?param1[]=a¶m1[]=b
will result respectively in {param1: ['a']}
and {param1: ['a', 'b']}
For URL parameters and matrix parameters, you can add a constraint in the form of a regular expression. Note that back slashes have to be escaped.
:param<\\d+>
will match numbers only for parameter param
;id<[a-fA-F0-9]{8}
will match 8 characters hexadecimal strings for parameter id
Constraints are also applied when building paths, unless specified otherwise (set option flag ignoreConstraints
to true).
// Path.build(params, opts)
var Path = new Path('/users/profile/:id<\d+>');
path.build({id: 'not-a-number'}); // => Will throw an error
path.build({id: 'not-a-number'}, {ignoreConstraints: true}); // => '/users/profile/not-a-number'
When using .match()
or .partialMatch()
, you can path a second argument. If truthy, it will make trailing slashes optional.
var path = new Path('/my-path');
path.match('/my-path/') // => null
path.match('/my-path/', true) // => {}
FAQs
A small utility to parse, match and generate paths
The npm package path-parser receives a total of 57,767 weekly downloads. As such, path-parser popularity was classified as popular.
We found that path-parser 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.