@mintlify/common
Version:
Commonly shared code within Mintlify
15 lines (14 loc) • 733 B
JavaScript
/**
* Check if an export statement contains a regular function declaration
* MDX parser only works properly with arrow functions, so we skip regular functions
*/
export const containsRegularFunction = (exportStatement) => {
// remove comments and clean up the statement
const cleanStatement = exportStatement.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/.*$/gm, '');
// check for function declarations like:
// 1. export default function ComponentName() { ... }
// 2. export function ComponentName() { ... }
// 3. function ComponentName() { ... }; export default ComponentName;
const functionDeclarationPattern = /\bfunction\s+\w+\s*\(/;
return functionDeclarationPattern.test(cleanStatement);
};