Skip to content

Commit 23ffa7c

Browse files
jheraxDavid Rivera
authored and
David Rivera
committed
Added umdAugmentation template to allow Module Augmentation in the root
1 parent 36fd113 commit 23ffa7c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

templates/umdAugmentation.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// This UMD allows extend an existing module or library in the browser,
2+
// instead of overwriting it. It is useful for libraries that serves
3+
// as a shared namespace.
4+
5+
(function umd(root, factory) {
6+
if(typeof exports === 'object' && typeof module === 'object')
7+
// Node. CommonJs2 environments that support module.exports.
8+
module.exports = factory();
9+
else if(typeof define === 'function' && define.amd)
10+
// AMD. Register as an anonymous module.
11+
define([], factory);
12+
else if(typeof exports === 'object')
13+
// CommonJs
14+
exports.myLib = factory();
15+
else {
16+
// Browser. Allow Module Augmentation (root is window)
17+
var ts = Object.prototype.toString,
18+
obj = '[object Object]',
19+
myLib = factory();
20+
if (ts.call(root.myLib) === obj && ts.call(myLib) === obj) {
21+
for (var p in myLib) root.myLib[p] = myLib[p];
22+
// not used Object.assign(a,b) for compatibility
23+
} else root.myLib = myLib;
24+
}
25+
}(this, function() {
26+
27+
// Just return a value to define the module export.
28+
// This example returns an object, but the module
29+
// can return a function as the exported value.
30+
return {};
31+
}));

0 commit comments

Comments
 (0)