mirror of
https://github.com/lloeki/umodule-js.git
synced 2025-12-06 10:34:40 +01:00
umodule.js: first public release
This commit is contained in:
commit
c375db3ddf
11 changed files with 306 additions and 0 deletions
70
umodule.js
Normal file
70
umodule.js
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
// Generated by CoffeeScript 1.6.2
|
||||
/*
|
||||
# umodule.js v0.5
|
||||
# (c) 2013 Loic Nageleisen
|
||||
# Licensed under 3-clause BSD
|
||||
*/
|
||||
|
||||
|
||||
(function() {
|
||||
var Module, require, root,
|
||||
__slice = [].slice;
|
||||
|
||||
root = typeof global !== "undefined" && global !== null ? global : window;
|
||||
|
||||
require = function(id) {
|
||||
var item, target, _i, _len, _ref;
|
||||
|
||||
target = Module.root;
|
||||
_ref = id.split('/');
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
item = _ref[_i];
|
||||
target = target[item];
|
||||
}
|
||||
if (typeof target === 'undefined') {
|
||||
throw new Error("module not found: " + id);
|
||||
}
|
||||
return target.exports;
|
||||
};
|
||||
|
||||
Module = (function() {
|
||||
function Module(id) {
|
||||
this.id = id;
|
||||
this.exports = {};
|
||||
}
|
||||
|
||||
Module.define = function(target, name, block) {
|
||||
var item, top, _i, _len, _ref, _ref1;
|
||||
|
||||
if (arguments.length < 3) {
|
||||
_ref = [Module.root].concat(__slice.call(arguments)), target = _ref[0], name = _ref[1], block = _ref[2];
|
||||
}
|
||||
top = target;
|
||||
_ref1 = name.split('/');
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
item = _ref1[_i];
|
||||
target = target[item] || (target[item] = new Module(item));
|
||||
}
|
||||
block.call(target, target.exports, target.require, target);
|
||||
return target;
|
||||
};
|
||||
|
||||
Module.prototype.require = function() {
|
||||
return require();
|
||||
};
|
||||
|
||||
return Module;
|
||||
|
||||
})();
|
||||
|
||||
Module.root = new Module('root');
|
||||
|
||||
Module.root.exports = root;
|
||||
|
||||
Module.root.module = new Module('module');
|
||||
|
||||
Module.root.module.exports = Module;
|
||||
|
||||
root.require = require;
|
||||
|
||||
}).call(this);
|
||||
Loading…
Add table
Add a link
Reference in a new issue