MCPcopy
hub / github.com/tinyhttp/tinyhttp / format

Function format

packages/content-disposition/src/index.ts:52–76  ·  view source on GitHub ↗
({
  parameters,
  type
}: Partial<{
  parameters: Record<any, any>
  type: string | boolean | undefined
}>)

Source from the content-addressed store, hash-verified

50}
51
52function format({
53 parameters,
54 type
55}: Partial<{
56 parameters: Record<any, any>
57 type: string | boolean | undefined
58}>) {
59 if (!type || typeof type !== 'string' || !TOKEN_REGEXP.test(type)) throw new TypeError('invalid type')
60
61 // start with normalized type
62 let string = String(type).toLowerCase()
63
64 // append parameters
65 if (parameters && typeof parameters === 'object') {
66 const params = Object.keys(parameters).sort()
67
68 for (const param of params) {
69 const val = param.substr(-1) === '*' ? ustring(parameters[param]) : qstring(parameters[param])
70
71 string += '; ' + param + '=' + val
72 }
73 }
74
75 return string
76}
77
78function createParams(filename?: string, fallback?: string | boolean) {
79 if (filename === undefined) return

Callers 2

contentDispositionFunction · 0.85
setCharsetFunction · 0.85

Calls 2

ustringFunction · 0.85
qstringFunction · 0.85

Tested by

no test coverage detected