Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esquire

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esquire - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

2

esquire-full.min.js

@@ -1,1 +0,1 @@

"use strict";!function a(b){function c(a,b){if(!(this instanceof c))return new c(a,b);var d=0,e=null,f=[],g=function(a){var b=d>0?"resolve":0>d?"reject":null;if(b)for(var c in a)a[c][b](e)},h=this;Object.defineProperties(this,{$$id:{enumerable:!1,configurable:!1,value:++s},resolve:{enumerable:!0,configurable:!1,value:function(b){if(b&&"function"==typeof b.then)b.then(function(a){h.resolve(a)},function(a){h.reject(a)});else if(0==d){if(e=b,d=1,a)try{e=a(e)}catch(c){e=c,d=-1}g(f)}}},reject:{enumerable:!0,configurable:!1,value:function(a){if(0==d){if(e=a,d=-1,b)try{e=b(e),d=1}catch(c){e=c}g(f)}}},promise:{enumerable:!0,configurable:!1,value:Object.defineProperties(new Object,{$$id:{enumerable:!1,configurable:!1,value:h.$$id},then:{enumerable:!0,configurable:!1,value:function(a,b){var e=new c(a,b);return 0==d?f.push(e):g([e]),e.promise}},"catch":{enumerable:!0,configurable:!1,value:function(a){return this.then(null,a)}}})}})}function d(a){if(!(this instanceof d))return new d(a);if("function"!=typeof a)throw new TypeError("Executor is not a function");var b=new c;Object.defineProperties(this,{$$id:{enumerable:!1,configurable:!1,value:b.$$id},then:{enumerable:!0,configurable:!1,value:function(){return b.promise.then.apply(b.promise,arguments)}},"catch":{enumerable:!0,configurable:!1,value:function(){return b.promise.catch.apply(b.promise,arguments)}}});try{a(b.resolve,b.reject)}catch(e){b.reject(e)}}function e(a,b){a="Esquire: "+(a||"Unknown error");var c="";if(b&&b.length)for(var d=0;d<b.length;d++)b[d]&&(c+=" -> "+b[d]);c&&(a+=" resolving"+c),Error.call(this,a),this.message=a;var e=this.stack||(new Error).stack;e&&(e=e.replace(new RegExp("^(Error|"+this.name+")\n"),""),this.stack=this.name+": "+this.message+"\n"+e)}function f(a,b){e.call(this,"Module '"+a+"' not found",b)}function g(a,b,c){e.call(this,"Module '"+a+"' failed to initialize",c),b&&(this.message=this.message+" [Cause: "+(b.message?b.message:"[no message]")+"]",this.cause=b)}function h(a,b){e.call(this,"Module '"+a+"' has circular dependencies",b)}function i(a,b,c,d){a=o(a);for(var e in b)b[e]=o(b[e]);Object.defineProperty(this,"name",{enumerable:!0,configurable:!1,value:a}),Object.defineProperty(this,"dependencies",{enumerable:!0,configurable:!1,value:b}),Object.defineProperty(this,"constructor",{enumerable:!0,configurable:!1,value:c}),Object.defineProperty(this,"$$dynamic",{enumerable:!1,configurable:!1,value:d||!1}),Object.defineProperty(this,"$$script",{enumerable:!1,configurable:!1,get:function(){return"Esquire.define("+JSON.stringify(this.name)+","+JSON.stringify(this.dependencies)+","+c.toString()+");"}}),Object.freeze(this)}function j(a){i.call(this,a,["$global"],function(a){function b(a,c,d){if(!d&&a in c)return c[a];var e=["Ms","ms","Moz","moz","WebKit","webkit"];for(var f in e){var g=e[f]+a;if(g in c)return c[g]}return a[0]!==a[0].toUpperCase()?b(a[0].toUpperCase()+a.substring(1),c,!0):void 0}function c(a,d){if(!d)return void 0;if(!a)return void 0;switch(a.length){case 0:return void 0;case 1:return b(a[0],d);default:return c(a.slice(1),b(a[0],d))}}return c(this.name.substring(8).split("."),a)},!0)}function k(a){i.call(this,a,[],function(){throw new e("The constructor for '"+a+"' should not be called'")},!0)}function l(a){if(!a)return[];for(var b=[],c=0;c<a.length;c++){var d=a[c];if("string"==typeof d)b.push(d);else if("function"==typeof d)b.push(d);else if(Array.isArray(d))b=b.concat(l(d));else{if("object"!=typeof d||"number"!=typeof d.length)throw new e("Invalid dependency: "+JSON.stringify(d));b=b.concat(l(d))}}return b}function m(){var a=l(arguments),b={arguments:[],"function":null};if(!a.length)return b;"function"==typeof a[a.length-1]&&(b.function=a.splice(-1)[0]);for(var c in a){var d=a[c];if("string"!=typeof d)throw new e("Found "+typeof d+" but needed string: "+d);b.arguments.push(d)}return b}function n(a){return/^\$global[\/\.].+/.test(a)}function o(a){return n(a)?"$global/"+a.substring(8):a}function p(){if(1==arguments.length&&arguments[0].name&&arguments[0].constructor){var a=arguments[0];return p(a.name,a.dependencies||[],a.constructor)}var b,c,d=m(arguments),f=[];if(!d.arguments.length)throw new e("No module name specified");if(b=o(d.arguments.splice(0,1)[0]),f=d.arguments,t[b])throw new e("Module '"+b+"' already defined");if(!d.function)throw new e("No constructor function specified for module '"+b+"'");return c=d.function,t[b]=new i(b,f,c),t[b]}function q(a,b,c){if(c||(c=[]),!a)throw new e("No module or module name specified");if("string"==typeof a){if(!t[a])throw new f(m,c);a=t[a]}if(c.indexOf(a.name)>=0)throw new h(a.name,c);var d=[];c.push(a.name);for(var g in a.dependencies){var i=a.dependencies[g],k=t[i];if(k){if(d.push(k),b){var l=q(k,c);for(var m in l)d.push(l[m])}}else{if(!n(i))throw new f(a.dependencies[g],c);d.push(new j(i))}}return c.pop(),d}function r(a){function f(d,h){if(l[d.name])return l[d.name];var i=q(d,!1,h),j=[];for(var m in i){var n=i[m];l[n.name]?j.push(l[n.name]):(h.push(d.name),j.push(f(n,h)),h.pop())}var o=h.slice(0),p=new c;d.name&&!d.$$dynamic&&(l[d.name]=p.promise);var r=a-5*o.length;50>r&&(r=50);var s=b.setTimeout(function(){var a=new e("Timeout reached waiting for module '"+d.name+"'",o);p.reject(a)},r),t=function(a){b.clearTimeout(s),d.name&&!d.$$dynamic&&(l[d.name]=a),p.resolve(a)},u=function(a){b.clearTimeout(s),p.reject(a)};return k.all(j).then(function(a){try{var b=d.constructor.apply(d,a);b&&"function"==typeof b.then?b.then(t,function(a){var b=new g(d.name,a,o);u(b)}):t(b)}catch(c){u(new g(d.name,c,o))}},function(a){u(a)}),p.promise}function h(){return 1==arguments.length&&"string"==typeof arguments[0]?j([arguments[0]],function(a){return a}):j(arguments,function(){for(var a=[],b=0;b<arguments.length;b++)a.push(arguments[b]);return a})}function j(){var a=m(arguments);if(!a.function)throw new e("Callback for injection unspecified");var b=new i(null,a.arguments,a.function);try{return f(b,[])}catch(c){return k.reject(c)}}if(!(this instanceof r))return new r(k);var k=b.Promise||d;if(void 0===a)a=2e3;else{if(a=Number(a),0/0===a)throw new e("Timeout is not a number");if(100>a)throw new e("Timeout must be greater or equal than 100ms")}var l={$global:b,$esquire:this,$promise:k,$deferred:c};Object.defineProperties(this,{inject:{enumerable:!0,configurable:!1,value:j},require:{enumerable:!0,configurable:!1,value:h}})}b.console||(b.console={}),b.console.error||(b.console.error=function(){}),b.console.warn||(b.console.warn=function(){}),b.console.log||(b.console.log=function(){}),b.console.info||(b.console.info=function(){}),b.console.debug||(b.console.debug=function(){});var s=0;c.prototype=Object.create(Object.prototype),c.prototype.constructor=c,c.prototype.name="Deferred",d.prototype=Object.create(Object.prototype),d.prototype.constructor=d,d.prototype.name="Promise",Object.defineProperty(d,"all",{enumerable:!0,configurable:!1,value:function(a){if(!Array.isArray(a))return d.reject(new TypeError("Invalid argument"));var b=new c;if(0==a.length)return b.resolve([]),b.promise;for(var e=new Array(a.length),f=a.length,g=0;g<a.length;g++)!function(c){var d=a[c];d&&"function"==typeof d.then?d.then(function(a){e[c]=a,0==--f&&b.resolve(e)},function(a){b.reject(a)}):(e[c]=d,0==--f&&b.resolve(e))}(g);return b.promise}}),Object.defineProperty(d,"race",{enumerable:!0,configurable:!1,value:function(a){if(!Array.isArray(a))return d.reject(new TypeError("Invalid argument"));var b=new c;for(var e in a){var f=a[e];f&&"function"==typeof f.then?f.then(function(a){b.resolve(a)},function(a){b.reject(a)}):b.resolve(f)}return b.promise}}),Object.defineProperty(d,"resolve",{enumerable:!0,configurable:!1,value:function(a){var b=new c;return a&&"function"==typeof a.then?a.then(function(a){b.resolve(a)},function(a){b.reject(a)}):b.resolve(a),b.promise}}),Object.defineProperty(d,"reject",{enumerable:!0,configurable:!1,value:function(a){var b=new c;return b.reject(a),b.promise}}),e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e.prototype.name="EsquireError",f.prototype=Object.create(e.prototype),f.prototype.constructor=f,f.prototype.name="NoModuleError",g.prototype=Object.create(e.prototype),g.prototype.constructor=g,g.prototype.name="ModuleConstructorError",h.prototype=Object.create(e.prototype),h.prototype.constructor=h,h.prototype.name="CircularDependencyError",j.prototype=Object.create(i.prototype),j.prototype.constructor=j,j.prototype.name="GlobalModule",k.prototype=Object.create(i.prototype),k.prototype.constructor=k,k.prototype.name="InternalModule";var t={$global:new k("$global"),$esquire:new k("$esquire"),$promise:new k("$promise"),$deferred:new k("$deferred")};if(Object.defineProperties(r,{$$script:{enumerable:!1,configurable:!1,value:a.toString()},$$normalize:{enumerable:!1,configurable:!1,value:m},$$Promise:{enumerable:!1,configurable:!1,value:d},$$Deferred:{enumerable:!1,configurable:!1,value:c},define:{enumerable:!0,configurable:!1,value:p},resolve:{enumerable:!0,configurable:!1,value:q},modules:{enumerable:!0,configurable:!1,get:function(){var a={};for(var b in t)a[b]=t[b];return Object.freeze(a)}},module:{enumerable:!0,configurable:!1,value:function(a){return a=o(a),a in t?t[a]:n(a)?new j(a):null}}}),b.Esquire)throw new Error("Esquire already defined in global scope");b.Esquire=r;var u=new r;b.esquire=function(){if(0==arguments.length)throw new e("No dependencies/callback specified");var a=m(arguments);return a.function?u.inject(a.arguments,a.function):u.require(1==arguments.length&&"string"==typeof arguments[0]?arguments[0]:a.arguments)}}(function(){try{return window}catch(a){return global}}()),function(a){function b(a){var b=a.filename||a.target&&a.target.src;if(g[b]){if(a.stopPropagation&&a.stopPropagation(),a.preventDefault&&a.preventDefault(),a.target&&a.target.parentNode)try{a.target.parentNode.removeChild(a.target)}catch(c){}var d=g[b];return delete g[b],d.remaining-=1,{script:b,promise:d}}}function c(a){var c=b(a);c&&(console.debug("Esquire: Successfully loaded script '",c.script,"'"),0==c.promise.remaining&&c.promise.resolve(Esquire.modules))}function d(a){var c=b(a);if(c){console.warn("Esquire: Unable to load script '",c.script,"'");var d=a.error||new Error("Unable to load script '"+c.script+"'");c.promise.reject(d)}}function e(){if(!h)throw new Error("Esquire: Document not available");var a=h.getElementsByTagName("script")[0],b=a.parentNode,e=new Esquire.$$Deferred(function(a){return a},function(a){throw a});e.remaining=0;var i=Esquire.$$normalize(arguments).arguments,j=[];for(var k in i)!function(a){var b=h.createElement("script");b.async=!0,b.defer=!0,b.src=a,a=b.src,f[a]?console.debug("Esquire: Script '"+a+"' already loaded"):g[a]?console.debug("Esquire: Script '"+a+"' already being loaded"):(b.addEventListener("load",c,!1),b.addEventListener("error",d,!1),g[a]=e,e.remaining+=1,j.push(b))}(i[k]);if(0==j.length)e.resolve(Esquire.modules);else for(var k in j)console.debug("Esquire: About to load '"+j[k].src+"'"),b.insertBefore(j[k],a);return e.promise}if(!a.Esquire)throw new Error("Esquire not available");var f={},g={};a.addEventListener("error",d,!0);var h=a.document;a.Esquire||(a.Esquire={}),a.Esquire.load=e}(window);
"use strict";!function a(b){function c(a,b){var d=0,e=null,f=[],g=function(a){var b=d>0?"resolve":0>d?"reject":null;if(b)for(var c in a)a[c][b](e)},h=this;Object.defineProperties(this,{resolve:{enumerable:!0,configurable:!1,value:function(b){if(b&&"function"==typeof b.then)b.then(function(a){h.resolve(a)},function(a){h.reject(a)});else if(0==d){if(e=b,d=1,a)try{e=a(e)}catch(c){e=c,d=-1}g(f)}}},reject:{enumerable:!0,configurable:!1,value:function(a){if(0==d){if(e=a,d=-1,b)try{e=b(e),d=1}catch(c){e=c}g(f)}}},promise:{enumerable:!0,configurable:!1,value:Object.defineProperties(new Object,{then:{enumerable:!0,configurable:!1,value:function(a,b){var e=new c(a,b);return 0==d?f.push(e):g([e]),e.promise}},"catch":{enumerable:!0,configurable:!1,value:function(a){return this.then(null,a)}}})}})}function d(a,e){if(!(this instanceof d))return new d(a,e);if(void 0===a)c.call(this);else{if(!("number"==typeof a&&a>=0))throw new TypeError("Deferred constructor must be called with a non-negative number");null==e?e=new Error("Timeout waiting for resolution/rejection"):"string"==typeof e&&(e=new Error(e));var f=this,g=b.setTimeout(function(){f.reject(e)},a);c.call(this,function(a){return b.clearTimeout(g),a},function(a){throw b.clearTimeout(g),a})}}function e(a){if(!(this instanceof e))return new e(a);if("function"!=typeof a)throw new TypeError("Executor is not a function");var b=new d;Object.defineProperties(this,{then:{enumerable:!0,configurable:!1,value:function(){return b.promise.then.apply(b.promise,arguments)}},"catch":{enumerable:!0,configurable:!1,value:function(){return b.promise.catch.apply(b.promise,arguments)}}});try{a(b.resolve,b.reject)}catch(c){b.reject(c)}}function f(a,b){a="Esquire: "+(a||"Unknown error");var c="";if(b&&b.length)for(var d=0;d<b.length;d++)b[d]&&(c+=" -> "+b[d]);c&&(a+=" resolving"+c),Error.call(this,a),this.message=a;var e=this.stack||(new Error).stack;e&&(e=e.replace(new RegExp("^(Error|"+this.name+")\n"),""),this.stack=this.name+": "+this.message+"\n"+e)}function g(a){f.call(this,"Module '"+a+"' not found")}function h(a,b){var c=a?"Error instantiating '"+a+"' module":"Injection failed";this.$$message=c,b&&(this.originalCause=b.originalCause||b,this.cause=b);for(var d=b;null!=d;d=d.cause)c+="\n- Cause: "+(d.$$message||d.message||"[no message]");f.call(this,c)}function i(a){var b="Detected circular dependency in ";for(var c in a)b+=a[c]+" -> ";b+=a[0],this.$$message=b,f.call(this,b)}function j(a,b,c,d){a=p(a);for(var e in b)b[e]=p(b[e]);Object.defineProperty(this,"name",{enumerable:!0,configurable:!1,value:a}),Object.defineProperty(this,"dependencies",{enumerable:!0,configurable:!1,value:b}),Object.defineProperty(this,"constructor",{enumerable:!0,configurable:!1,value:c}),Object.defineProperty(this,"$$dynamic",{enumerable:!1,configurable:!1,value:d||!1}),Object.defineProperty(this,"$$script",{enumerable:!1,configurable:!1,get:function(){return"Esquire.define("+JSON.stringify(this.name)+","+JSON.stringify(this.dependencies)+","+c.toString()+");"}}),Object.freeze(this)}function k(a){j.call(this,a,["$global"],function(a){function b(a,c,d){if(!d&&a in c)return c[a];var e=["Ms","ms","Moz","moz","WebKit","webkit"];for(var f in e){var g=e[f]+a;if(g in c)return c[g]}return a[0]!==a[0].toUpperCase()?b(a[0].toUpperCase()+a.substring(1),c,!0):void 0}function c(a,d){if(!d)return void 0;if(!a)return void 0;switch(a.length){case 0:return void 0;case 1:return b(a[0],d);default:return c(a.slice(1),b(a[0],d))}}return c(this.name.substring(8).split("."),a)},!0)}function l(a){j.call(this,a,[],function(){throw new f("The constructor for '"+a+"' should not be called'")},!0)}function m(a){if(!a)return[];for(var b=[],c=0;c<a.length;c++){var d=a[c];if("string"==typeof d)b.push(d);else if("function"==typeof d)b.push(d);else if(Array.isArray(d))b=b.concat(m(d));else{if("object"!=typeof d||"number"!=typeof d.length)throw new f("Invalid dependency: "+JSON.stringify(d));b=b.concat(m(d))}}return b}function n(){var a=m(arguments),b={arguments:[],"function":null};if(!a.length)return b;"function"==typeof a[a.length-1]&&(b.function=a.splice(-1)[0]);for(var c in a){var d=a[c];if("string"!=typeof d)throw new f("Found "+typeof d+" but needed string: "+d);b.arguments.push(d)}return b}function o(a){return/^\$global[\/\.].+/.test(a)}function p(a){return o(a)?"$global/"+a.substring(8):a}function q(){if(1==arguments.length&&arguments[0].name&&arguments[0].constructor){var a=arguments[0];return q(a.name,a.dependencies||[],a.constructor)}var b,c,d=n(arguments),e=[];if(!d.arguments.length)throw new f("No module name specified");if(b=p(d.arguments.splice(0,1)[0]),e=d.arguments,y[b])throw new f("Module '"+b+"' already defined");if(!d.function)throw new f("No constructor function specified for module '"+b+"'");c=d.function;var a=y[b]=new j(b,e,c);for(var g in x.define)try{x.define[g](a)}catch(h){console.error("Error notifying listener",h)}return z[a.name]&&(z[a.name].resolve(a),delete z[a.name]),a}function r(a){if(a instanceof j)return a;if("string"==typeof a){if(y[a])return y[a];if(z[a])return z[a].promise;if(o(a))return y[a]=new k(a);var b=new d(v/2,new g(a));return z[a]=b,b.promise}return w.reject("Unable to resolve module of type "+typeof a)}function s(a){if(!(a instanceof j))return w.reject("Unable to resolve module of type "+typeof a);if(0==a.dependencies.length)return A;var b=[];for(var c in a.dependencies){var d=a.dependencies[c];b.push(r(d))}return w.all(b)}function t(a,b){if(!(a instanceof j))return w.reject("Unable to resolve module of type "+typeof a);var c=[];for(var d in a.dependencies){var e=a.dependencies[d];if(!b[e]){var f=b[e]=r(e);c.push(w.resolve(f).then(function(a){return b[e]=a,t(a,b)}))}}return w.all(c).then(function(){return b})}function u(a){function c(a,b,e){if(e=e.slice(0),null!=a.name&&e.push(a.name),k[a.name])return k[a.name];50>b&&(b=50);var f=new d(b,"Timeout waiting for module '"+a.name+"'");return a.name&&!a.$$dynamic&&(k[a.name]=f.promise),s(a).then(function(d){var f=[];for(var g in d){var h=d[g],j=e.indexOf(h.name);if(j>=0){var l=e.slice(j);throw new i(l)}f.push(k[h.name]?k[h.name]:c(h,b-5,e))}return w.all(f).then(function(b){return a.constructor.apply(a,b)})}).then(function(b){a.name&&!a.$$dynamic&&(k[a.name]=b),f.resolve(b)},function(b){f.reject(new h(a.name,b))}),f.promise}function e(){return 1==arguments.length&&"string"==typeof arguments[0]?g([arguments[0]],function(a){return a}):g(arguments,function(){for(var a=[],b=0;b<arguments.length;b++)a.push(arguments[b]);return a})}function g(){var b=n(arguments);if(!b.function)throw new f("Callback for injection unspecified");var d=new j(null,b.arguments,b.function);try{return c(d,a,[])}catch(e){return w.reject(e)}}if(!(this instanceof u))return new u(w);if(void 0===a)a=v;else{if(a=Number(a),0/0===a)throw new f("Timeout is not a number");if(100>a)throw new f("Timeout must be greater or equal than 100ms")}var k={$global:b,$esquire:this,$promise:w,$deferred:d};Object.defineProperties(this,{inject:{enumerable:!0,configurable:!1,value:g},require:{enumerable:!0,configurable:!1,value:e}})}b.console||(b.console={}),b.console.error||(b.console.error=function(){}),b.console.warn||(b.console.warn=function(){}),b.console.log||(b.console.log=function(){}),b.console.info||(b.console.info=function(){}),b.console.debug||(b.console.debug=function(){}),c.prototype=Object.create(Object.prototype),c.prototype.constructor=c,c.prototype.name="Deferring",d.prototype=Object.create(c.prototype),d.prototype.constructor=d,d.prototype.name="Deferred",e.prototype=Object.create(Object.prototype),e.prototype.constructor=e,e.prototype.name="Promise",Object.defineProperty(e,"all",{enumerable:!0,configurable:!1,value:function(a){if(!Array.isArray(a))return e.reject(new TypeError("Invalid argument"));var b=new d;if(0==a.length)return b.resolve([]),b.promise;for(var c=new Array(a.length),f=a.length,g=0;g<a.length;g++)!function(d){var e=a[d];e&&"function"==typeof e.then?e.then(function(a){c[d]=a,0==--f&&b.resolve(c)},function(a){b.reject(a)}):(c[d]=e,0==--f&&b.resolve(c))}(g);return b.promise}}),Object.defineProperty(e,"race",{enumerable:!0,configurable:!1,value:function(a){if(!Array.isArray(a))return e.reject(new TypeError("Invalid argument"));var b=new d;for(var c in a){var f=a[c];f&&"function"==typeof f.then?f.then(function(a){b.resolve(a)},function(a){b.reject(a)}):b.resolve(f)}return b.promise}}),Object.defineProperty(e,"resolve",{enumerable:!0,configurable:!1,value:function(a){var b=new d;return a&&"function"==typeof a.then?a.then(function(a){b.resolve(a)},function(a){b.reject(a)}):b.resolve(a),b.promise}}),Object.defineProperty(e,"reject",{enumerable:!0,configurable:!1,value:function(a){var b=new d;return b.reject(a),b.promise}}),f.prototype=Object.create(Error.prototype),f.prototype.constructor=f,f.prototype.name="EsquireError",g.prototype=Object.create(f.prototype),g.prototype.constructor=g,g.prototype.name="NoModuleError",h.prototype=Object.create(f.prototype),h.prototype.constructor=h,h.prototype.name="InjectionError",i.prototype=Object.create(f.prototype),i.prototype.constructor=i,i.prototype.name="CircularDependencyError",k.prototype=Object.create(j.prototype),k.prototype.constructor=k,k.prototype.name="GlobalModule",l.prototype=Object.create(j.prototype),l.prototype.constructor=l,l.prototype.name="InternalModule";var v=2e3,w=b.Promise||e,x={define:[]},y={$global:new l("$global"),$esquire:new l("$esquire"),$promise:new l("$promise"),$deferred:new l("$deferred")},z={},A=w.resolve([]);if(Object.defineProperties(u,{$$script:{enumerable:!1,configurable:!1,value:a.toString()},$$normalize:{enumerable:!1,configurable:!1,value:n},$$Promise:{enumerable:!1,configurable:!1,value:e},$$Deferred:{enumerable:!1,configurable:!1,value:d},define:{enumerable:!0,configurable:!1,value:q},resolve:{enumerable:!0,configurable:!1,value:function(a,b){if("string"==typeof a)return w.resolve(r(a)).then(function(a){return u.resolve(a,b)});if(!(a instanceof j))throw new TypeError("Must be invoked with Module or module name");return b?t(a,{}):s(a).then(function(a){var b={};for(var c in a)b[a[c].name]=a[c];return b})}},timeout:{enumerable:!0,configurable:!1,get:function(){return v},set:function(a){if(a=Number(a),0/0===a)throw new f("Timeout is not a number");if(100>a)throw new f("Timeout must be greater or equal than 100ms");v=a}},modules:{enumerable:!0,configurable:!1,get:function(){var a={};for(var b in y)a[b]=y[b];return Object.freeze(a)}},module:{enumerable:!0,configurable:!1,value:function(a){return w.resolve(r(a))}},on:{enumerable:!0,configurable:!1,value:function(a,b){if("string"!=typeof a)throw new f("Event name must be a string");if("function"!=typeof b)throw new f("Listener must be a function");return"define"===a&&x.define.push(b),u}}}),b.Esquire)throw new Error("Esquire already defined in global scope");b.Esquire=u;var B=new u;b.esquire=function(){if(0==arguments.length)throw new f("No dependencies/callback specified");var a=n(arguments);return a.function?B.inject(a.arguments,a.function):B.require(1==arguments.length&&"string"==typeof arguments[0]?arguments[0]:a.arguments)}}(function(){try{return window}catch(a){return global}}()),function(a){function b(a){var b=a.filename||a.target&&a.target.src;if(g[b]){if(a.stopPropagation&&a.stopPropagation(),a.preventDefault&&a.preventDefault(),a.target&&a.target.parentNode)try{a.target.parentNode.removeChild(a.target)}catch(c){}var d=g[b];return delete g[b],d.remaining-=1,{script:b,promise:d}}}function c(a){var c=b(a);c&&(console.debug("Esquire: Successfully loaded script '",c.script,"'"),0==c.promise.remaining&&c.promise.resolve(Esquire.modules))}function d(a){var c=b(a);if(c){console.warn("Esquire: Unable to load script '",c.script,"'");var d=a.error||new Error("Unable to load script '"+c.script+"'");c.promise.reject(d)}}function e(){if(!h)throw new Error("Esquire: Document not available");var a=h.getElementsByTagName("script")[0],b=a.parentNode,e=new Esquire.$$Deferred;e.remaining=0;var i=Esquire.$$normalize(arguments).arguments,j=[];for(var k in i)!function(a){var b=h.createElement("script");b.async=!0,b.defer=!0,b.src=a,a=b.src,f[a]?console.debug("Esquire: Script '"+a+"' already loaded"):g[a]?console.debug("Esquire: Script '"+a+"' already being loaded"):(b.addEventListener("load",c,!1),b.addEventListener("error",d,!1),g[a]=e,e.remaining+=1,j.push(b))}(i[k]);if(0==j.length)e.resolve(Esquire.modules);else for(var k in j)console.debug("Esquire: About to load '"+j[k].src+"'"),b.insertBefore(j[k],a);return e.promise}if(!a.Esquire)throw new Error("Esquire not available");var f={},g={};a.addEventListener("error",d,!0);var h=a.document;a.Esquire||(a.Esquire={}),a.Esquire.load=e}(window);

@@ -1,1 +0,1 @@

"use strict";!function a(b){function c(a,b){if(!(this instanceof c))return new c(a,b);var d=0,e=null,f=[],g=function(a){var b=d>0?"resolve":0>d?"reject":null;if(b)for(var c in a)a[c][b](e)},h=this;Object.defineProperties(this,{$$id:{enumerable:!1,configurable:!1,value:++s},resolve:{enumerable:!0,configurable:!1,value:function(b){if(b&&"function"==typeof b.then)b.then(function(a){h.resolve(a)},function(a){h.reject(a)});else if(0==d){if(e=b,d=1,a)try{e=a(e)}catch(c){e=c,d=-1}g(f)}}},reject:{enumerable:!0,configurable:!1,value:function(a){if(0==d){if(e=a,d=-1,b)try{e=b(e),d=1}catch(c){e=c}g(f)}}},promise:{enumerable:!0,configurable:!1,value:Object.defineProperties(new Object,{$$id:{enumerable:!1,configurable:!1,value:h.$$id},then:{enumerable:!0,configurable:!1,value:function(a,b){var e=new c(a,b);return 0==d?f.push(e):g([e]),e.promise}},"catch":{enumerable:!0,configurable:!1,value:function(a){return this.then(null,a)}}})}})}function d(a){if(!(this instanceof d))return new d(a);if("function"!=typeof a)throw new TypeError("Executor is not a function");var b=new c;Object.defineProperties(this,{$$id:{enumerable:!1,configurable:!1,value:b.$$id},then:{enumerable:!0,configurable:!1,value:function(){return b.promise.then.apply(b.promise,arguments)}},"catch":{enumerable:!0,configurable:!1,value:function(){return b.promise.catch.apply(b.promise,arguments)}}});try{a(b.resolve,b.reject)}catch(e){b.reject(e)}}function e(a,b){a="Esquire: "+(a||"Unknown error");var c="";if(b&&b.length)for(var d=0;d<b.length;d++)b[d]&&(c+=" -> "+b[d]);c&&(a+=" resolving"+c),Error.call(this,a),this.message=a;var e=this.stack||(new Error).stack;e&&(e=e.replace(new RegExp("^(Error|"+this.name+")\n"),""),this.stack=this.name+": "+this.message+"\n"+e)}function f(a,b){e.call(this,"Module '"+a+"' not found",b)}function g(a,b,c){e.call(this,"Module '"+a+"' failed to initialize",c),b&&(this.message=this.message+" [Cause: "+(b.message?b.message:"[no message]")+"]",this.cause=b)}function h(a,b){e.call(this,"Module '"+a+"' has circular dependencies",b)}function i(a,b,c,d){a=o(a);for(var e in b)b[e]=o(b[e]);Object.defineProperty(this,"name",{enumerable:!0,configurable:!1,value:a}),Object.defineProperty(this,"dependencies",{enumerable:!0,configurable:!1,value:b}),Object.defineProperty(this,"constructor",{enumerable:!0,configurable:!1,value:c}),Object.defineProperty(this,"$$dynamic",{enumerable:!1,configurable:!1,value:d||!1}),Object.defineProperty(this,"$$script",{enumerable:!1,configurable:!1,get:function(){return"Esquire.define("+JSON.stringify(this.name)+","+JSON.stringify(this.dependencies)+","+c.toString()+");"}}),Object.freeze(this)}function j(a){i.call(this,a,["$global"],function(a){function b(a,c,d){if(!d&&a in c)return c[a];var e=["Ms","ms","Moz","moz","WebKit","webkit"];for(var f in e){var g=e[f]+a;if(g in c)return c[g]}return a[0]!==a[0].toUpperCase()?b(a[0].toUpperCase()+a.substring(1),c,!0):void 0}function c(a,d){if(!d)return void 0;if(!a)return void 0;switch(a.length){case 0:return void 0;case 1:return b(a[0],d);default:return c(a.slice(1),b(a[0],d))}}return c(this.name.substring(8).split("."),a)},!0)}function k(a){i.call(this,a,[],function(){throw new e("The constructor for '"+a+"' should not be called'")},!0)}function l(a){if(!a)return[];for(var b=[],c=0;c<a.length;c++){var d=a[c];if("string"==typeof d)b.push(d);else if("function"==typeof d)b.push(d);else if(Array.isArray(d))b=b.concat(l(d));else{if("object"!=typeof d||"number"!=typeof d.length)throw new e("Invalid dependency: "+JSON.stringify(d));b=b.concat(l(d))}}return b}function m(){var a=l(arguments),b={arguments:[],"function":null};if(!a.length)return b;"function"==typeof a[a.length-1]&&(b.function=a.splice(-1)[0]);for(var c in a){var d=a[c];if("string"!=typeof d)throw new e("Found "+typeof d+" but needed string: "+d);b.arguments.push(d)}return b}function n(a){return/^\$global[\/\.].+/.test(a)}function o(a){return n(a)?"$global/"+a.substring(8):a}function p(){if(1==arguments.length&&arguments[0].name&&arguments[0].constructor){var a=arguments[0];return p(a.name,a.dependencies||[],a.constructor)}var b,c,d=m(arguments),f=[];if(!d.arguments.length)throw new e("No module name specified");if(b=o(d.arguments.splice(0,1)[0]),f=d.arguments,t[b])throw new e("Module '"+b+"' already defined");if(!d.function)throw new e("No constructor function specified for module '"+b+"'");return c=d.function,t[b]=new i(b,f,c),t[b]}function q(a,b,c){if(c||(c=[]),!a)throw new e("No module or module name specified");if("string"==typeof a){if(!t[a])throw new f(m,c);a=t[a]}if(c.indexOf(a.name)>=0)throw new h(a.name,c);var d=[];c.push(a.name);for(var g in a.dependencies){var i=a.dependencies[g],k=t[i];if(k){if(d.push(k),b){var l=q(k,c);for(var m in l)d.push(l[m])}}else{if(!n(i))throw new f(a.dependencies[g],c);d.push(new j(i))}}return c.pop(),d}function r(a){function f(d,h){if(l[d.name])return l[d.name];var i=q(d,!1,h),j=[];for(var m in i){var n=i[m];l[n.name]?j.push(l[n.name]):(h.push(d.name),j.push(f(n,h)),h.pop())}var o=h.slice(0),p=new c;d.name&&!d.$$dynamic&&(l[d.name]=p.promise);var r=a-5*o.length;50>r&&(r=50);var s=b.setTimeout(function(){var a=new e("Timeout reached waiting for module '"+d.name+"'",o);p.reject(a)},r),t=function(a){b.clearTimeout(s),d.name&&!d.$$dynamic&&(l[d.name]=a),p.resolve(a)},u=function(a){b.clearTimeout(s),p.reject(a)};return k.all(j).then(function(a){try{var b=d.constructor.apply(d,a);b&&"function"==typeof b.then?b.then(t,function(a){var b=new g(d.name,a,o);u(b)}):t(b)}catch(c){u(new g(d.name,c,o))}},function(a){u(a)}),p.promise}function h(){return 1==arguments.length&&"string"==typeof arguments[0]?j([arguments[0]],function(a){return a}):j(arguments,function(){for(var a=[],b=0;b<arguments.length;b++)a.push(arguments[b]);return a})}function j(){var a=m(arguments);if(!a.function)throw new e("Callback for injection unspecified");var b=new i(null,a.arguments,a.function);try{return f(b,[])}catch(c){return k.reject(c)}}if(!(this instanceof r))return new r(k);var k=b.Promise||d;if(void 0===a)a=2e3;else{if(a=Number(a),0/0===a)throw new e("Timeout is not a number");if(100>a)throw new e("Timeout must be greater or equal than 100ms")}var l={$global:b,$esquire:this,$promise:k,$deferred:c};Object.defineProperties(this,{inject:{enumerable:!0,configurable:!1,value:j},require:{enumerable:!0,configurable:!1,value:h}})}b.console||(b.console={}),b.console.error||(b.console.error=function(){}),b.console.warn||(b.console.warn=function(){}),b.console.log||(b.console.log=function(){}),b.console.info||(b.console.info=function(){}),b.console.debug||(b.console.debug=function(){});var s=0;c.prototype=Object.create(Object.prototype),c.prototype.constructor=c,c.prototype.name="Deferred",d.prototype=Object.create(Object.prototype),d.prototype.constructor=d,d.prototype.name="Promise",Object.defineProperty(d,"all",{enumerable:!0,configurable:!1,value:function(a){if(!Array.isArray(a))return d.reject(new TypeError("Invalid argument"));var b=new c;if(0==a.length)return b.resolve([]),b.promise;for(var e=new Array(a.length),f=a.length,g=0;g<a.length;g++)!function(c){var d=a[c];d&&"function"==typeof d.then?d.then(function(a){e[c]=a,0==--f&&b.resolve(e)},function(a){b.reject(a)}):(e[c]=d,0==--f&&b.resolve(e))}(g);return b.promise}}),Object.defineProperty(d,"race",{enumerable:!0,configurable:!1,value:function(a){if(!Array.isArray(a))return d.reject(new TypeError("Invalid argument"));var b=new c;for(var e in a){var f=a[e];f&&"function"==typeof f.then?f.then(function(a){b.resolve(a)},function(a){b.reject(a)}):b.resolve(f)}return b.promise}}),Object.defineProperty(d,"resolve",{enumerable:!0,configurable:!1,value:function(a){var b=new c;return a&&"function"==typeof a.then?a.then(function(a){b.resolve(a)},function(a){b.reject(a)}):b.resolve(a),b.promise}}),Object.defineProperty(d,"reject",{enumerable:!0,configurable:!1,value:function(a){var b=new c;return b.reject(a),b.promise}}),e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e.prototype.name="EsquireError",f.prototype=Object.create(e.prototype),f.prototype.constructor=f,f.prototype.name="NoModuleError",g.prototype=Object.create(e.prototype),g.prototype.constructor=g,g.prototype.name="ModuleConstructorError",h.prototype=Object.create(e.prototype),h.prototype.constructor=h,h.prototype.name="CircularDependencyError",j.prototype=Object.create(i.prototype),j.prototype.constructor=j,j.prototype.name="GlobalModule",k.prototype=Object.create(i.prototype),k.prototype.constructor=k,k.prototype.name="InternalModule";var t={$global:new k("$global"),$esquire:new k("$esquire"),$promise:new k("$promise"),$deferred:new k("$deferred")};if(Object.defineProperties(r,{$$script:{enumerable:!1,configurable:!1,value:a.toString()},$$normalize:{enumerable:!1,configurable:!1,value:m},$$Promise:{enumerable:!1,configurable:!1,value:d},$$Deferred:{enumerable:!1,configurable:!1,value:c},define:{enumerable:!0,configurable:!1,value:p},resolve:{enumerable:!0,configurable:!1,value:q},modules:{enumerable:!0,configurable:!1,get:function(){var a={};for(var b in t)a[b]=t[b];return Object.freeze(a)}},module:{enumerable:!0,configurable:!1,value:function(a){return a=o(a),a in t?t[a]:n(a)?new j(a):null}}}),b.Esquire)throw new Error("Esquire already defined in global scope");b.Esquire=r;var u=new r;b.esquire=function(){if(0==arguments.length)throw new e("No dependencies/callback specified");var a=m(arguments);return a.function?u.inject(a.arguments,a.function):u.require(1==arguments.length&&"string"==typeof arguments[0]?arguments[0]:a.arguments)}}(function(){try{return window}catch(a){return global}}());
"use strict";!function a(b){function c(a,b){var d=0,e=null,f=[],g=function(a){var b=d>0?"resolve":0>d?"reject":null;if(b)for(var c in a)a[c][b](e)},h=this;Object.defineProperties(this,{resolve:{enumerable:!0,configurable:!1,value:function(b){if(b&&"function"==typeof b.then)b.then(function(a){h.resolve(a)},function(a){h.reject(a)});else if(0==d){if(e=b,d=1,a)try{e=a(e)}catch(c){e=c,d=-1}g(f)}}},reject:{enumerable:!0,configurable:!1,value:function(a){if(0==d){if(e=a,d=-1,b)try{e=b(e),d=1}catch(c){e=c}g(f)}}},promise:{enumerable:!0,configurable:!1,value:Object.defineProperties(new Object,{then:{enumerable:!0,configurable:!1,value:function(a,b){var e=new c(a,b);return 0==d?f.push(e):g([e]),e.promise}},"catch":{enumerable:!0,configurable:!1,value:function(a){return this.then(null,a)}}})}})}function d(a,e){if(!(this instanceof d))return new d(a,e);if(void 0===a)c.call(this);else{if(!("number"==typeof a&&a>=0))throw new TypeError("Deferred constructor must be called with a non-negative number");null==e?e=new Error("Timeout waiting for resolution/rejection"):"string"==typeof e&&(e=new Error(e));var f=this,g=b.setTimeout(function(){f.reject(e)},a);c.call(this,function(a){return b.clearTimeout(g),a},function(a){throw b.clearTimeout(g),a})}}function e(a){if(!(this instanceof e))return new e(a);if("function"!=typeof a)throw new TypeError("Executor is not a function");var b=new d;Object.defineProperties(this,{then:{enumerable:!0,configurable:!1,value:function(){return b.promise.then.apply(b.promise,arguments)}},"catch":{enumerable:!0,configurable:!1,value:function(){return b.promise.catch.apply(b.promise,arguments)}}});try{a(b.resolve,b.reject)}catch(c){b.reject(c)}}function f(a,b){a="Esquire: "+(a||"Unknown error");var c="";if(b&&b.length)for(var d=0;d<b.length;d++)b[d]&&(c+=" -> "+b[d]);c&&(a+=" resolving"+c),Error.call(this,a),this.message=a;var e=this.stack||(new Error).stack;e&&(e=e.replace(new RegExp("^(Error|"+this.name+")\n"),""),this.stack=this.name+": "+this.message+"\n"+e)}function g(a){f.call(this,"Module '"+a+"' not found")}function h(a,b){var c=a?"Error instantiating '"+a+"' module":"Injection failed";this.$$message=c,b&&(this.originalCause=b.originalCause||b,this.cause=b);for(var d=b;null!=d;d=d.cause)c+="\n- Cause: "+(d.$$message||d.message||"[no message]");f.call(this,c)}function i(a){var b="Detected circular dependency in ";for(var c in a)b+=a[c]+" -> ";b+=a[0],this.$$message=b,f.call(this,b)}function j(a,b,c,d){a=p(a);for(var e in b)b[e]=p(b[e]);Object.defineProperty(this,"name",{enumerable:!0,configurable:!1,value:a}),Object.defineProperty(this,"dependencies",{enumerable:!0,configurable:!1,value:b}),Object.defineProperty(this,"constructor",{enumerable:!0,configurable:!1,value:c}),Object.defineProperty(this,"$$dynamic",{enumerable:!1,configurable:!1,value:d||!1}),Object.defineProperty(this,"$$script",{enumerable:!1,configurable:!1,get:function(){return"Esquire.define("+JSON.stringify(this.name)+","+JSON.stringify(this.dependencies)+","+c.toString()+");"}}),Object.freeze(this)}function k(a){j.call(this,a,["$global"],function(a){function b(a,c,d){if(!d&&a in c)return c[a];var e=["Ms","ms","Moz","moz","WebKit","webkit"];for(var f in e){var g=e[f]+a;if(g in c)return c[g]}return a[0]!==a[0].toUpperCase()?b(a[0].toUpperCase()+a.substring(1),c,!0):void 0}function c(a,d){if(!d)return void 0;if(!a)return void 0;switch(a.length){case 0:return void 0;case 1:return b(a[0],d);default:return c(a.slice(1),b(a[0],d))}}return c(this.name.substring(8).split("."),a)},!0)}function l(a){j.call(this,a,[],function(){throw new f("The constructor for '"+a+"' should not be called'")},!0)}function m(a){if(!a)return[];for(var b=[],c=0;c<a.length;c++){var d=a[c];if("string"==typeof d)b.push(d);else if("function"==typeof d)b.push(d);else if(Array.isArray(d))b=b.concat(m(d));else{if("object"!=typeof d||"number"!=typeof d.length)throw new f("Invalid dependency: "+JSON.stringify(d));b=b.concat(m(d))}}return b}function n(){var a=m(arguments),b={arguments:[],"function":null};if(!a.length)return b;"function"==typeof a[a.length-1]&&(b.function=a.splice(-1)[0]);for(var c in a){var d=a[c];if("string"!=typeof d)throw new f("Found "+typeof d+" but needed string: "+d);b.arguments.push(d)}return b}function o(a){return/^\$global[\/\.].+/.test(a)}function p(a){return o(a)?"$global/"+a.substring(8):a}function q(){if(1==arguments.length&&arguments[0].name&&arguments[0].constructor){var a=arguments[0];return q(a.name,a.dependencies||[],a.constructor)}var b,c,d=n(arguments),e=[];if(!d.arguments.length)throw new f("No module name specified");if(b=p(d.arguments.splice(0,1)[0]),e=d.arguments,y[b])throw new f("Module '"+b+"' already defined");if(!d.function)throw new f("No constructor function specified for module '"+b+"'");c=d.function;var a=y[b]=new j(b,e,c);for(var g in x.define)try{x.define[g](a)}catch(h){console.error("Error notifying listener",h)}return z[a.name]&&(z[a.name].resolve(a),delete z[a.name]),a}function r(a){if(a instanceof j)return a;if("string"==typeof a){if(y[a])return y[a];if(z[a])return z[a].promise;if(o(a))return y[a]=new k(a);var b=new d(v/2,new g(a));return z[a]=b,b.promise}return w.reject("Unable to resolve module of type "+typeof a)}function s(a){if(!(a instanceof j))return w.reject("Unable to resolve module of type "+typeof a);if(0==a.dependencies.length)return A;var b=[];for(var c in a.dependencies){var d=a.dependencies[c];b.push(r(d))}return w.all(b)}function t(a,b){if(!(a instanceof j))return w.reject("Unable to resolve module of type "+typeof a);var c=[];for(var d in a.dependencies){var e=a.dependencies[d];if(!b[e]){var f=b[e]=r(e);c.push(w.resolve(f).then(function(a){return b[e]=a,t(a,b)}))}}return w.all(c).then(function(){return b})}function u(a){function c(a,b,e){if(e=e.slice(0),null!=a.name&&e.push(a.name),k[a.name])return k[a.name];50>b&&(b=50);var f=new d(b,"Timeout waiting for module '"+a.name+"'");return a.name&&!a.$$dynamic&&(k[a.name]=f.promise),s(a).then(function(d){var f=[];for(var g in d){var h=d[g],j=e.indexOf(h.name);if(j>=0){var l=e.slice(j);throw new i(l)}f.push(k[h.name]?k[h.name]:c(h,b-5,e))}return w.all(f).then(function(b){return a.constructor.apply(a,b)})}).then(function(b){a.name&&!a.$$dynamic&&(k[a.name]=b),f.resolve(b)},function(b){f.reject(new h(a.name,b))}),f.promise}function e(){return 1==arguments.length&&"string"==typeof arguments[0]?g([arguments[0]],function(a){return a}):g(arguments,function(){for(var a=[],b=0;b<arguments.length;b++)a.push(arguments[b]);return a})}function g(){var b=n(arguments);if(!b.function)throw new f("Callback for injection unspecified");var d=new j(null,b.arguments,b.function);try{return c(d,a,[])}catch(e){return w.reject(e)}}if(!(this instanceof u))return new u(w);if(void 0===a)a=v;else{if(a=Number(a),0/0===a)throw new f("Timeout is not a number");if(100>a)throw new f("Timeout must be greater or equal than 100ms")}var k={$global:b,$esquire:this,$promise:w,$deferred:d};Object.defineProperties(this,{inject:{enumerable:!0,configurable:!1,value:g},require:{enumerable:!0,configurable:!1,value:e}})}b.console||(b.console={}),b.console.error||(b.console.error=function(){}),b.console.warn||(b.console.warn=function(){}),b.console.log||(b.console.log=function(){}),b.console.info||(b.console.info=function(){}),b.console.debug||(b.console.debug=function(){}),c.prototype=Object.create(Object.prototype),c.prototype.constructor=c,c.prototype.name="Deferring",d.prototype=Object.create(c.prototype),d.prototype.constructor=d,d.prototype.name="Deferred",e.prototype=Object.create(Object.prototype),e.prototype.constructor=e,e.prototype.name="Promise",Object.defineProperty(e,"all",{enumerable:!0,configurable:!1,value:function(a){if(!Array.isArray(a))return e.reject(new TypeError("Invalid argument"));var b=new d;if(0==a.length)return b.resolve([]),b.promise;for(var c=new Array(a.length),f=a.length,g=0;g<a.length;g++)!function(d){var e=a[d];e&&"function"==typeof e.then?e.then(function(a){c[d]=a,0==--f&&b.resolve(c)},function(a){b.reject(a)}):(c[d]=e,0==--f&&b.resolve(c))}(g);return b.promise}}),Object.defineProperty(e,"race",{enumerable:!0,configurable:!1,value:function(a){if(!Array.isArray(a))return e.reject(new TypeError("Invalid argument"));var b=new d;for(var c in a){var f=a[c];f&&"function"==typeof f.then?f.then(function(a){b.resolve(a)},function(a){b.reject(a)}):b.resolve(f)}return b.promise}}),Object.defineProperty(e,"resolve",{enumerable:!0,configurable:!1,value:function(a){var b=new d;return a&&"function"==typeof a.then?a.then(function(a){b.resolve(a)},function(a){b.reject(a)}):b.resolve(a),b.promise}}),Object.defineProperty(e,"reject",{enumerable:!0,configurable:!1,value:function(a){var b=new d;return b.reject(a),b.promise}}),f.prototype=Object.create(Error.prototype),f.prototype.constructor=f,f.prototype.name="EsquireError",g.prototype=Object.create(f.prototype),g.prototype.constructor=g,g.prototype.name="NoModuleError",h.prototype=Object.create(f.prototype),h.prototype.constructor=h,h.prototype.name="InjectionError",i.prototype=Object.create(f.prototype),i.prototype.constructor=i,i.prototype.name="CircularDependencyError",k.prototype=Object.create(j.prototype),k.prototype.constructor=k,k.prototype.name="GlobalModule",l.prototype=Object.create(j.prototype),l.prototype.constructor=l,l.prototype.name="InternalModule";var v=2e3,w=b.Promise||e,x={define:[]},y={$global:new l("$global"),$esquire:new l("$esquire"),$promise:new l("$promise"),$deferred:new l("$deferred")},z={},A=w.resolve([]);if(Object.defineProperties(u,{$$script:{enumerable:!1,configurable:!1,value:a.toString()},$$normalize:{enumerable:!1,configurable:!1,value:n},$$Promise:{enumerable:!1,configurable:!1,value:e},$$Deferred:{enumerable:!1,configurable:!1,value:d},define:{enumerable:!0,configurable:!1,value:q},resolve:{enumerable:!0,configurable:!1,value:function(a,b){if("string"==typeof a)return w.resolve(r(a)).then(function(a){return u.resolve(a,b)});if(!(a instanceof j))throw new TypeError("Must be invoked with Module or module name");return b?t(a,{}):s(a).then(function(a){var b={};for(var c in a)b[a[c].name]=a[c];return b})}},timeout:{enumerable:!0,configurable:!1,get:function(){return v},set:function(a){if(a=Number(a),0/0===a)throw new f("Timeout is not a number");if(100>a)throw new f("Timeout must be greater or equal than 100ms");v=a}},modules:{enumerable:!0,configurable:!1,get:function(){var a={};for(var b in y)a[b]=y[b];return Object.freeze(a)}},module:{enumerable:!0,configurable:!1,value:function(a){return w.resolve(r(a))}},on:{enumerable:!0,configurable:!1,value:function(a,b){if("string"!=typeof a)throw new f("Event name must be a string");if("function"!=typeof b)throw new f("Listener must be a function");return"define"===a&&x.define.push(b),u}}}),b.Esquire)throw new Error("Esquire already defined in global scope");b.Esquire=u;var B=new u;b.esquire=function(){if(0==arguments.length)throw new f("No dependencies/callback specified");var a=n(arguments);return a.function?B.inject(a.arguments,a.function):B.require(1==arguments.length&&"string"==typeof arguments[0]?arguments[0]:a.arguments)}}(function(){try{return window}catch(a){return global}}());
{
"name": "esquire",
"version": "1.0.2",
"version": "1.1.0",
"main": "node-adapter.js",

@@ -5,0 +5,0 @@ "description": "Esquire: asynchronous injection framework",

@@ -22,19 +22,5 @@ 'use strict';

/**
* Create a new {@link Deferred} instance.
*
* @class module:$deferred.Deferred
* @example -
* Esquire.define("myModule", ['$deferred'], function(Deferred) {
* var deferred = new Deferred();
* // ....
* return deferred.promise;
* });
*/
var deferredId = 0;
function Deferred(onSuccess, onFailure) {
/* Internal "Deferring" class, we'll expose "Deferred" below */
function Deferring(onSuccess, onFailure) {
/* Proper construction */
if (!(this instanceof Deferred)) return new Deferred(onSuccess, onFailure);
/* Statuses: 0 -> pending, -1 -> rejected, 1 -> resolved */

@@ -57,4 +43,2 @@ var status = 0;

Object.defineProperties(this, {
"$$id": { enumerable: false, configurable: false, value: (++deferredId) },
/**

@@ -126,5 +110,4 @@ * Resolve this instance's derived {@link Deferred#promise promise} with

Object.defineProperties(new Object(), {
"$$id": { enumerable: false, configurable: false, value: deferred.$$id },
"then": { enumerable: true, configurable: false, value: function(onSuccess, onFailure) {
var chained = new Deferred(onSuccess, onFailure);
var chained = new Deferring(onSuccess, onFailure);
if (status == 0) {

@@ -146,3 +129,58 @@ chain.push(chained);

/* Prototype, constructor and name */
Deferred.prototype = Object.create(Object.prototype);
Deferring.prototype = Object.create(Object.prototype);
Deferring.prototype.constructor = Deferring;
Deferring.prototype.name = 'Deferring';
/**
* Create a new {@link Deferred} instance.
*
* @param {number} [timeout] The (optional) timeout after which this
* {@link Deferred} will be automatically rejected.
* This must be a number greater or equal to zero.
* @param {*} [rejection] The reason with which this {@link Deferred} will be
* automatically rejected after the `timeout`. If this
* parameter is a `string` then it will be used to
* construct an {@link Error} using the string as its
* message. If the parameter is `null` or `undefined`
* a generic {@link Error} will be used.
* @class module:$deferred.Deferred
* @example -
* Esquire.define("myModule", ['$deferred'], function(Deferred) {
* var deferred = new Deferred();
* // ....
* return deferred.promise;
* });
*/
function Deferred(timeout, rejection) {
/* Proper construction */
if (!(this instanceof Deferred)) return new Deferred(timeout, rejection);
if (timeout === undefined) {
Deferring.call(this);
} else if ((typeof(timeout) === 'number') && (timeout >= 0)) {
if (rejection == null) rejection = new Error("Timeout waiting for resolution/rejection");
else if (typeof(rejection) === 'string') rejection = new Error(rejection);
var deferred = this;
var timeoutId = global.setTimeout(function() {
deferred.reject(rejection);
}, timeout);
Deferring.call(this, function(success) {
global.clearTimeout(timeoutId);
return success;
}, function(failure) {
global.clearTimeout(timeoutId);
throw failure;
});
} else {
throw new TypeError("Deferred constructor must be called with a non-negative number")
}
}
/* Prototype, constructor and name */
Deferred.prototype = Object.create(Deferring.prototype);
Deferred.prototype.constructor = Deferred;

@@ -192,3 +230,2 @@ Deferred.prototype.name = 'Deferred';

Object.defineProperties(this, {
'$$id': { enumerable: false, configurable: false, value: deferred.$$id },

@@ -427,18 +464,27 @@ /**

/* When modules are not found */
function NoModuleError(name, dependencyStack) {
EsquireError.call(this, "Module '" + name + "' not found", dependencyStack);
function NoModuleError(name) {
EsquireError.call(this, "Module '" + name + "' not found");
};
/* When circular dependencies are detected */
function ModuleConstructorError(name, cause, dependencyStack) {
EsquireError.call(this, "Module '" + name + "' failed to initialize", dependencyStack);
function InjectionError(name, cause) {
var message = name ? "Error instantiating '" + name + "' module" : "Injection failed";
this.$$message = message;
if (cause) {
this.message = this.message + " [Cause: " + (cause.message ? cause.message : "[no message]") + "]";
this.originalCause = cause.originalCause || cause;
this.cause = cause;
}
for (var error = cause; error != null; error = error.cause) {
message += "\n- Cause: " + (error.$$message || error.message || "[no message]");
}
EsquireError.call(this, message);
};
/* When circular dependencies are detected */
function CircularDependencyError(name, dependencyStack) {
EsquireError.call(this, "Module '" + name + "' has circular dependencies", dependencyStack);
function CircularDependencyError(dependencies) {
var message = "Detected circular dependency in ";
for (var i in dependencies) message += dependencies[i] + " -> ";
message += dependencies[0];
this.$$message = message;
EsquireError.call(this, message);
};

@@ -454,5 +500,5 @@

ModuleConstructorError.prototype = Object.create(EsquireError.prototype);
ModuleConstructorError.prototype.constructor = ModuleConstructorError;
ModuleConstructorError.prototype.name = 'ModuleConstructorError';
InjectionError.prototype = Object.create(EsquireError.prototype);
InjectionError.prototype.constructor = InjectionError;
InjectionError.prototype.name = 'InjectionError';

@@ -591,2 +637,8 @@ CircularDependencyError.prototype = Object.create(EsquireError.prototype);

/* The global timeout */
var globalTimeout = 2000;
/* Promise implementation */
var Promise = global.Promise || PromiseImpl;
/* Listeners (should contain only "define") */

@@ -603,2 +655,5 @@ var listeners = { define: [] };

/* Deferred modules */
var deferredModules = {};
/* Flatten an array, or array of array, for aguments */

@@ -682,36 +737,4 @@ function flatten(iterable) {

/**
* Define a {@link Module} as available to Esquire
*
* @function Esquire.define
* @example -
* Esquire.define('foo', ['modA', 'depB'], function(a, b) {
* // 'a' will be an instance of 'modA'
* // 'b' will be an instance of 'depB'
* function Foo(aInstance, bInstance) {
* // ...
* };
* return new Foo(a, b);
* });
*
* @example Definition with a {@link Module}-like object also works.
* Esquire.define({
* name: 'foo',
* dependencies: ['modA', 'depB'],
* constructor: function(a, b) {
* // ...
* }
* });
*
* @param {string} name - The name of the module to define.
* @param {string[]} [dependencies] - An array of required module names whose
* instances will be passed to the
* `constructor(...)` method.
* @param {function} constructor - A function that will be invoked once per
* each {@link Esquire} instance. Its return
* value will be injected in any other module
* requiring this module as a dependency.
* @returns {Module} The new {@link Module} created by this call.
*/
function define() {
/* Module definition */
function defineModule() {

@@ -723,5 +746,5 @@ /* Object based definition */

var module = arguments[0];
return define(module.name,
module.dependencies || [], //optional
module.constructor);
return defineModule(module.name,
module.dependencies || [], //optional
module.constructor);
}

@@ -759,3 +782,2 @@

var module = modules[name] = new Module(name, dependencies, constructor);
if (module.$$dynamic) return module;

@@ -771,36 +793,41 @@ /* Notify all "define" listeners */

/* Resolve our deferred if someone was waiting for this */
if (deferredModules[module.name]) {
deferredModules[module.name].resolve(module);
delete deferredModules[module.name];
}
/* Return our defined module */
return module;
};
/**
* Return an array of {@link Module} dependencies for a {@link Module}.
*
* @function Esquire.resolve
* @param {string|Module} module - The {@link Module} (or its name) for which
* dependendencies should be resolved.
* @param {boolean} [transitive] - If `true` all direct and indirect
* _(transitive)_ dependencies will be
* resolved. If `false` or _undefined_, only
* the {@link Module}'s explicit dependencies
* will be resolved.
* @returns {Module[]} An array of all required {@link Module}s.
*/
function resolve(module, transitive, dependencyStack) {
/* Return a module (if known) or a promise to get it */
function moduleOrPromise(module) {
if (module instanceof Module) return module;
/* Check parameters */
if (!dependencyStack) dependencyStack = [];
if (!module) throw new EsquireError("No module or module name specified");
if (typeof(module) === 'string') {
if (modules[module]) {
module = modules[module];
} else {
throw new NoModuleError(name, dependencyStack);
}
if (modules[module]) return modules[module];
if (deferredModules[module]) return deferredModules[module].promise;
if (isGlobal(module)) return modules[module] = new GlobalModule(module);
/* Half timeout, so this will take precedence on "create(...)" */
var deferred = new Deferred(globalTimeout / 2, new NoModuleError(module));
deferredModules[module] = deferred;
return deferred.promise;
}
/* Check recursion */
if (dependencyStack.indexOf(module.name) >= 0) {
throw new CircularDependencyError(module.name, dependencyStack);
/* Not a module, not a string... Foo! */
return Promise.reject("Unable to resolve module of type " + typeof(module));
}
/* Resolve direct dependencies for the specified module */
var emptyPromise = Promise.resolve([]);
function resolveDependencies(module) {
if (!(module instanceof Module)) {
return Promise.reject("Unable to resolve module of type " + typeof(module));
}
if (module.dependencies.length == 0) return emptyPromise;
/* The dependencies to return */

@@ -810,37 +837,36 @@ var moduleDependencies = [];

/* Recurse into module */
dependencyStack.push(module.name);
for (var i in module.dependencies) {
/* Check this module's dependency */
var dependencyName = module.dependencies[i];
var dependency = modules[dependencyName];
if (dependency) {
/* Add the dependency */
moduleDependencies.push(dependency);
moduleDependencies.push(moduleOrPromise(dependencyName));
}
/* If transitive, recurse */
if (transitive) {
var dependencies = resolve(dependency, dependencyStack);
for (var name in dependencies) {
moduleDependencies.push(dependencies[name]);
}
}
} else if (isGlobal(dependencyName)) {
return Promise.all(moduleDependencies);
}
/* Global "any" dependency not in modules */
moduleDependencies.push(new GlobalModule(dependencyName));
/* Resolve ALL dependencies, transitively */
function resolveTransitiveDependencies(module, hash) {
if (!(module instanceof Module)) {
return Promise.reject("Unable to resolve module of type " + typeof(module));
}
} else {
var promises = [];
for (var i in module.dependencies) {
var dependencyName = module.dependencies[i];
/* Dependency not found */
throw new NoModuleError(module.dependencies[i], dependencyStack);
}
}
/* Ignore already resolved dependencies */
if (hash[dependencyName]) continue;
/* Pop ourselves out */
dependencyStack.pop();
/* Get a module or a promise to it and put it in the hash NOW! */
var dependency = hash[dependencyName] = moduleOrPromise(dependencyName);
/* Return our resolved module dependencies */
return moduleDependencies;
/* Transitively resolve the dependency */
promises.push(Promise.resolve(dependency).then(function(dependency) {
hash[dependencyName] = dependency;
return resolveTransitiveDependencies(dependency, hash);
}));
}
return Promise.all(promises).then(function() {
return hash;
});
}

@@ -862,2 +888,4 @@

* @class Esquire
* @public
* @global
* @classdesc

@@ -878,11 +906,9 @@ * {@link Esquire.modules Modules} are _static_ and shared amongst

function Esquire(timeout) {
/* Proper construction */
if (!(this instanceof Esquire)) return new Esquire(Promise);
/* Promise implementation */
var Promise = global.Promise || PromiseImpl;
/* Timeout */
if (timeout === undefined) {
timeout = 2000;
timeout = globalTimeout;
} else {

@@ -906,3 +932,5 @@ timeout = Number(timeout);

/* Create a new instance from a defined module */
function create(module, dependencyStack) {
function create(module, timeout, dependencyStack) {
dependencyStack = dependencyStack.slice(0);
if (module.name != null) dependencyStack.push(module.name);

@@ -912,27 +940,7 @@ /* Already in cache? Why even bother? */

/* Calculate the module's direct dependencies */
var dependencies = resolve(module, false, dependencyStack);
var parameters = [];
/* Create an expiring Deferred, shortening the timeout */
if (timeout < 50) timeout = 50;
var deferred = new Deferred(timeout, "Timeout waiting for module '" + module.name + "'");
for (var i in dependencies) {
var dependency = dependencies[i];
/* Already in cache? Just push it! */
if (cache[dependency.name]) {
parameters.push(cache[dependency.name]);
} else {
/* Not in cache, create (recursively) the dependency */
dependencyStack.push(module.name);
parameters.push(create(dependency, dependencyStack));
dependencyStack.pop();
}
}
/* Clone dependency stack for errors */
var cloneStack = dependencyStack.slice(0);
/* Create a deferred and *IMMEDIATELY* cache the promise */
var deferred = new Deferred();
/* ... and *IMMEDIATELY* cache the promise */
if (module.name && (! module.$$dynamic)) {

@@ -942,55 +950,39 @@ cache[module.name] = deferred.promise;

/* Set a timeout, after which module construction will fail */
var timeoutMillis = timeout - (cloneStack.length * 5);
if (timeoutMillis < 50) timeoutMillis = 50;
var timeoutId = global.setTimeout(function() {
var error = new EsquireError("Timeout reached waiting for module '" + module.name + "'", cloneStack);
deferred.reject(error);
}, timeoutMillis);
/* Calculate the module's direct dependencies */
resolveDependencies(module).then(function(dependencies) {
var parameters = [];
/* Clear timeouts and resolve */
var resolveCallback = function(success) {
global.clearTimeout(timeoutId);
/* Prepare parameters, either from cache or new creations */
for (var i in dependencies) {
var dependency = dependencies[i];
/* Cache the resolved value */
if (module.name && (! module.$$dynamic)) {
cache[module.name] = success;
/* Check for circular dependencies */
var circularIndex = dependencyStack.indexOf(dependency.name);
if (circularIndex >= 0) {
var circularDependencies = dependencyStack.slice(circularIndex);
throw new CircularDependencyError(circularDependencies);
}
if (cache[dependency.name]) {
parameters.push(cache[dependency.name]);
} else {
parameters.push(create(dependency, timeout - 5, dependencyStack));
}
}
/* Resolve the deferred */
deferred.resolve(success);
};
/* When all parameters have been resolved... */
return Promise.all(parameters).then(function(parameters) {
return module.constructor.apply(module, parameters);
});
})
/* Clear timeouts and reject */
var rejectCallback = function(failure) {
global.clearTimeout(timeoutId);
deferred.reject(failure);
};
/* Cache and resolve, or reject */
.then(function(created) {
if (module.name && (! module.$$dynamic)) cache[module.name] = created;
deferred.resolve(created);
}, function(failure) {
deferred.reject(new InjectionError(module.name, failure));
});
/* When all parameters have been resolved... */
Promise.all(parameters).then(
function(success) {
try {
/* ... then call the constructor */
var result = module.constructor.apply(module, success);
if (result && (typeof(result.then) === 'function')) {
result.then(resolveCallback, function(failure) {
var error = new ModuleConstructorError(module.name, failure, cloneStack);
rejectCallback(error);
});
} else {
resolveCallback(result);
}
} catch (error) {
/* Errors from invoking the constructor head down here */
rejectCallback(new ModuleConstructorError(module.name, error, cloneStack));
}
}, function(failure) {
rejectCallback(failure);
}
);
/* Return the promise */
/* Return the deferred promise */
return deferred.promise;

@@ -1108,3 +1100,3 @@

try {
return create(module, []);
return create(module, timeout, []);
} catch (error) {

@@ -1135,8 +1127,100 @@ return Promise.reject(error);

/* Public methods from above */
"define": { enumerable: true, configurable: false, value: define },
"resolve": { enumerable: true, configurable: false, value: resolve },
/**
* Define a {@link Module} as available to Esquire
*
* @function Esquire.define
* @example -
* Esquire.define('foo', ['modA', 'depB'], function(a, b) {
* // 'a' will be an instance of 'modA'
* // 'b' will be an instance of 'depB'
* function Foo(aInstance, bInstance) {
* // ...
* };
* return new Foo(a, b);
* });
*
* @example Definition with a {@link Module}-like object also works.
* Esquire.define({
* name: 'foo',
* dependencies: ['modA', 'depB'],
* constructor: function(a, b) {
* // ...
* }
* });
*
* @param {string} name - The name of the module to define.
* @param {string[]} [dependencies] - An array of required module names
* whose instances will be passed to the
* `constructor(...)` method.
* @param {function} constructor - A function that will be invoked once per
* each {@link Esquire} instance. Its return
* value will be injected in any other module
* requiring this module as a dependency.
* @returns {Module} The new {@link Module} created by this call.
*/
"define": { enumerable: true, configurable: false, value: defineModule },
/**
* An unmodifiable dictionary of all {@link Module}s known by
* Return an array of {@link Module} dependencies for a {@link Module}.
*
* @function Esquire.resolve
* @param {string|Module} module - The {@link Module} (or its name) for which
* dependendencies should be resolved.
* @param {boolean} [transitive] - If `true` all direct and indirect
* _(transitive)_ dependencies will be
* resolved. If `false` or _undefined_, only
* the {@link Module}'s explicit dependencies
* will be resolved.
* @returns {Promise} An {@link Promise} to a dictionary of all required
* {@link Module}s keyed by their `name`.
*/
"resolve": { enumerable: true, configurable: false, value: function(module, transitive) {
if (typeof(module) === 'string') {
return Promise.resolve(moduleOrPromise(module)).then(function(module) {
return Esquire.resolve(module, transitive);
})
} else if (!(module instanceof Module)) {
throw new TypeError("Must be invoked with Module or module name");
}
if (transitive) return resolveTransitiveDependencies(module, {});
else return resolveDependencies(module).then(function(dependencies) {
var hash = {};
for (var i in dependencies) {
hash[dependencies[i].name] = dependencies[i];
}
return hash;
});
return resolveTransitiveDependencies(module, {});
}},
/**
* The global timeout (in milliseconds) to wait for module definition
* and injection.
*
* Defaults to _2000 ms_ (2 seconds), can not be less than _100 ms_.
*
* @static
* @member {number} timeout
* @memberof Esquire
*/
"timeout": { enumerable: true, configurable: false,
get: function() {
return globalTimeout;
},
set: function(timeout) {
timeout = Number(timeout);
if (timeout === NaN) {
throw new EsquireError("Timeout is not a number");
} else if (timeout < 100) {
throw new EsquireError("Timeout must be greater or equal than 100ms");
} else {
globalTimeout = timeout;
}
}
},
/**
* An unmodifiable dictionary of all {@link Module}s _currently_ known by
* {@link Esquire}.

@@ -1171,4 +1255,4 @@ *

/**
* Return the {@link Module} associated with the given `name` as defined
* in {@link Esquire} or `null`.
* Returns a {@link Promise} to the {@link Module} associated with the
* given `name`.
*

@@ -1182,6 +1266,3 @@ * @static

"module": { enumerable: true, configurable: false, value: function(name) {
name = globalName(name);
if (name in modules) return modules[name];
if (isGlobal(name)) return new GlobalModule(name);
return null;
return Promise.resolve(moduleOrPromise(name));
}},

@@ -1188,0 +1269,0 @@

@@ -74,2 +74,5 @@ 'use strict';

*
* **NOTE**: This document refers to the _browser_ based implementation, under
* _Node.JS_ this method works slightly differently.
*
* @static

@@ -100,7 +103,3 @@ * @function load

/* Our then-able for notifications */
var thenable = new Esquire.$$Deferred(function(success) {
return success;
}, function(failure) {
throw failure;
});
var thenable = new Esquire.$$Deferred();

@@ -107,0 +106,0 @@ /* Mark the number of remainig scripts on the then-able */

@@ -157,2 +157,61 @@ 'use strict';

/* ==================================================================== */
promises("should timeout with no rejection specified", function(done) {
var deferred = new Deferred(10);
setTimeout(function() {
deferred.resolve("this is bad...");
}, 20)
return deferred.promise.then(wrap(done, function(result) {
throw new Error("Should not resolve");
}), function(failure) {
expect(failure).to.be.instanceof(Error);
expect(failure.message).to.be.equal('Timeout waiting for resolution/rejection');
})
});
/* ==================================================================== */
promises("should timeout with a rejection message", function(done) {
// 0, not null but also not truthy...
var deferred = new Deferred(10, "Fail, deferred, FAIL!");
setTimeout(function() {
deferred.resolve("this is bad...");
}, 20)
return deferred.promise.then(wrap(done, function(result) {
throw new Error("Should not resolve");
}), function(failure) {
expect(failure).to.be.instanceof(Error);
expect(failure.message).to.be.equal('Fail, deferred, FAIL!');
})
});
/* ==================================================================== */
promises("should timeout with a specific rejection", function(done) {
// 0, not null but also not truthy...
var deferred = new Deferred(10, 0);
setTimeout(function() {
deferred.resolve("this is bad...");
}, 20)
return deferred.promise.then(wrap(done, function(result) {
throw new Error("Should not resolve");
}), function(failure) {
expect(failure).to.be.a('number');
expect(failure).to.be.equal(0);
})
});
});

@@ -159,0 +218,0 @@ }

@@ -192,2 +192,13 @@ 'use strict';

promises('should eventually inject a module returning a promise', function() {
return new Esquire().require("module-g")
.then(function(success) {
expect(success).to.equal("value-g");
})
});
/* ==================================================================== */
promises('should fail on construction error', function() {

@@ -200,3 +211,5 @@

expect(error).to.be.instanceof(Error);
expect(error.message).to.be.equal('Esquire: Module \'module-e\' failed to initialize [Cause: This module always fails]');
expect(error.message).to.be.equal("Esquire: Injection failed\n- Cause: Error instantiating 'module-e' module\n- Cause: This module always fails");
expect(error.originalCause).to.be.instanceof(Error);
expect(error.originalCause.message).to.be.equal('This module always fails');
})

@@ -206,3 +219,3 @@

promises('should fail on depending on failing module', function() {
promises('should fail depending on failing module', function() {

@@ -214,3 +227,5 @@ return new Esquire().require("module-f")

expect(error).to.be.instanceof(Error);
expect(error.message).to.be.equal('Esquire: Module \'module-e\' failed to initialize resolving -> module-f [Cause: This module always fails]');
expect(error.message).to.be.equal("Esquire: Injection failed\n- Cause: Error instantiating 'module-f' module\n- Cause: Error instantiating 'module-e' module\n- Cause: This module always fails");
expect(error.originalCause).to.be.instanceof(Error);
expect(error.originalCause.message).to.be.equal('This module always fails');
})

@@ -220,7 +235,12 @@

promises('should eventually inject a module returning a promise', function() {
promises('should not inject a module returning a rejected promise', function() {
return new Esquire().require("module-g")
return new Esquire().require("module-h")
.then(function(success) {
expect(success).to.equal("value-g");
throw new Error("Should not succeed")
}, function(error) {
expect(error).to.be.instanceof(Error);
expect(error.message).to.be.equal("Esquire: Injection failed\n- Cause: Error instantiating 'module-h' module\n- Cause: value-h");
expect(error.originalCause).to.be.instanceof(Error);
expect(error.originalCause.message).to.be.equal('value-h');
})

@@ -230,12 +250,12 @@

promises('should not inject a module returning a rejected promise', function() {
promises('should time out waiting injection', function() {
return new Esquire().require("module-h")
return new Esquire(100).require("module-i")
.then(function(success) {
throw new Error("Should not succeed")
throw new Error("Should not succeed");
}, function(error) {
expect(error).to.be.instanceof(Error);
expect(error.message).to.be.equal('Esquire: Module \'module-h\' failed to initialize [Cause: value-h]');
expect(error.cause).to.be.instanceof(Error);
expect(error.cause.message).to.be.equal('value-h');
expect(error.message).to.be.equal("Esquire: Injection failed\n- Cause: Timeout waiting for module 'module-i'");
expect(error.originalCause).to.be.instanceof(Error);
expect(error.originalCause.message).to.be.equal("Timeout waiting for module 'module-i'");
})

@@ -245,2 +265,4 @@

/* ==================================================================== */
promises('should expose a $global module', function() {

@@ -266,14 +288,2 @@

promises('should time out waiting injection', function() {
return new Esquire(100).require("module-i")
.then(function(success) {
throw new Error("Should not succeed");
}, function(error) {
expect(error).to.be.instanceof(Error);
expect(error.message).to.be.equal('Esquire: Timeout reached waiting for module \'module-i\'');
})
});
});

@@ -423,3 +433,3 @@

Esquire.define(name, function() {
var module = Esquire.define(name, function() {
expect(arguments.length).to.be.equal(0);

@@ -430,2 +440,7 @@ return "module " + name;

return esquire(name, function(dependency) {
expect(module).to.be.a('object');
expect(module.name).to.be.equal(name);
expect(module.dependencies).to.be.deep.equal([]);
expect(module.constructor).to.be.a('function');
return "return " + dependency;

@@ -441,3 +456,3 @@ }).then(function(result) {

Esquire.define(name, "module-a", function(a) {
var module = Esquire.define(name, "module-a", function(a) {
return "module " + name + ":" + a;

@@ -447,2 +462,7 @@ });

return esquire(name, function(dependency) {
expect(module).to.be.a('object');
expect(module.name).to.be.equal(name);
expect(module.dependencies).to.be.deep.equal(['module-a']);
expect(module.constructor).to.be.a('function');
return "return " + dependency;

@@ -458,3 +478,3 @@ }).then(function(result) {

Esquire.define(name, ["module-a", "module-b"], function(a, b) {
var module = Esquire.define(name, ["module-a", "module-b"], function(a, b) {
return "module " + name + ":" + a + "/" + b;

@@ -464,2 +484,7 @@ });

return esquire(name, function(dependency) {
expect(module).to.be.a('object');
expect(module.name).to.be.equal(name);
expect(module.dependencies).to.be.deep.equal(['module-a', 'module-b']);
expect(module.constructor).to.be.a('function');
return "return " + dependency;

@@ -475,3 +500,3 @@ }).then(function(result) {

Esquire.define(name, ["module-a", "module-b", function(a, b) {
var module = Esquire.define(name, ["module-a", "module-b", function(a, b) {
return "module " + name + ":" + a + "/" + b;

@@ -481,2 +506,7 @@ }]);

return esquire(name, function(dependency) {
expect(module).to.be.a('object');
expect(module.name).to.be.equal(name);
expect(module.dependencies).to.be.deep.equal(['module-a', 'module-b']);
expect(module.constructor).to.be.a('function');
return "return " + dependency;

@@ -494,3 +524,3 @@ }).then(function(result) {

Esquire.define({
var module = Esquire.define({
name: name,

@@ -504,2 +534,7 @@ constructor: function() {

return esquire(name, function(dependency) {
expect(module).to.be.a('object');
expect(module.name).to.be.equal(name);
expect(module.dependencies).to.be.deep.equal([]);
expect(module.constructor).to.be.a('function');
return "return " + dependency;

@@ -515,3 +550,3 @@ }).then(function(result) {

Esquire.define({
var module = Esquire.define({
name: name,

@@ -526,2 +561,7 @@ dependencies: [],

return esquire(name, function(dependency) {
expect(module).to.be.a('object');
expect(module.name).to.be.equal(name);
expect(module.dependencies).to.be.deep.equal([]);
expect(module.constructor).to.be.a('function');
return "return " + dependency;

@@ -537,3 +577,3 @@ }).then(function(result) {

Esquire.define({
var module = Esquire.define({
name: name,

@@ -548,2 +588,7 @@ dependencies: 'module-a',

return esquire(name, function(dependency) {
expect(module).to.be.a('object');
expect(module.name).to.be.equal(name);
expect(module.dependencies).to.be.deep.equal(['module-a']);
expect(module.constructor).to.be.a('function');
return "return " + dependency;

@@ -559,3 +604,3 @@ }).then(function(result) {

Esquire.define({
var module = Esquire.define({
name: name,

@@ -570,2 +615,7 @@ dependencies: ['module-a', 'module-b'],

return esquire(name, function(dependency) {
expect(module).to.be.a('object');
expect(module.name).to.be.equal(name);
expect(module.dependencies).to.be.deep.equal(['module-a', 'module-b']);
expect(module.constructor).to.be.a('function');
return "return " + dependency;

@@ -600,40 +650,110 @@ }).then(function(result) {

var modules = Esquire.modules;
expect(modules['circular-a'] ).to.equal(Esquire.module('circular-a'));
expect(modules['circular-b'] ).to.equal(Esquire.module('circular-b'));
expect(modules['circular-c'] ).to.equal(Esquire.module('circular-c'));
expect(modules['circular-d'] ).to.equal(Esquire.module('circular-d'));
expect(modules['circular-e'] ).to.equal(Esquire.module('circular-e'));
expect(modules['circular-f'] ).to.equal(Esquire.module('circular-f'));
expect(modules['circular-g'] ).to.equal(Esquire.module('circular-g'));
expect(modules['circular-self']).to.equal(Esquire.module('circular-self'));
expect(modules['module-a'] ).to.equal(Esquire.module('module-a'));
expect(modules['module-b'] ).to.equal(Esquire.module('module-b'));
expect(modules['circular-a'] ).to.equal(Esquire.modules['circular-a']);
expect(modules['circular-b'] ).to.equal(Esquire.modules['circular-b']);
expect(modules['circular-c'] ).to.equal(Esquire.modules['circular-c']);
expect(modules['circular-d'] ).to.equal(Esquire.modules['circular-d']);
expect(modules['circular-e'] ).to.equal(Esquire.modules['circular-e']);
expect(modules['circular-f'] ).to.equal(Esquire.modules['circular-f']);
expect(modules['circular-g'] ).to.equal(Esquire.modules['circular-g']);
expect(modules['circular-self']).to.equal(Esquire.modules['circular-self']);
expect(modules['module-a'] ).to.equal(Esquire.modules['module-a']);
expect(modules['module-b'] ).to.equal(Esquire.modules['module-b']);
});
it('should resolve empty dependencies', function() {
var dependencies = Esquire.resolve('module-a');
expect(dependencies).to.be.empty;
promises('should resolve empty dependencies', function() {
return Esquire.resolve('module-a')
.then(function(dependencies) {
expect(dependencies).to.be.an('object');
expect(Object.keys(dependencies).length).to.be.equal(0);
});
});
it('should resolve valid dependencies', function() {
var dependencies = Esquire.resolve('module-c');
expect(dependencies.length).to.equal(2);
expect(dependencies[0]).to.equal(Esquire.module('module-a'));
expect(dependencies[1]).to.equal(Esquire.module('module-b'));
promises('should resolve valid dependencies', function() {
return Esquire.resolve('module-c')
.then(function(dependencies) {
expect(dependencies).to.be.an('object');
expect(Object.keys(dependencies).length).to.be.equal(2);
expect(dependencies['module-a']).to.equal(Esquire.modules['module-a']);
expect(dependencies['module-b']).to.equal(Esquire.modules['module-b']);
});
});
it('should resolve direct dependencies', function() {
var dependencies = Esquire.resolve('module-d');
expect(dependencies.length).to.equal(1);
expect(dependencies[0]).to.equal(Esquire.module('module-c'));
promises('should resolve direct dependencies', function() {
return Esquire.resolve('module-d')
.then(function(dependencies) {
expect(dependencies).to.be.an('object');
expect(Object.keys(dependencies).length).to.be.equal(1);
expect(dependencies['module-c']).to.equal(Esquire.modules['module-c']);
});
});
it('should resolve transitive dependencies', function() {
var dependencies = Esquire.resolve('module-d', true);
expect(dependencies.length).to.equal(3);
expect(dependencies[0]).to.equal(Esquire.module('module-c'));
expect(dependencies[1]).to.equal(Esquire.module('module-a'));
expect(dependencies[2]).to.equal(Esquire.module('module-b'));
promises('should resolve transitive dependencies', function() {
return Esquire.resolve('module-d', true)
.then(function(dependencies) {
expect(dependencies).to.be.an('object');
expect(Object.keys(dependencies).length).to.be.equal(3);
expect(dependencies['module-a']).to.equal(Esquire.modules['module-a']);
expect(dependencies['module-b']).to.equal(Esquire.modules['module-b']);
expect(dependencies['module-c']).to.equal(Esquire.modules['module-c']);
});
});
promises('should resolve transitive deferred dependencies', function() {
var start = "test/deferred-" + (Math.floor(Math.random() * 1000000));
var name1 = "test/deferred-" + (Math.floor(Math.random() * 1000000));
var name2 = "test/deferred-" + (Math.floor(Math.random() * 1000000));
var name3 = "test/deferred-" + (Math.floor(Math.random() * 1000000));
Esquire.define(start, [name1], function() {});
setTimeout(function() { Esquire.define(name1, [name2], function() {}) }, 20);
setTimeout(function() { Esquire.define(name2, [name3], function() {}) }, 40);
setTimeout(function() { Esquire.define(name3, ["module-d"], function() {}) }, 60);
return Esquire.resolve(start, true)
.then(function(dependencies) {
expect(dependencies).to.be.an('object');
expect(Object.keys(dependencies).length).to.be.equal(7);
// check on module NAMES, not instances returned by Esquire.define()
// because we might potentially unlock all our chains (and have this
// call resolved) before the actual "Esquire.define" method returns.
expect(dependencies[name1].name).to.equal(name1);
expect(dependencies[name2].name).to.equal(name2);
expect(dependencies[name3].name).to.equal(name3);
// those ones on the other hand were not deferred, safe to check...
expect(dependencies['module-a']).to.equal(Esquire.modules['module-a']);
expect(dependencies['module-b']).to.equal(Esquire.modules['module-b']);
expect(dependencies['module-c']).to.equal(Esquire.modules['module-c']);
expect(dependencies['module-d']).to.equal(Esquire.modules['module-d']);
});
});
promises('should resolve circular dependencies', function() {
return Esquire.resolve('circular-a', true)
.then(function(dependencies) {
expect(dependencies).to.be.an('object');
expect(Object.keys(dependencies).length).to.be.equal(7);
expect(dependencies['circular-a']).to.equal(Esquire.modules['circular-a']);
expect(dependencies['circular-b']).to.equal(Esquire.modules['circular-b']);
expect(dependencies['circular-c']).to.equal(Esquire.modules['circular-c']);
expect(dependencies['circular-d']).to.equal(Esquire.modules['circular-d']);
expect(dependencies['circular-e']).to.equal(Esquire.modules['circular-e']);
expect(dependencies['circular-f']).to.equal(Esquire.modules['circular-f']);
expect(dependencies['circular-g']).to.equal(Esquire.modules['circular-g']);
});
});
promises('should resolve circular dependencies to self', function() {
return Esquire.resolve('circular-self', true)
.then(function(dependencies) {
expect(dependencies).to.be.an('object');
expect(Object.keys(dependencies).length).to.be.equal(1);
expect(dependencies['circular-self']).to.equal(Esquire.modules['circular-self']);
});
});
});

@@ -643,2 +763,42 @@

describe('deferred definition', function() {
promises('should wait until modules are defined and resolve', function() {
var name = "test/deferred-" + (Math.floor(Math.random() * 1000000));
setTimeout(function() {
Esquire.define(name, [], function() { return "value for " + name });
}, 50);
return new Esquire(100).inject(name, function(value) {
expect(value).to.be.equal("value for " + name);
});
});
promises('should wait until modules are defined and reject', function() {
var name = "test/deferred-" + (Math.floor(Math.random() * 1000000));
setTimeout(function() {
Esquire.define(name, [], function() { throw new Error("Error " + name) });
}, 50);
var invoked = false;
return new Esquire(100).inject(name, function(value) {
invoked = true;
}).then(function(success) {
throw new Error("Should not succeed")
}, function (failure) {
expect(failure).to.be.instanceof(Error);
expect(failure.originalCause).to.be.instanceof(Error);
expect(failure.originalCause.message).to.equal("Error " + name);
expect(invoked).to.be.false;
})
});
});
/* ======================================================================== */
describe("failures", function() {

@@ -648,2 +808,5 @@

var timeout = Esquire.timeout;
Esquire.timeout = 100;
var invoked = false;

@@ -654,4 +817,6 @@

}).then(function(success) {
Esquire.timeout = timeout;
throw new Error("Should not succeed")
}, function (failure) {
Esquire.timeout = timeout;
expect(failure).to.be.instanceof(Error);

@@ -678,3 +843,8 @@ expect(failure.message).to.match(/module 'not-known' not found/i);

return new Esquire().require("circular-a")
var name = "testCircular-" + Math.floor(Math.random() * 1000000);
Esquire.define(name, "circular-a", function() {
throw new Error("NEVER");
});
return new Esquire().require(name)
.then(function(success) {

@@ -684,3 +854,5 @@ throw new Error("Should not succeed")

expect(failure).to.be.instanceof(Error);
expect(failure.message).to.match(/module 'circular-a' has circular dependencies/i);
expect(failure.message).to.match(/^Esquire: Injection failed/);
expect(failure.originalCause).to.be.instanceof(Error);
expect(failure.originalCause.message).to.equal("Esquire: Detected circular dependency in circular-a -> circular-b -> circular-c -> circular-d -> circular-e -> circular-f -> circular-g -> circular-a");
})

@@ -692,3 +864,8 @@

return new Esquire().require("circular-self")
var name = "testCircular-" + Math.floor(Math.random() * 1000000);
Esquire.define(name, "circular-self", function() {
throw new Error("NEVER");
});
return new Esquire().require(name)
.then(function(success) {

@@ -698,3 +875,5 @@ throw new Error("Should not succeed")

expect(failure).to.be.instanceof(Error);
expect(failure.message).to.match(/module 'circular-self' has circular dependencies/i);
expect(failure.message).to.match(/^Esquire: Injection failed/);
expect(failure.originalCause).to.be.instanceof(Error);
expect(failure.originalCause.message).to.equal("Esquire: Detected circular dependency in circular-self -> circular-self");
})

@@ -701,0 +880,0 @@

@@ -99,8 +99,5 @@ 'use strict';

Esquire.define("$global.forDependency1", ["$global.foo"], function() {});
Esquire.define("$global/forDependency2", ["$global/bar"], function() {});
var m1 = Esquire.define("$global.forDependency1", ["$global.foo"], function() {});
var m2 = Esquire.define("$global/forDependency2", ["$global/bar"], function() {});
var m1 = Esquire.module("$global/forDependency1");
var m2 = Esquire.module("$global.forDependency2");
expect(m1.name).to.equal("$global/forDependency1");

@@ -160,13 +157,20 @@ expect(m2.name).to.equal("$global/forDependency2");

var script = Esquire.module("$global.console").$$script
.replace("$global/console",
"xinject-console");
eval(script);
var c0 = new Esquire().require("xinject-console");
var c1 = esquire("$global.console");
return Promise.all([c0, c1]).then(function(c) {
expect(c[0]).to.equal(c[1]);
return Esquire.module("$global.console")
.then(function(module) {
return module.$$script.replace("$global/console", "xinject-console");
})
.then(function(script) {
return eval(script);
})
.then(function(module) {
expect(module).to.be.a('object');
expect(module.name).to.be.equal("xinject-console");
return Promise.all([
new Esquire().require("xinject-console"),
esquire("$global.console")
])
})
.then(function(result) {
expect(result[0]).to.equal(result[1])
});

@@ -173,0 +177,0 @@ });

@@ -1,26 +0,26 @@

Esquire.define('circular-a', ['circular-g'], function() {
Esquire.define('circular-a', ['circular-b'], function() {
return "a value";
});
Esquire.define('circular-b', ['circular-a'], function() {
Esquire.define('circular-b', ['circular-c'], function() {
return "b value";
});
Esquire.define('circular-c', ['circular-b'], function() {
Esquire.define('circular-c', ['circular-d'], function() {
return "c value";
});
Esquire.define('circular-d', ['circular-c'], function() {
Esquire.define('circular-d', ['circular-e'], function() {
return "d value";
});
Esquire.define('circular-e', ['circular-d'], function() {
Esquire.define('circular-e', ['circular-f'], function() {
return "e value";
});
Esquire.define('circular-f', ['circular-e'], function() {
Esquire.define('circular-f', ['circular-g'], function() {
return "f value";
});
Esquire.define('circular-g', ['circular-f'], function() {
Esquire.define('circular-g', ['circular-a'], function() {
return "g value";

@@ -27,0 +27,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc