test-matching-route
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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'

Package Sidebar

Install

npm i test-matching-route

Weekly Downloads

7

Version

2.0.0

License

MIT

Unpacked Size

2.93 MB

Total Files

90

Last publish

Collaborators

  • yawetse