| 19 | // Given a MIME type, a {name, ...options} config object, or a name |
| 20 | // string, return a mode config object. |
| 21 | export function resolveMode(spec) { |
| 22 | if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) { |
| 23 | spec = mimeModes[spec] |
| 24 | } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) { |
| 25 | let found = mimeModes[spec.name] |
| 26 | if (typeof found == "string") found = {name: found} |
| 27 | spec = createObj(found, spec) |
| 28 | spec.name = found.name |
| 29 | } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) { |
| 30 | return resolveMode("application/xml") |
| 31 | } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) { |
| 32 | return resolveMode("application/json") |
| 33 | } |
| 34 | if (typeof spec == "string") return {name: spec} |
| 35 | else return spec || {name: "null"} |
| 36 | } |
| 37 | |
| 38 | // Given a mode spec (anything that resolveMode accepts), find and |
| 39 | // initialize an actual mode object. |