Skip to main content


Module Overview

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:

Matching URL pathname pattern.
const pattern = new URLPattern({ pathname: '/users/:user' })
const match = pattern.exec('/users/jessie')

console.log(match.pathname.groups.user) // jessie
Matching a full URL pattern.
const pattern = new URLPattern('')
console.log(pattern.test('')) // true
console.log(pattern.test('')) // false
Matching URL pathname pattern with a base URL
const pattern = new URLPattern('/:article', '')

console.log(pattern.test('')) // true
console.log(pattern.test('')) // 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.

Run in the root of your project.
$ yarn add urlpattern-polyfill
## Related Entries

External Resources


import * as URIUtils from 'keywork/uri'

Type Aliases

Path Parsing Functions

Type Cast Functions



Re-exports PathBuilder