MCPcopy Index your code
hub / github.com/developit/workerize / toCjs

Function toCjs

src/index.js:81–91  ·  view source on GitHub ↗
(code, exportsObjName, exports)

Source from the content-addressed store, hash-verified

79}
80
81function toCjs(code, exportsObjName, exports) {
82 code = code.replace(/^(\s*)export\s+default\s+/m, (s, before) => {
83 exports.default = true;
84 return `${before}${exportsObjName}.default=`;
85 });
86 code = code.replace(/^(\s*)export\s+((?:async\s*)?function(?:\s*\*)?|const|let|var)(\s+)([a-zA-Z$_][a-zA-Z0-9$_]*)/mg, (s, before, type, ws, name) => {
87 exports[name] = true;
88 return `${before}${exportsObjName}.${name}=${type}${ws}${name}`;
89 });
90 return `var ${exportsObjName}={};\n${code}\n${exportsObjName};`;
91}

Callers 1

workerizeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected