route-helpers

v0.0.5
Match and reverse routes. Fast with no dependencies. Nothing more.
routes match reverse

Route helpers

Match and reverse routes. Fast with no dependencies. Nothing more.

build status npm version

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

npm i route-helpers

Metadata

  • MIT
  • Whatever
  • Michael Bannister
  • released 3/13/2016

Downloads

Maintainers