summaryrefslogtreecommitdiff
path: root/node_modules/swup/src/helpers/matchPath.ts
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/swup/src/helpers/matchPath.ts')
-rw-r--r--node_modules/swup/src/helpers/matchPath.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/node_modules/swup/src/helpers/matchPath.ts b/node_modules/swup/src/helpers/matchPath.ts
new file mode 100644
index 00000000..e1332911
--- /dev/null
+++ b/node_modules/swup/src/helpers/matchPath.ts
@@ -0,0 +1,23 @@
+import { match } from 'path-to-regexp';
+
+import type {
+ Path,
+ ParseOptions,
+ TokensToRegexpOptions,
+ RegexpToFunctionOptions,
+ MatchFunction
+} from 'path-to-regexp';
+
+export { type Path };
+
+/** Create a match function from a path pattern that checks if a URLs matches it. */
+export const matchPath = <P extends object = object>(
+ path: Path,
+ options?: ParseOptions & TokensToRegexpOptions & RegexpToFunctionOptions
+): MatchFunction<P> => {
+ try {
+ return match<P>(path, options);
+ } catch (error) {
+ throw new Error(`[swup] Error parsing path "${String(path)}":\n${String(error)}`);
+ }
+};