react / wstein / node_modules / browserify / node_modules / browser-pack / node_modules / umd / index.js
80538 views'use strict';123var templateSTR = "(function(f){if(typeof exports===\"object\"&&typeof module!==\"undefined\"){module.exports=f()}else if(typeof define===\"function\"&&define.amd){define([],f)}else{var g;if(typeof window!==\"undefined\"){g=window}else if(typeof global!==\"undefined\"){g=global}else if(typeof self!==\"undefined\"){g=self}else{g=this}defineNamespace()}})(function(){source()});";45function template(moduleName, options) {6if (typeof options === 'boolean') {7options = {commonJS: options};8} else if (!options) {9options = {};10}11var str = templateSTR.replace(/defineNamespace\(\)/g, compileNamespace(moduleName))12.split('source()')13str[0] = str[0].trim();14//make sure these are undefined so as to not get confused if modules have inner UMD systems15str[0] += 'var define,module,exports;';16if (options.commonJS) str[0] += 'module={exports:(exports={})};';17str[0] += '\n';18if (options.commonJS) str[1] = 'return module.exports;' + str[1];19str[1] = '\n' + str[1];20return str;21}2223exports = module.exports = function (name, src, options) {24if (typeof options === 'string' && typeof src === 'object') {25var tmp = options;26options = src;27src = tmp;28}29return exports.prelude(name, options) + src + exports.postlude(name, options);30};3132exports.prelude = function (moduleName, options) {33return template(moduleName, options)[0];34};35exports.postlude = function (moduleName, options) {36return template(moduleName, options)[1];37};383940function camelCase(name) {41name = name.replace(/\-([a-z])/g, function (_, char) { return char.toUpperCase(); });42if (!/^[a-zA-Z_$]$/.test(name[0])) {43name = name.substr(1);44}45var result = name.replace(/[^\w$]+/g, '')46if (!result) {47throw new Error('Invalid JavaScript identifier resulted from camel-casing');48}49return result50}515253function compileNamespace(name) {54var names = name.split('.')5556// No namespaces, yield the best case 'global.NAME = VALUE'57if (names.length === 1) {58return 'g.' + camelCase(name) + ' = f()';5960// Acceptable case, with reasonable compilation61} else if (names.length === 2) {62names = names.map(camelCase);63return '(g.' + names[0] + ' || (g.' + names[0] + ' = {})).' + names[1] + ' = f()';6465// Worst case, too many namespaces to care about66} else {67var valueContainer = names.pop()68return names.map(compileNamespaceStep)69.concat(['g.' + camelCase(valueContainer) + ' = f()'])70.join(';');71}72}7374function compileNamespaceStep(name) {75name = camelCase(name);76return 'g=(g.' + name + '||(g.' + name + ' = {}))';77}787980