Skip to content

repetere/test-matching-route

 
 

Repository files navigation

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'

About

test dynamic route of array of routes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 56.1%
  • TypeScript 43.9%