Skip to content

Commit c041284

Browse files
committed
Added umdAugmentation template to allow Module Augmentation in the root
1 parent 1568e31 commit c041284

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

templates/umdAugmentation.js

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

0 commit comments

Comments
 (0)