Comparing version 0.8.1 to 0.8.2
{ | ||
"name": "udefine", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"homepage": "https://github.com/freezedev/udefine", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -99,2 +99,14 @@ (function() { | ||
udefine.inject.add = function(name, value) { | ||
if (name == null) { | ||
return; | ||
} | ||
if (value == null) { | ||
value = {}; | ||
} | ||
if (value.root == null) { | ||
value.root = root; | ||
} | ||
if (value.name == null) { | ||
value.name = name; | ||
} | ||
udefine.inject.modules[name] = value; | ||
@@ -173,3 +185,4 @@ return this; | ||
commonjs: hasModule, | ||
browser: !hasModule | ||
browser: !hasModule, | ||
globals: !hasModule && !udefine.amd | ||
}); | ||
@@ -176,0 +189,0 @@ udefine.paths = { |
@@ -1,2 +0,2 @@ | ||
/*! udefine - v0.8.0 - 16-09-2013 */ | ||
(function(){"use strict";var e,n,t;(function(){var e;return null!=(e=Array.isArray)?e:Array.isArray=function(e){return e.push===Array.prototype.push&&null!=e.length}})(),n="undefined"!=typeof module&&null!==module&&null!=module.exports,e={},t=function(e){return"object"==typeof e&&!Array.isArray(e)},function(e){var o,r,u,i,l;return u=["commonjs","globals"],r=n?"commonjs":"globals",i=function(e,n){return"function"==typeof e?e.apply(this,n):e},o=function(e,t){var o,r;return n&&"string"==typeof l[t][e]?(o=require("path"),r=function(){return l.paths[t].base?l.paths[t].base:""}(),require(o.join(process.cwd(),r,l[t][e]))):l[t][e]},l=function(e,u,s){var d,f,c,a,m,p;if(null==e)throw Error("A udefine module needs to have a name");return("function"==typeof u||t(u))&&(p=[e,[],u],e=p[0],u=p[1],s=p[2]),"undefined"!=typeof define&&null!==define?(define.amd||define.umd)&&(m=define.apply(this,arguments)):(f=function(){var e,n,t;for(t=[],e=0,n=u.length;n>e;e++)d=u[e],t.push(o(d,r));return t}(),m=i(s,f),n&&(module.exports=m),Object.hasOwnProperty.call(l.modules[r],e)||(l.modules[r][e]=m)),Object.hasOwnProperty.call(l.inject.modules,e)&&(c=l.inject.modules[e].name,a=l.inject.modules[e].root,l.inject(a,c)(m)),m},l.inject=function(e,n){return function(t){return null!=e&&null!=n?e[n]=t:void 0}},l.inject.modules={},l.inject.add=function(e,n){return l.inject.modules[e]=n,this},l.inject.remove=function(e){return delete l.inject.modules[e],this},l.inject.clear=function(){return l.inject.modules={},this},l.modules={globals:{},commonjs:{},add:function(e,n){var t,o,u;if(n)if(Array.isArray(n))for(o=0,u=n.length;u>o;o++)t=n[o],l.modules[t][e]=void 0;else l.modules.set(e,n);else l.modules[r][e]=void 0;return this},remove:function(e){var n,t,o;for(t=0,o=u.length;o>t;t++)n=u[t],Object.hasOwnProperty.call(l.modules[n],e)&&delete l.modules[n][e];return this},get:function(e){return l.modules[r][e]},set:function(e,n){var t,o;if("object"==typeof n)for(t in n)o=n[t],l.modules[t][e]=o;else l.modules[r][e]=n;return this},clear:function(){var e,n,t;for(n=0,t=u.length;t>n;n++)e=u[n],l.modules[e]={};return this}},l.env||(l.env={amd:function(){return"undefined"!=typeof define&&null!==define&&(define.amd||define.umd)}(),commonjs:n,browser:!n}),l.paths={commonjs:{base:void 0}},l.defaultConfig=function(){return l.modules.commonjs.root=e,null!=e.define?define("root",function(){return e}):void 0},l.defaultConfig(),l.configure=function(n){return n.apply(l,[e])},n?module.exports=l:e.udefine=l}(n?{}:this)}).call(this); | ||
/*! udefine - v0.8.1 - 16-09-2013 */ | ||
(function(){"use strict";var e,n,t;(function(){var e;return null!=(e=Array.isArray)?e:Array.isArray=function(e){return e.push===Array.prototype.push&&null!=e.length}})(),n="undefined"!=typeof module&&null!==module&&null!=module.exports,e={},t=function(e){return"object"==typeof e&&!Array.isArray(e)},function(e){var o,r,u,i,l;return u=["commonjs","globals"],r=n?"commonjs":"globals",i=function(e,n){return"function"==typeof e?e.apply(this,n):e},o=function(e,t){var o,r;return n&&"string"==typeof l[t][e]?(o=require("path"),r=function(){return l.paths[t].base?l.paths[t].base:""}(),require(o.join(process.cwd(),r,l[t][e]))):l[t][e]},l=function(e,u,s){var d,f,c,a,m,p;if(null==e)throw Error("A udefine module needs to have a name");return("function"==typeof u||t(u))&&(p=[e,[],u],e=p[0],u=p[1],s=p[2]),"undefined"!=typeof define&&null!==define?(define.amd||define.umd)&&(m=define.apply(this,arguments)):(f=function(){var e,n,t;for(t=[],e=0,n=u.length;n>e;e++)d=u[e],t.push(o(d,r));return t}(),m=i(s,f),n&&(module.exports=m),Object.hasOwnProperty.call(l.modules[r],e)||(l.modules[r][e]=m)),Object.hasOwnProperty.call(l.inject.modules,e)&&(c=l.inject.modules[e].name,a=l.inject.modules[e].root,l.inject(a,c)(m)),m},l.inject=function(e,n){return function(t){return null!=e&&null!=n?e[n]=t:void 0}},l.inject.modules={},l.inject.add=function(n,t){return null!=n?(null==t&&(t={}),null==t.root&&(t.root=e),null==t.name&&(t.name=n),l.inject.modules[n]=t,this):void 0},l.inject.remove=function(e){return delete l.inject.modules[e],this},l.inject.clear=function(){return l.inject.modules={},this},l.modules={globals:{},commonjs:{},add:function(e,n){var t,o,u;if(n)if(Array.isArray(n))for(o=0,u=n.length;u>o;o++)t=n[o],l.modules[t][e]=void 0;else l.modules.set(e,n);else l.modules[r][e]=void 0;return this},remove:function(e){var n,t,o;for(t=0,o=u.length;o>t;t++)n=u[t],Object.hasOwnProperty.call(l.modules[n],e)&&delete l.modules[n][e];return this},get:function(e){return l.modules[r][e]},set:function(e,n){var t,o;if("object"==typeof n)for(t in n)o=n[t],l.modules[t][e]=o;else l.modules[r][e]=n;return this},clear:function(){var e,n,t;for(n=0,t=u.length;t>n;n++)e=u[n],l.modules[e]={};return this}},l.env||(l.env={amd:function(){return"undefined"!=typeof define&&null!==define&&(define.amd||define.umd)}(),commonjs:n,browser:!n,globals:!n&&!l.amd}),l.paths={commonjs:{base:void 0}},l.defaultConfig=function(){return l.modules.commonjs.root=e,null!=e.define?define("root",function(){return e}):void 0},l.defaultConfig(),l.configure=function(n){return n.apply(l,[e])},n?module.exports=l:e.udefine=l}(n?{}:this)}).call(this); |
{ | ||
"name": "udefine", | ||
"description": "Define a module like it's an AMD module and use it in the browser/AMD and CommonJS", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"main": "dist/udefine.js", | ||
@@ -6,0 +6,0 @@ "devDependencies": { |
@@ -28,2 +28,5 @@ (function() { | ||
}); | ||
it('udefine.env has globals property', function() { | ||
return expect(envProp).to.have.property('globals'); | ||
}); | ||
it('udefine.env.commonjs is a boolean', function() { | ||
@@ -38,2 +41,5 @@ return expect(envProp.commonjs).to.be.a('boolean'); | ||
}); | ||
it('udefine.env.globals is a boolean', function() { | ||
return expect(envProp.globals).to.be.a('boolean'); | ||
}); | ||
it('udefine.env.commonjs is true on Node.js', function() { | ||
@@ -40,0 +46,0 @@ if (hasModule) { |
@@ -86,3 +86,3 @@ (function() { | ||
}); | ||
return it('udefine module definition with injection (module !== injection)', function() { | ||
it('udefine module definition with injection (module !== injection)', function() { | ||
var injectObj; | ||
@@ -104,4 +104,31 @@ | ||
}); | ||
it('udefine module definition with injection shorthand', function() { | ||
var injectObj; | ||
injectObj = {}; | ||
udefine.inject.add('pqr', { | ||
root: injectObj | ||
}); | ||
udefine('pqr', function() { | ||
return function() { | ||
return 43; | ||
}; | ||
}); | ||
expect(injectObj).to.be.a('object'); | ||
expect(injectObj.pqr).to.be.a('function'); | ||
return expect(injectObj.pqr()).to.equal(43); | ||
}); | ||
if (!hasModule) { | ||
it('udefine module definition with injection shorthand (globals)', function() {}); | ||
udefine.inject.add('stu'); | ||
udefine('stu', function() { | ||
return function() { | ||
return 44; | ||
}; | ||
}); | ||
expect(window.stu).to.be.a('function'); | ||
return expect(window.stu()).to.equal(44); | ||
} | ||
}); | ||
}).call(this); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
56644
641