Tiny, light-weight JavaScript routing with zero dependencies.
const urlChecker = require('url-checker'); // not now in npm, but u cat copy code from index.js is very-lightweight!
urlChecker(
{
'/a/b-{c}-d-{e}': vars => console.log(vars),
'/about': vars => console.log(vars),
},
'/a/b-lalala-d-lololo'
);
// prints {c: 'lalala', e: 'lololo'}
Type: object
{
'/category': variablesFromUrl => {},
'/category/page': variablesFromUrl => {},
'/category/page-{pageNumber}': variablesFromUrl => { /* here variablesFromUrl.pageNumber is 31337 */ },
}
Type: string
/category/page-31337
MIT © Andrey Gurtovoy