-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathumh.js
63 lines (60 loc) · 2.66 KB
/
umh.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
;(function (factory) {
// Avoid referencing another module by its package (in Node.js environment) to
// make it loadable by Require.js: define(['sqimitive'], ...) will fail
// (unless a map or paths entry is configured) because Require.js doesn't
// parse package.json and will try to fetch sqimitive.js, not
// sqimitive/main.js.
//
// The '?part' is optional and is given only to Require.js, with '?' replaced
// with '/'. It exists for conditional dependency on another universal module:
// suppose your script depends on a utility library like NoDash but may also
// work with Underscore. You set deps to 'nodash?main:_' and it works with
// both Node.js and Require.js out of the box. However, overriding in Node.js
// happens on the per-package basis meaning 'nodash' is substituted for
// 'underscore' - but the latter may have another main script and requiring
// 'nodash/main' would fail; by giving the package's name alone we include the
// 'main' from package.json of 'underscore'. At the same time, 'nodash:_'
// won't work in Require.js without configuration (as explained above) even if
// no override takes place.
//
// If you have no dependencies but still want to use UMH, set this to ''.
var deps = 'moduleID?main:Property.in.window ano/ther:dep'
var me = 'ExportProperty.in.window'
// --- Universal Module (squizzle.me) - CommonJS - AMD - window --- IE9+ ---
if (typeof exports != 'undefined' && !exports.nodeType) {
// CommonJS/Node.js.
deps = (deps.replace(/\?[^:]*/g, '').match(/\S+(?=:)/g) || []).map(require)
if (typeof module != 'undefined' && module.exports) {
module.exports = factory.apply(this, deps)
} else {
exports = factory.apply(this, deps)
}
} else if (typeof define == 'function' && define.amd) {
// AMD/Require.js.
define(deps.replace(/\?/g, '/').match(/\S+(?=:)/g) || [], factory)
} else {
// In-browser. self = window or web worker scope.
var root = typeof self == 'object' ? self
: typeof global == 'object' ? global
: (this || {})
var by = function (obj, path) {
path = path.split('.')
while (obj && path.length) { obj = obj[path.shift()] }
return obj
}
// No lookbehind in IE.
deps = (deps.match(/:\S+/g) || []).map(function (dep) {
var res = by(root, dep = dep.substr(1))
if (!res) { throw me + ': missing dependency: ' + dep }
return res
})
me = me.split(/\.([^.]+)$/)
if (me.length > 1) { root = by(root, me.shift()) }
root[me[0]] = factory.apply(this, deps)
}
}).call(this, function (Sqimitive, $) {
"use strict";
//var exported = {}
//exported.foo = ...
return exported
});