UNPKG

@clerk/shared

Version:

Internal package utils used by the Clerk SDKs

1 lines 1.4 kB
{"version":3,"sources":["../src/pathMatcher.ts"],"sourcesContent":["import type { Autocomplete } from '@clerk/types';\n\nimport { pathToRegexp } from './pathToRegexp';\n\nexport type WithPathPatternWildcard<T = string> = `${T & string}(.*)`;\nexport type PathPattern = Autocomplete<WithPathPatternWildcard>;\nexport type PathMatcherParam = Array<RegExp | PathPattern> | RegExp | PathPattern;\n\nconst precomputePathRegex = (patterns: Array<string | RegExp>) => {\n return patterns.map(pattern => (pattern instanceof RegExp ? pattern : pathToRegexp(pattern)));\n};\n\n/**\n * Creates a function that matches paths against a set of patterns.\n *\n * @param patterns - A string, RegExp, or array of patterns to match against\n * @returns A function that takes a pathname and returns true if it matches any of the patterns\n */\nexport const createPathMatcher = (patterns: PathMatcherParam) => {\n const routePatterns = [patterns || ''].flat().filter(Boolean);\n const matchers = precomputePathRegex(routePatterns);\n return (pathname: string) => matchers.some(matcher => matcher.test(pathname));\n};\n"],"mappings":";;;;;AAQA,IAAM,sBAAsB,CAAC,aAAqC;AAChE,SAAO,SAAS,IAAI,aAAY,mBAAmB,SAAS,UAAU,aAAa,OAAO,CAAE;AAC9F;AAQO,IAAM,oBAAoB,CAAC,aAA+B;AAC/D,QAAM,gBAAgB,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,OAAO,OAAO;AAC5D,QAAM,WAAW,oBAAoB,aAAa;AAClD,SAAO,CAAC,aAAqB,SAAS,KAAK,aAAW,QAAQ,KAAK,QAAQ,CAAC;AAC9E;","names":[]}