{"library":"path-parser","title":"Path Parser","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install path-parser"],"cli":null},"imports":["import { Path } from 'path-parser'","const { Path } = require('path-parser')","import { Path } from 'path-parser'; const p = Path.create('/foo')"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { Path } from 'path-parser';\n\n// Define a path with a URL parameter and a regex constraint\nconst userPath = new Path('/users/:id<\\\\d+>/profile');\n\nconsole.log('--- Matching Examples ---');\n// Full match\nlet matchResult = userPath.test('/users/12345/profile');\nconsole.log('Full match for /users/12345/profile:', matchResult);\n// Expected: { id: \"12345\" }\n\n// Full match - no match due to constraint\nmatchResult = userPath.test('/users/abcde/profile');\nconsole.log('Full match for /users/abcde/profile:', matchResult);\n// Expected: null\n\n// Partial matching\nlet partialMatchResult = userPath.partialTest('/users/67890/profile/settings');\nconsole.log('Partial match for /users/67890/profile/settings:', partialMatchResult);\n// Expected: { id: \"67890\" }\n\npartialMatchResult = userPath.partialTest('/products/123');\nconsole.log('Partial match for /products/123:', partialMatchResult);\n// Expected: null\n\nconsole.log('\\n--- Building Examples ---');\n// Building a path\nlet builtPath = userPath.build({ id: '54321' });\nconsole.log('Building path with id 54321:', builtPath);\n// Expected: \"/users/54321/profile\"\n\n// Building a path - with constraint violation (will throw an error)\ntry {\n  userPath.build({ id: 'not-a-number' });\n} catch (e) {\n  console.log('Building path with invalid id (expected error):', e.message);\n  // Expected: \"Parameter 'id' with value 'not-a-number' does not match constraint <\\\\d+>\"\n}\n\n// Another path definition with query parameters\nconst productPath = new Path('/products/:category?:page&:sort');\nconsole.log('\\n--- Product Path Examples ---');\nconsole.log('Building product path:', productPath.build({ category: 'electronics', page: 2, sort: 'price' }));\n// Expected: \"/products/electronics?page=2&sort=price\"\nconsole.log('Matching product path:', productPath.test('/products/books?page=1&sort=title'));\n// Expected: { category: \"books\", page: \"1\", sort: \"title\" }","lang":"javascript","description":"Demonstrates defining paths with parameters and constraints, performing full and partial matching, and building paths while handling constraint violations.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}