MCPcopy Create free account
hub / github.com/freeCodeCamp/freeCodeCamp / getHook

Function getHook

tools/challenge-parser/parser/plugins/add-hooks.js:23–40  ·  view source on GitHub ↗
(tree, sectionName)

Source from the content-addressed store, hash-verified

21}
22
23function getHook(tree, sectionName) {
24 const section = getSection(tree, sectionName);
25
26 if (section.length === 0) return;
27 if (section.length > 1)
28 throw Error(
29 `# ${sectionName} section must only contain a single code block`
30 );
31
32 const codeNode = section[0];
33
34 if (codeNode.type !== 'code')
35 throw Error(`# ${sectionName} section must contain a code block`);
36 if (codeNode.lang !== 'javascript' && codeNode.lang !== 'js')
37 throw Error(`# ${sectionName} hook must be written in JavaScript`);
38
39 return codeNode.value;
40}
41
42module.exports = plugin;

Callers 1

transformerFunction · 0.85

Calls 1

getSectionFunction · 0.85

Tested by

no test coverage detected