path-parser is a small utility library designed for parsing, matching, and generating URL paths. It allows developers to define path patterns with various parameter types (URL, matrix, splat, query) and apply regular expression constraints. It supports full and partial path matching, returning extracted parameters, and robust path building. The current stable version is 6.1.0, as indicated by the package.json and npm badge. While a specific release cadence isn't explicitly documented, the package appears actively maintained given its versioning and features. Its key differentiators include comprehensive parameter definition, robust constraint enforcement during path building, and flexible matching options (case-sensitive, strict trailing slash, delimited partial matching), making it a foundational tool for routing libraries like `route-node`. The library ships with TypeScript types, enhancing development experience for TypeScript users.
npm install path-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates defining paths with parameters and constraints, performing full and partial matching, and building paths while handling constraint violations.
Review the new `urlParamsEncoding` options ('default', 'uriComponent', 'uri', 'none') and explicitly set the desired behavior during `Path` instantiation or test/build calls. If absolute backward compatibility is needed (not recommended), use `urlParamsEncoding: 'legacy'`.Ensure parameters passed to `.build()` conform to their regex constraints, or set the `ignoreConstraints: true` option in the build method options to bypass validation (use with caution).
Place `*splat` parameters at the end of your path definition or ensure subsequent segments are clearly distinguishable if partial matching is intended and further segments need to be matched later.
Set `'caseSensitive: true'` and/or `'strictTrailingSlash: true'` in the options object for `.test()` or `.partialTest()` if stricter matching behavior is required for your routes.
Provide a value that matches the parameter's constraint (e.g., a number for `<\\d+>`), or pass `{ ignoreConstraints: true }` as an option to the `.build()` method to bypass validation.For ESM, use `import { Path } from 'path-parser';`. For CommonJS, use `const { Path } = require('path-parser');`. Alternatively, use the static factory method: `const path = Path.create('/your/path');`.No dependency data recorded yet.