Skip to content

Instantly share code, notes, and snippets.

@joshuacerbito
Created May 18, 2017 16:37
Show Gist options
  • Save joshuacerbito/72917266d13e3343c28baa4c59d08fb6 to your computer and use it in GitHub Desktop.
Save joshuacerbito/72917266d13e3343c28baa4c59d08fb6 to your computer and use it in GitHub Desktop.
JS Module Exporter (AMD, CommonJS, Globals)
(function(globals){
// module name
const MODULE_NAME = 'moduleName';
// define your functions here
const functions = {
fn1: alert,
fn2: console.log
};
function exportFunctions (functions) {
if (typeof define === 'function' && define.amd) {
// set module name for AMD-based implementations
define(function () {
return functions;
});
} else if (typeof module !== 'undefined' && module !== null && module.exports) {
// set module name for CommonJS-based implementations
module.exports = functions;
} else {
// set module name for Global-based implementations
globals[MODULE_NAME] = functions;
}
}
exportFunctions(functions);
})(this)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment