route-helper
v0.0.3 routes match reverse
Route helper
Match and reverse routes. Fast with no dependencies. Nothing more.
Install
npm install --save route-helper
Note: it is assumed that this will be used in a modern environemnt, for legacy environments add babel-polyfill in your app.
Usage
Declare some routes:
import { urlToRouteHelper, routeToUrlHelper } from 'route-helper'
const routes = [
'/fruits/:fruitId',
'/fruits/:fruitId/veggies/:veggieId/meats/:meatId',
'/fruits/:fruitId/veggies/:veggieId',
]
const routeToUrl = routeToUrlHelper(routes)
const urlToRoute = urlToRouteHelper(routes)
Match:
const url = '/fruits/apple/veggies/celery/meats/pork'
urlToRoute(url) // <- { fruitId: 'apple', veggieId: 'celery', meatId: 'pork' }
Reverse:
const route = { fruitId: 'apple', veggieId: 'celery', meatId: 'pork' }
routeToUrl(route) // <- '/fruits/apple/veggies/celery/meats/pork'
npm i [email protected]
Metadata
- MIT
- Whatever
- Michael Bannister
- released 1/18/2016