route-helpers
v0.0.5
Published
Match and reverse routes. Fast with no dependencies. Nothing more.
Downloads
4
Readme
Route helpers
Match and reverse routes. Fast with no dependencies. Nothing more.
Install
npm install --save route-helpers
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-helpers'
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'
Releases
npm run build && npm publish