MCPcopy
hub / github.com/tinyhttp/tinyhttp / typeIs

Function typeIs

packages/type-is/src/index.ts:71–91  ·  view source on GitHub ↗
(value: string, ...types: string[])

Source from the content-addressed store, hash-verified

69 * or a mime type.
70 */
71export const typeIs = (value: string, ...types: string[]) => {
72 let i: number
73 // remove parameters and normalize
74 const val = tryNormalizeType(value)
75
76 // no type or invalid
77 if (!val) return false
78
79 // no types, return the content type
80 if (!types || !types.length) return val
81
82 let type: string
83 for (i = 0; i < types.length; i++) {
84 if (mimeMatch(normalize((type = types[i])), val)) {
85 return type[0] === '+' || type.indexOf('*') !== -1 ? val : type
86 }
87 }
88
89 // no matches
90 return false
91}

Callers 2

reqIsFunction · 0.90
type-is.test.tsFile · 0.90

Calls 3

tryNormalizeTypeFunction · 0.85
mimeMatchFunction · 0.85
normalizeFunction · 0.85

Tested by

no test coverage detected