0.3.0 • Published 5 years ago

properjs-matchroute v0.3.0

Weekly downloads
12
License
-
Repository
github
Last release
5 years ago

ProperJS // MatchRoute

Wildcard route matching for urls with !num and !slug conditions.

Installation

npm install properjs-matchroute --save-dev

Usage

Alone this utility may not be that useful, which is why it's used with the ProperJS/Router.

import MatchRoute = from "properjs-matchroute";

const routes = [
    // Known route
    "some/route",

    // Unknown route
    "another/:slug",

    // Enforce Number on last URI segment
    "also/:slug/:num!num"
];

const matcher = new MatchRoute( routes );

// Test url against routes
console.log( "test", matcher.test( "http://localhost:9999/some/route" ) );

// Compare a route against a url
console.log( "compare", matcher.compare( "some/:slug", "http://localhost:9999/some/route" ) );

// Parse a url against routes config
console.log( "parse", matcher.parse( "http://localhost:9999/some/route", routes ) );

// Get params property from .parse()
console.log( "params", matcher.params( "http://localhost:9999/another/thing" ) );

// Set routes config after initialization
// Wildcard any route that is non-external to your domain
matcher.config( ["*"] );
0.3.0

5 years ago

0.2.0

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago