Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/content/docs/curriculum-help.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,26 @@ const match =
match[1]; // "myFunc = arg1 => arg1; console.log();\n // captured, unfortunately"
```

NOTE: `capture: true` does not work correctly for regular functions whose body contains nested blocks (`if`, `try`, `for`, etc.). The captured content is truncated at the first `}` inside the body, so everything after the first closing brace of a nested block is silently excluded.

```js
const regEx = __helpers.functionRegex('registerUser', [], { capture: true });

const match = `function registerUser() {
if (name.trim() === "") {
throw new Error("Name is required");
}
if (age.trim() === "") {
throw new Error("Age is required");
}
}`.match(regEx);

match[1].includes('throw new Error("Name is required")'); // true — first if block IS captured
match[1].includes('age.trim'); // false — second if block is NOT captured
```

For functions with nested blocks, match directly against `code` or the stringified function instead of relying on `match[1]`.

#### `.getFunctionParams()`

Available via `__helpers.getFunctionParams(codeString)`, this method extracts parameter information from a function definition string.
Expand Down