MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / resolveMode

Function resolveMode

lib/web/CodeMirror/src/modes.js:21–36  ·  view source on GitHub ↗
(spec)

Source from the content-addressed store, hash-verified

19// Given a MIME type, a {name, ...options} config object, or a name
20// string, return a mode config object.
21export 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.

Callers 1

getModeFunction · 0.70

Calls 2

createObjFunction · 0.90
testMethod · 0.45

Tested by

no test coverage detected