Giter Site home page Giter Site logo

path-param-matcher's Introduction

path-param-matcher

Tests

Parse URL route paths into a RegExp with a syntax similar to chi. Conceptually similar to path-to-regexp, although simpler.

Install

npm install --save path-param-matcher

Usage

const parser = require('path-param-matcher')

/** Basic routes. */
parser('/')
/**
 * => new RegExp(/^\/$/)
 */

/** Trailing slashes must be explicit. */
parser('/some/thing/')
/**
 * => new RegExp(/^\/some\/thing\/$/)
 */

/** Named placeholders. */
parser('/{some}/{thing}')
/**
 * => new RegExp(/^\/(?<some>[^/]+)\/(?<thing>[^/]+)$/)
 */

/** Placeholders can provide their own regex. */
parser('/date/{yyyy:\\d\\d\\d\\d}/{mm:\\d\\d}/{dd:\\d\\d}')
/**
 * => new RegExp(/^\/date\/(?<yyyy>\d\d\d\d)\/(?<mm>\d\d)\/(?<dd>\d\d)$/)
 */

/** Anonymous placeholders. */
parser('/date/{:\\d\\d\\d\\d}/')
/**
 * => new RegExp(/^\/date\/(?:\d\d\d\d)\/$/)
 */

API

parser(path)

  • returns RegExp
  • throws TypeError

path: String

A TypeError will be thrown if the path meets any of the following criteria:

  • It is not a String.
  • It does not begin with a /.
  • A placeholder regex contains a /, {, or }.

License

MIT © Pat Gaffney

path-param-matcher's People

Contributors

patrickrgaffney avatar

Watchers

 avatar  avatar

path-param-matcher's Issues

Full chi Support

Tracking support for all of chis features:

  • Explicit trailing slash.
  • Basic string-only routes.
  • Named placeholders.
  • Placeholders can provide their own regex.
  • Anonymous placeholders.
  • Special * placeholder.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.