UNPKG

1.01 kBJavaScriptView Raw
1function wrapModule(format, source, name) {
2 switch (format) {
3 case 'iife':
4 return `var ${name} = (function () {
5 return ${source}
6 }())`;
7 case 'cjs':
8 return `module.exports = ${source}`;
9 case 'esm':
10 return `export default ${source}`;
11 case 'umd':
12 return `
13 (function (global, factory) {
14 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
15 typeof define === 'function' && define.amd ? define(factory) :
16 (global.${name} = factory());
17 }(this, (function () {
18 return ${source}
19 })))
20 `;
21 case 'amd':
22 return `
23 define(function () {
24 return ${source}
25 });
26 `;
27 default:
28 return `(function () {
29 'use strict';
30 return ${source}
31 })()`;
32 }
33}
34
35module.exports = wrapModule;
\No newline at end of file