easier than regex string matching for urls, domains, filepaths and other strings.
can capture named parts of strings and conveniently returns them as objects. also does the reverse and generates strings given a pattern and such an object.
install:
npm install url-pattern
simple match example:
> var pattern = new UrlPattern('/api/users/:id');
> pattern.match('/api/users/10');
{id: '10'}
> pattern.match('/api/products/5');
null
complex match example showing off escaping, wildcards and optional segments:
url-pattern
easier than regex string matching for urls, domains, filepaths and other strings.
can capture named parts of strings and conveniently returns them as objects. also does the reverse and generates strings given a pattern and such an object.
install:
simple match example:
complex match example showing off escaping, wildcards and optional segments:
stringify example: