JSPM

  • Created
  • Published
  • Downloads 86637
  • Score
    100M100P100Q147182F
  • License ISC

A small utility to parse paths

Package Exports

  • path-parser

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (path-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Build Status

path-parser

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

Usage

var Path = require('path-parser');
// Defining a new path
var 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')       // => false
// Building
p.build({id: '00123'})                       // => "users/profile/00123"

Defining parameters

  • :param: for URL parameters
  • *splat: for parameters spanning over multiple segments. Handle with care
  • ?param1&param2 or ?:param1&:param2: for query parameters. Colons : are optional