Skip to main content
Module

x/keywork/uri/mod.ts

A library for building V8 Isolate web apps on Cloudflare Workers, Deno, and Node.JS
Go to Latest
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 URLPatternLike to URLPattern

Converts a given URLPatternInput to URLPatternI nit

Type Aliases

Either an instance of URLPattern, or a string representing the pathname portion of a URLPattern