UNPKG

defuse

Version:

A poor man's module namespacing solution for the browser

1 lines 944 B
(function(){var a,b;"undefined"!=typeof global?(a=global,b=this):(a=this,a.defuse=b={}),b.api={},b.pending={},b.registry={},b.old=null,b.api.def=function(a,c){return b.pending[a]=c,b.registry[a]=null,this},b.api.undef=function(a){return delete b.pending[a],delete b.registry[a],this},b.api.use=function(a){var c=b.registry[a];if("undefined"==typeof c)throw new Error("module '"+a+"' does not exist");return null===c&&(c={},b.pending[a](c),b.registry[a]=c,delete b.pending[a]),c},b.assignTo=function(a){var c=b.api;for(var d in c)a[d]=c[d];return this},b.pollute=function(){var c=b.old={};for(var d in b.api)a.hasOwnProperty(d)&&(c[d]=a[d]);return b.assignTo(a),this},b.unpollute=function(){var c=b.old;if(null===c)throw new Error("defuse has not been assigned to the global object");for(var d in b.api)delete a[d];for(var e in c)a[e]=c[e];return b.old=null,this},b.exports=function(){var a={};return b.assignTo(a),a},b.assignTo(b)}).call(this);