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

Function createParams

packages/content-disposition/src/index.ts:78–110  ·  view source on GitHub ↗
(filename?: string, fallback?: string | boolean)

Source from the content-addressed store, hash-verified

76}
77
78function createParams(filename?: string, fallback?: string | boolean) {
79 if (filename === undefined) return
80
81 const params: Partial<
82 Record<string, any> & {
83 filename: string
84 }
85 > = {}
86
87 // fallback defaults to true
88 if (fallback === undefined) fallback = true
89
90 if (typeof fallback === 'string' && NON_LATIN1_REGEXP.test(fallback))
91 throw new TypeError('fallback must be ISO-8859-1 string')
92
93 // restrict to file base name
94 const name = basename(filename)
95
96 // determine if name is suitable for quoted string
97 const isQuotedString = TEXT_REGEXP.test(name)
98
99 // generate fallback name
100 const fallbackName = typeof fallback !== 'string' ? fallback && getlatin1(name) : basename(fallback)
101 const hasFallback = typeof fallbackName === 'string' && fallbackName !== name
102
103 // set extended filename parameter
104 if (hasFallback || !isQuotedString || HEX_ESCAPE_REGEXP.test(name)) params['filename*'] = name
105
106 // set filename parameter
107 if (isQuotedString || hasFallback) params.filename = hasFallback ? fallbackName : name
108
109 return params
110}
111
112const pdecode = (_str: string, hex: string) => String.fromCharCode(parseInt(hex, 16))
113

Callers 1

contentDispositionFunction · 0.85

Calls 1

getlatin1Function · 0.85

Tested by

no test coverage detected