| 726 | // Given a MIME type, a {name, ...options} config object, or a name |
| 727 | // string, return a mode config object. |
| 728 | function resolveMode(spec) { |
| 729 | if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) { |
| 730 | spec = mimeModes[spec]; |
| 731 | } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) { |
| 732 | var found = mimeModes[spec.name]; |
| 733 | if (typeof found == "string") { found = {name: found}; } |
| 734 | spec = createObj(found, spec); |
| 735 | spec.name = found.name; |
| 736 | } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) { |
| 737 | return resolveMode("application/xml") |
| 738 | } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) { |
| 739 | return resolveMode("application/json") |
| 740 | } |
| 741 | if (typeof spec == "string") { return {name: spec} } |
| 742 | else { return spec || {name: "null"} } |
| 743 | } |
| 744 | |
| 745 | // Given a mode spec (anything that resolveMode accepts), find and |
| 746 | // initialize an actual mode object. |