MCPcopy Index your code
hub / github.com/tinyhttp/tinyhttp / pathCheck

Function pathCheck

packages/unless/src/index.ts:47–61  ·  view source on GitHub ↗

* Check path parameter * @param path path * @param url URL * @param method HTTP method

(path: (string | RegExp | PathObject)[], url: string, method: string)

Source from the content-addressed store, hash-verified

45 * @param method HTTP method
46 */
47function pathCheck(path: (string | RegExp | PathObject)[], url: string, method: string): boolean {
48 let res = false
49 for (const p of path) {
50 if (typeof p === 'string') res = res || p === url
51 else if (p instanceof RegExp) {
52 const regexPath: RegExp = p
53 res = res || regexPath.test(url)
54 } else {
55 const objectPath: PathObject = p
56 res = res || (objectPath.url === url && objectPath.methods.indexOf(method) !== -1)
57 }
58 if (res) return res
59 }
60 return res
61}
62
63/**
64 * Middleware for conditional middleware executing.

Callers 1

unlessFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected