UNPKG

flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

38 lines (35 loc) 1.25 kB
import { getJsType } from './get-js-type.js'; function wrapDefaultExport(content, withFunction) { const { isCJS, isESM } = getJsType(content); if (!isCJS && !isESM) { return content; } let wrappedContent = content; if (isESM) { const esmMatch = content.match(/export\s+default\s+(?:class|interface|abstract\s+class)\s+/); if (!esmMatch) { wrappedContent = wrappedContent.replace( /(export\s+default\s+)([^;\n]+(?:{[^}]*})?[^;\n]*)(;?\s*)$/gm, (_, prefix, exportValue, semicolon) => { const trimmedValue = exportValue.trim(); return `${prefix}${withFunction}(${trimmedValue})${semicolon}`; } ); } } if (isCJS) { const cjsMatch = content.match(/module\.exports\s*=\s*(?:class|interface|abstract\s+class)\s+/); if (!cjsMatch) { wrappedContent = wrappedContent.replace( /(module\.exports\s*=\s*)([^;\n]+(?:{[^}]*})?[^;\n]*)(;?\s*)$/gm, (_, prefix, exportValue, semicolon) => { const trimmedValue = exportValue.trim(); return `${prefix}${withFunction}(${trimmedValue})${semicolon}`; } ); } } return wrappedContent; } export { wrapDefaultExport }; //# sourceMappingURL=wrap-default-export.js.map