* @see https://mimesniff.spec.whatwg.org/#serialize-a-mime-type
(mimeType)
| 470 | * @see https://mimesniff.spec.whatwg.org/#serialize-a-mime-type |
| 471 | */ |
| 472 | function serializeAMimeType (mimeType) { |
| 473 | assert(mimeType !== 'failure') |
| 474 | const { parameters, essence } = mimeType |
| 475 | |
| 476 | // 1. Let serialization be the concatenation of mimeType’s |
| 477 | // type, U+002F (/), and mimeType’s subtype. |
| 478 | let serialization = essence |
| 479 | |
| 480 | // 2. For each name → value of mimeType’s parameters: |
| 481 | for (let [name, value] of parameters.entries()) { |
| 482 | // 1. Append U+003B (;) to serialization. |
| 483 | serialization += ';' |
| 484 | |
| 485 | // 2. Append name to serialization. |
| 486 | serialization += name |
| 487 | |
| 488 | // 3. Append U+003D (=) to serialization. |
| 489 | serialization += '=' |
| 490 | |
| 491 | // 4. If value does not solely contain HTTP token code |
| 492 | // points or value is the empty string, then: |
| 493 | if (!HTTP_TOKEN_CODEPOINTS.test(value)) { |
| 494 | // 1. Precede each occurrence of U+0022 (") or |
| 495 | // U+005C (\) in value with U+005C (\). |
| 496 | value = value.replace(/[\\"]/ug, '\\$&') |
| 497 | |
| 498 | // 2. Prepend U+0022 (") to value. |
| 499 | value = '"' + value |
| 500 | |
| 501 | // 3. Append U+0022 (") to value. |
| 502 | value += '"' |
| 503 | } |
| 504 | |
| 505 | // 5. Append value to serialization. |
| 506 | serialization += value |
| 507 | } |
| 508 | |
| 509 | // 3. Return serialization. |
| 510 | return serialization |
| 511 | } |
| 512 | |
| 513 | /** |
| 514 | * @see https://fetch.spec.whatwg.org/#http-whitespace |
no test coverage detected