2.0.0 • Published 5 years ago

test-matching-route v2.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

test-matching-route Coverage Status Build Status

Test a location against a list of possible routes. This is a simple way to test routes.

Example

This works for both socket servers and clients

// SERVER CODE
import { findMatchingRoutePath, } from 'test-matching-route';

const routesObject = {
  '/collections/:collection/products/:product': { page:'data1', },
  '/products/:product': { page:'data2',  },
  '/somedata/:collection/products/:id': { page:'data3', },
  '/:product': { page:'data4',  },
  '/:id': { page:'data5', },
};
const routesArray = ['/collections/:collection/products/:product',  '/products/:product',  '/somedata/:collection/products/:id',  '/:product',  '/:id',];

findMatchingRoutePath(routesObject, '/products/cool-shoes'); // => '/products/:product'
findMatchingRoutePath(routesArray, '/collections/luxury/products/fancy-watch'); // => '/collections/:collection/products/:product'