ya
Version:
屋 ya - simple glob pub/sub store
1 lines • 12 kB
JavaScript
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).ya=t()}}(function(){return function a(o,s,u){function c(n,t){if(!s[n]){if(!o[n]){var e="function"==typeof require&&require;if(!t&&e)return e(n,!0);if(h)return h(n,!0);var r=new Error("Cannot find module '"+n+"'");throw r.code="MODULE_NOT_FOUND",r}var i=s[n]={exports:{}};o[n][0].call(i.exports,function(t){var e=o[n][1][t];return c(e||t)},i,i.exports,a,o,s,u)}return s[n].exports}for(var h="function"==typeof require&&require,t=0;t<u.length;t++)c(u[t]);return c}({1:[function(t,e,n){"use strict";function r(t,e,n){t instanceof RegExp&&(t=i(t,n)),e instanceof RegExp&&(e=i(e,n));var r=a(t,e,n);return r&&{start:r[0],end:r[1],pre:n.slice(0,r[0]),body:n.slice(r[0]+t.length,r[1]),post:n.slice(r[1]+e.length)}}function i(t,e){var n=e.match(t);return n?n[0]:null}function a(t,e,n){var r,i,a,o,s,u=n.indexOf(t),c=n.indexOf(e,u+1),h=u;if(0<=u&&0<c){for(r=[],a=n.length;0<=h&&!s;)h==u?(r.push(h),u=n.indexOf(t,h+1)):1==r.length?s=[r.pop(),c]:((i=r.pop())<a&&(a=i,o=c),c=n.indexOf(e,h+1)),h=u<c&&0<=u?u:c;r.length&&(s=[a,o])}return s}(e.exports=r).range=a},{}],2:[function(t,e,n){var S=t("concat-map"),$=t("balanced-match");e.exports=function(t){if(!t)return[];"{}"===t.substr(0,2)&&(t="\\{\\}"+t.substr(2));return function e(t,n){var r=[];var i=$("{","}",t);if(!i||/\$$/.test(i.pre))return[t];var a=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(i.body);var o=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(i.body);var s=a||o;var u=0<=i.body.indexOf(",");if(!s&&!u)return i.post.match(/,.*\}/)?(t=i.pre+"{"+i.body+M+i.post,e(t)):[t];var c;if(s)c=i.body.split(/\.\./);else if(1===(c=function t(e){if(!e)return[""];var n=[];var r=$("{","}",e);if(!r)return e.split(",");var i=r.pre;var a=r.body;var o=r.post;var s=i.split(",");s[s.length-1]+="{"+a+"}";var u=t(o);o.length&&(s[s.length-1]+=u.shift(),s.push.apply(s,u));n.push.apply(n,s);return n}(i.body)).length&&1===(c=e(c[0],!1).map(C)).length){var h=i.post.length?e(i.post,!1):[""];return h.map(function(t){return i.pre+c[0]+t})}var f=i.pre;var h=i.post.length?e(i.post,!1):[""];var p;if(s){var l=R(c[0]),g=R(c[1]),d=Math.max(c[0].length,c[1].length),v=3==c.length?Math.abs(R(c[2])):1,b=_,m=g<l;m&&(v*=-1,b=N);var y=c.some(T);p=[];for(var x=l;b(x,g);x+=v){var w;if(o)"\\"===(w=String.fromCharCode(x))&&(w="");else if(w=String(x),y){var j=d-w.length;if(0<j){var O=new Array(j+1).join("0");w=x<0?"-"+O+w.slice(1):O+w}}p.push(w)}}else p=S(c,function(t){return e(t,!1)});for(var E=0;E<p.length;E++)for(var A=0;A<h.length;A++){var k=f+p[E]+h[A];(!n||s||k)&&r.push(k)}return r}((e=t,e.split("\\\\").join(r).split("\\{").join(i).split("\\}").join(M).split("\\,").join(a).split("\\.").join(o)),!0).map(s);var e};var r="\0SLASH"+Math.random()+"\0",i="\0OPEN"+Math.random()+"\0",M="\0CLOSE"+Math.random()+"\0",a="\0COMMA"+Math.random()+"\0",o="\0PERIOD"+Math.random()+"\0";function R(t){return parseInt(t,10)==t?parseInt(t,10):t.charCodeAt(0)}function s(t){return t.split(r).join("\\").split(i).join("{").split(M).join("}").split(a).join(",").split(o).join(".")}function C(t){return"{"+t+"}"}function T(t){return/^-?0\d/.test(t)}function _(t,e){return t<=e}function N(t,e){return e<=t}},{"balanced-match":1,"concat-map":3}],3:[function(t,e,n){e.exports=function(t,e){for(var n=[],r=0;r<t.length;r++){var i=e(t[r],r);a(i)?n.push.apply(n,i):n.push(i)}return n};var a=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}},{}],4:[function(t,e,n){(e.exports=u).Minimatch=i;var c={sep:"/"};try{c=t("path")}catch(t){}var q=u.GLOBSTAR=i.GLOBSTAR={},r=t("brace-expansion"),B={"!":{open:"(?:(?!(?:",close:"))[^/]*?)"},"?":{open:"(?:",close:")?"},"+":{open:"(?:",close:")+"},"*":{open:"(?:",close:")*"},"@":{open:"(?:",close:")"}},G="[^/]",I=G+"*?",a="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",o="(?:(?!(?:\\/|^)\\.).)*?",D="().*{}+?[]^$\\!".split("").reduce(function(t,e){return t[e]=!0,t},{});var h=/\/+/;function s(e,n){e=e||{},n=n||{};var r={};return Object.keys(n).forEach(function(t){r[t]=n[t]}),Object.keys(e).forEach(function(t){r[t]=e[t]}),r}function u(t,e,n){if("string"!=typeof e)throw new TypeError("glob pattern string required");return n||(n={}),!(!n.nocomment&&"#"===e.charAt(0))&&(""===e.trim()?""===t:new i(e,n).match(t))}function i(t,e){if(!(this instanceof i))return new i(t,e);if("string"!=typeof t)throw new TypeError("glob pattern string required");e||(e={}),t=t.trim(),"/"!==c.sep&&(t=t.split(c.sep).join("/")),this.options=e,this.set=[],this.pattern=t,this.regexp=null,this.negate=!1,this.comment=!1,this.empty=!1,this.make()}function f(t,e){if(e||(e=this instanceof i?this.options:{}),void 0===(t=void 0===t?this.pattern:t))throw new TypeError("undefined pattern");return e.nobrace||!t.match(/\{.*\}/)?[t]:r(t)}u.filter=function(r,i){return i=i||{},function(t,e,n){return u(t,r,i)}},u.defaults=function(r){if(!r||!Object.keys(r).length)return u;var i=u,t=function(t,e,n){return i.minimatch(t,e,s(r,n))};return t.Minimatch=function(t,e){return new i.Minimatch(t,s(r,e))},t},i.defaults=function(t){return t&&Object.keys(t).length?u.defaults(t).Minimatch:i},i.prototype.debug=function(){},i.prototype.make=function(){if(this._made)return;var t=this.pattern,e=this.options;if(!e.nocomment&&"#"===t.charAt(0))return void(this.comment=!0);if(!t)return void(this.empty=!0);this.parseNegate();var n=this.globSet=this.braceExpand();e.debug&&(this.debug=console.error);this.debug(this.pattern,n),n=this.globParts=n.map(function(t){return t.split(h)}),this.debug(this.pattern,n),n=n.map(function(t,e,n){return t.map(this.parse,this)},this),this.debug(this.pattern,n),n=n.filter(function(t){return-1===t.indexOf(!1)}),this.debug(this.pattern,n),this.set=n},i.prototype.parseNegate=function(){var t=this.pattern,e=!1,n=this.options,r=0;if(n.nonegate)return;for(var i=0,a=t.length;i<a&&"!"===t.charAt(i);i++)e=!e,r++;r&&(this.pattern=t.substr(r));this.negate=e},u.braceExpand=function(t,e){return f(t,e)},i.prototype.braceExpand=f,i.prototype.parse=function(t,e){if(65536<t.length)throw new TypeError("pattern is too long");var n=this.options;if(!n.noglobstar&&"**"===t)return q;if(""===t)return"";var r,i="",a=!!n.nocase,o=!1,s=[],u=[],c=!1,h=-1,f=-1,p="."===t.charAt(0)?"":n.dot?"(?!(?:^|\\/)\\.{1,2}(?:$|\\/))":"(?!\\.)",l=this;function g(){if(r){switch(r){case"*":i+=I,a=!0;break;case"?":i+=G,a=!0;break;default:i+="\\"+r}l.debug("clearStateChar %j %j",r,i),r=!1}}for(var d,v=0,b=t.length;v<b&&(d=t.charAt(v));v++)if(this.debug("%s\t%s %s %j",t,v,i,d),o&&D[d])i+="\\"+d,o=!1;else switch(d){case"/":return!1;case"\\":g(),o=!0;continue;case"?":case"*":case"+":case"@":case"!":if(this.debug("%s\t%s %s %j <-- stateChar",t,v,i,d),c){this.debug(" in class"),"!"===d&&v===f+1&&(d="^"),i+=d;continue}l.debug("call clearStateChar %j",r),g(),r=d,n.noext&&g();continue;case"(":if(c){i+="(";continue}if(!r){i+="\\(";continue}s.push({type:r,start:v-1,reStart:i.length,open:B[r].open,close:B[r].close}),i+="!"===r?"(?:(?!(?:":"(?:",this.debug("plType %j %j",r,i),r=!1;continue;case")":if(c||!s.length){i+="\\)";continue}g(),a=!0;var m=s.pop();i+=m.close,"!"===m.type&&u.push(m),m.reEnd=i.length;continue;case"|":if(c||!s.length||o){i+="\\|",o=!1;continue}g(),i+="|";continue;case"[":if(g(),c){i+="\\"+d;continue}c=!0,f=v,h=i.length,i+=d;continue;case"]":if(v===f+1||!c){i+="\\"+d,o=!1;continue}if(c){var y=t.substring(f+1,v);try{RegExp("["+y+"]")}catch(t){var x=this.parse(y,P);i=i.substr(0,h)+"\\["+x[0]+"\\]",a=a||x[1],c=!1;continue}}c=!(a=!0),i+=d;continue;default:g(),o?o=!1:!D[d]||"^"===d&&c||(i+="\\"),i+=d}c&&(y=t.substr(f+1),x=this.parse(y,P),i=i.substr(0,h)+"\\["+x[0],a=a||x[1]);for(m=s.pop();m;m=s.pop()){var w=i.slice(m.reStart+m.open.length);this.debug("setting tail",i,m),w=w.replace(/((?:\\{2}){0,64})(\\?)\|/g,function(t,e,n){return n||(n="\\"),e+e+n+"|"}),this.debug("tail=%j\n %s",w,w,m,i);var j="*"===m.type?I:"?"===m.type?G:"\\"+m.type;a=!0,i=i.slice(0,m.reStart)+j+"\\("+w}g(),o&&(i+="\\\\");var O=!1;switch(i.charAt(0)){case".":case"[":case"(":O=!0}for(var E=u.length-1;-1<E;E--){var A=u[E],k=i.slice(0,A.reStart),S=i.slice(A.reStart,A.reEnd-8),$=i.slice(A.reEnd-8,A.reEnd),M=i.slice(A.reEnd);$+=M;var R=k.split("(").length-1,C=M;for(v=0;v<R;v++)C=C.replace(/\)[+*?]?/,"");var T="";""===(M=C)&&e!==P&&(T="$");var _=k+S+M+T+$;i=_}""!==i&&a&&(i="(?=.)"+i);O&&(i=p+i);if(e===P)return[i,a];if(!a)return t.replace(/\\(.)/g,"$1");var N=n.nocase?"i":"";try{var L=new RegExp("^"+i+"$",N)}catch(t){return new RegExp("$.")}return L._glob=t,L._src=i,L};var P={};u.makeRe=function(t,e){return new i(t,e||{}).makeRe()},i.prototype.makeRe=function(){if(this.regexp||!1===this.regexp)return this.regexp;var t=this.set;if(!t.length)return this.regexp=!1,this.regexp;var e=this.options,n=e.noglobstar?I:e.dot?a:o,r=e.nocase?"i":"",i=t.map(function(t){return t.map(function(t){return t===q?n:"string"==typeof t?t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"):t._src}).join("\\/")}).join("|");i="^(?:"+i+")$",this.negate&&(i="^(?!"+i+").*$");try{this.regexp=new RegExp(i,r)}catch(t){this.regexp=!1}return this.regexp},u.match=function(t,e,n){var r=new i(e,n=n||{});return t=t.filter(function(t){return r.match(t)}),r.options.nonull&&!t.length&&t.push(e),t},i.prototype.match=function(t,e){if(this.debug("match",t,this.pattern),this.comment)return!1;if(this.empty)return""===t;if("/"===t&&e)return!0;var n=this.options;"/"!==c.sep&&(t=t.split(c.sep).join("/"));t=t.split(h),this.debug(this.pattern,"split",t);var r,i,a=this.set;for(this.debug(this.pattern,"set",a),i=t.length-1;0<=i&&!(r=t[i]);i--);for(i=0;i<a.length;i++){var o=a[i],s=t;n.matchBase&&1===o.length&&(s=[r]);var u=this.matchOne(s,o,e);if(u)return!!n.flipNegate||!this.negate}return!n.flipNegate&&this.negate},i.prototype.matchOne=function(t,e,n){var r=this.options;this.debug("matchOne",{this:this,file:t,pattern:e}),this.debug("matchOne",t.length,e.length);for(var i=0,a=0,o=t.length,s=e.length;i<o&&a<s;i++,a++){this.debug("matchOne loop");var u,c=e[a],h=t[i];if(this.debug(e,c,h),!1===c)return!1;if(c===q){this.debug("GLOBSTAR",[e,c,h]);var f=i,p=a+1;if(p===s){for(this.debug("** at the end");i<o;i++)if("."===t[i]||".."===t[i]||!r.dot&&"."===t[i].charAt(0))return!1;return!0}for(;f<o;){var l=t[f];if(this.debug("\nglobstar while",t,f,e,p,l),this.matchOne(t.slice(f),e.slice(p),n))return this.debug("globstar found match!",f,o,l),!0;if("."===l||".."===l||!r.dot&&"."===l.charAt(0)){this.debug("dot detected!",t,f,e,p);break}this.debug("globstar swallow a segment, and continue"),f++}return!(!n||(this.debug("\n>>> no match, partial?",t,f,e,p),f!==o))}if("string"==typeof c?(u=r.nocase?h.toLowerCase()===c.toLowerCase():h===c,this.debug("string match",c,h,u)):(u=h.match(c),this.debug("pattern match",c,h,u)),!u)return!1}if(i===o&&a===s)return!0;if(i===o)return n;if(a===s)return i===o-1&&""===t[i];throw new Error("wtf?")}},{"brace-expansion":2,path:void 0}],5:[function(t,e,n){"use strict";var u=t("minimatch");function r(t){var e={},i={},s=[];return e.state={},e.on=function(t,e){var n=i[t]||[];return 0<=(i[t]=n).indexOf(e)?console.log("YA WARNING: callback already added to store (was skipped)"):n.push(e),function(){var t=n.indexOf(e);if(0<=t)return n.splice(t,0)}},e.glob=function(t,e){var n=s,r={glob:t,buffer:[],_callback:e,_timeout:void 0,callback:function(t,e){clearTimeout(r._timeout),r.buffer.push({evt:t,data:e}),r._timeout=setTimeout(function(){var t=r.buffer;r.buffer=[],r._callback(t)},4)}};return n.push(r),function(){var t=n.indexOf(r);if(0<=t)return n.splice(t,0)}},e.emit=function(t,e){!function(t,e){for(var n=0;n<s.length;n++){var r=s[n],i=r.glob,a=r.callback,o=u(t,i);o&&a(t,e)}}(t,e);for(var n=i[t]||[],r=0;r<n.length;r++){(0,n[r])(e)}},e}function i(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];return r()}i.createStore=r,e.exports=i},{minimatch:4}]},{},[5])(5)});