https://github.com/thomd/javascript-module-wrapper
universal wrapper for AMD, CommonJS and oldschools-JS modules (with tests)
https://github.com/thomd/javascript-module-wrapper
Last synced: 11 months ago
JSON representation
universal wrapper for AMD, CommonJS and oldschools-JS modules (with tests)
- Host: GitHub
- URL: https://github.com/thomd/javascript-module-wrapper
- Owner: thomd
- Created: 2014-02-23T18:52:47.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2017-03-02T21:06:33.000Z (over 9 years ago)
- Last Synced: 2025-03-30T19:14:54.120Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## JavaScript Modules
This is a little research project about using javascript modules.
[](https://travis-ci.org/thomd/javascript-module-wrapper)
A universal module wrapper is wrapping your javascript library so it can work as
1. **[CommonJS](http://www.commonjs.org/) module** (Implemented by [Node.js](http://wiki.thomd.net/index.php?title=Node.js),
[Rhino](http://wiki.thomd.net/index.php?title=Javascript_engines#Rhino),
[MongoDB](http://wiki.thomd.net/index.php?title=MongoDB) or
[CouchDB](http://wiki.thomd.net/index.php?title=CouchDB)
among others)
2. **[AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) module** (mplemented
by [Require.js](http://wiki.thomd.net/index.php?title=Javascript_Loader#RequireJS)
or [curl](https://github.com/cujojs/curl) among others)
3. **Plain JavaScript** (attached to the `global` object)
### Universal Module Wrapper
(function(global, factory){
if (typeof define === "function" && define.amd) define(factory); // AMD
else if (typeof module === "object") module.exports = factory(); // CommonJS
else global.myModule = factory(); // global context
}(this, function(){
"use strict";
return function(...) { ... } // the module
}));
### Load module using AMD
require(['module.js'], function(){
myModule();
})
### Load module using CommonJS
var myModule = require('./module');
myModule();
### Load module using the global context
myModule();
## Test
Tests are done with [Mocha](http://mochajs.org/) using
[Zombie](http://zombie.labnotes.org/).
Run all tests for AMD, CommonJS and Plain Javascript with
npm install
npm test