next-path-matcher
Version:
A tiny utility to match Next.js request paths using glob patterns or regular expressions. Built for use with Next.js middleware and API routes.
18 lines (15 loc) • 910 B
TypeScript
import { NextRequest } from 'next/server';
type Autocomplete<U extends T, T = string> = U | (T & Record<never, never>);
type WithPathPatternWildcard<T = string> = `${T & string}(.*)`;
type PathPattern = Autocomplete<WithPathPatternWildcard>;
type PathMatcherParam = Array<RegExp | PathPattern> | RegExp | PathPattern;
/**
* Returns a function that accepts a `NextRequest` object and returns whether the request matches the list of
* predefined paths that can be passed in as the first argument.
*
* You can use glob patterns to match multiple paths or a function to match against the request object.
* Path patterns and limited regular expressions are supported.
* For more information, see: https://www.npmjs.com/package/path-to-regexp/v/6.3.0
*/
declare const createPathMatcher: (paths: PathMatcherParam) => (req: NextRequest) => boolean;
export { createPathMatcher, createPathMatcher as default };