import * as keywork from "https://deno.land/x/keywork@v6.0.1/uri/mod.ts";
Keywork uses JavaScript's built-in URL Pattern API to create pattern matchers. The syntax is based on path-to-regexp. Wildcards, named capture groups, regular groups, and group modifiers are all supported.
URL patterns can be matched against full URLs, or individual URL components:
const pattern = new URLPattern({ pathname: '/users/:user' })
const match = pattern.exec('/users/jessie')
console.log(match.pathname.groups.user) // jessie
const pattern = new URLPattern('https://example.com/books/:id')
console.log(pattern.test('https://example.com/books/123')) // true
console.log(pattern.test('https://keywork.app/books/123')) // false
const pattern = new URLPattern('/:article', 'https://blog.example.com')
console.log(pattern.test('https://blog.example.com/article')) // true
console.log(pattern.test('https://blog.example.com/article/123')) // false
Peer Dependencies
Support for the URL Pattern API varies across browser runtimes.
You may need a polyfill if your app uses a runtime that hasn't yet added URLPattern
class.
yarn add urlpattern-polyfill
npm install --save urlpattern-polyfill
- Keywork#Router | Router
External Resources
Variables
Resolves a POSIX-like path into slash delineated segments. |
Functions
Converts a given | |
Converts a given |
Type Aliases
Either an instance of |