Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
path-parser
Advanced tools
A small library to parse and build paths. It can be used to partially or fully test paths against a defined pattern.
Partial testing allows to determine if a given path starts with the defined pattern. It is used by route-node
import Path from 'path-parser'
// or
const Path = require('path-parser').default
const path = new Path('/users/:id')
// Matching
path.test('/users/00123')
// {
// id: "00123"
// }
// Partial testing: does the provided path
// starts with the defined pattern?
path.partialTest('/users/00123/orders')
// {
// id: "00123"
// }
path.partialTest('/profile/00123/orders')
// null
// Building
path.build({ id: '00123' })
// => "/users/00123"
Without new
:
const path = Path.createPath('/users/: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.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/:id<d+>')
path.build({ id: 'not-a-number' }) // => Will throw an error
path.build({ id: '123' }) // => '/users/123'
Test if the provided path matches the defined path template. Options available are:
'caseSensitive'
: whether matching should be case sensitive or not (default to false
)'strictTrailingSlash'
: whether or not it should strictly match trailing slashes (default to false
)'queryParams'
: options for query parametersTest if the provided path is partially matched (starts with) the defined path template. Options available are:
'caseSensitive'
: whether matching should be case sensitive or not (default to false
)'delimited'
: whether or not a partial match should only be successful if it reaches a delimiter (/
, ?
, .
and ;
). Default to true
.'queryParams'
: options for query parametersBuilds the defined path template with the provided parameters
'ignoreConstraints'
: whether or not to ignore parameter constraints (default to false
)'ignoreSearch'
: whether or not to build query parameters (default to false
)'caseSensitive'
: whether matching should be case sensitive or not (default to false
)'queryParams'
: options for query parametersFAQs
A small utility to parse, match and generate paths
The npm package path-parser receives a total of 89,522 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
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.