UNPKG

@powership/server

Version:
29 lines (26 loc) 943 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createRouteMatcher = createRouteMatcher; var _urlPattern = _interopRequireDefault(require("url-pattern")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * A wrapper around UrlPattern with improved typings * @param path * see: https://github.com/snd/url-pattern */ 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.default(_path, {}); } // extract route params from a string literal // used to infer if a route needs a params object //# sourceMappingURL=routeMatch.cjs.map