MCPcopy Create free account
hub / github.com/nodejs/node / makeEntry

Function makeEntry

deps/undici/src/lib/web/fetch/formdata.js:242–274  ·  view source on GitHub ↗

* @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#create-an-entry * @param {string} name * @param {string|Blob} value * @param {?string} filename * @returns

(name, value, filename)

Source from the content-addressed store, hash-verified

240 * @returns
241 */
242function makeEntry (name, value, filename) {
243 // 1. Set name to the result of converting name into a scalar value string.
244 // Note: This operation was done by the webidl converter USVString.
245
246 // 2. If value is a string, then set value to the result of converting
247 // value into a scalar value string.
248 if (typeof value === 'string') {
249 // Note: This operation was done by the webidl converter USVString.
250 } else {
251 // 3. Otherwise:
252
253 // 1. If value is not a File object, then set value to a new File object,
254 // representing the same bytes, whose name attribute value is "blob"
255 if (!webidl.is.File(value)) {
256 value = new File([value], 'blob', { type: value.type })
257 }
258
259 // 2. If filename is given, then set value to a new File object,
260 // representing the same bytes, whose name attribute is filename.
261 if (filename !== undefined) {
262 /** @type {FilePropertyBag} */
263 const options = {
264 type: value.type,
265 lastModified: value.lastModified
266 }
267
268 value = new File([value], filename, options)
269 }
270 }
271
272 // 4. Return an entry whose name is name and whose value is value.
273 return { name, value }
274}
275
276webidl.is.FormData = webidl.util.MakeTypeAssertion(FormData)
277

Callers 3

multipartFormDataParserFunction · 0.70
appendMethod · 0.70
setMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected