UNPKG

@powership/server

Version:
23 lines (20 loc) 699 B
import UrlPattern from 'url-pattern'; /** * A wrapper around UrlPattern with improved typings * @param path * see: https://github.com/snd/url-pattern */ export function createRouteMatcher(path) { let _path = path // changing the path to the format expected by UrlPattern for optional route parameters // https://www.npmjs.com/package/url-pattern#optional-segments-wildcards-and-escaping .replace(/(\/:?)([^?/:]*)\?/g, '($1$2)'); if (_path.endsWith('/')) { _path = path.slice(0, -1); } _path += `(/)`; return new UrlPattern(_path, {}); } // extract route params from a string literal // used to infer if a route needs a params object //# sourceMappingURL=routeMatch.mjs.map