-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathqparser.min.js
More file actions
2 lines (2 loc) · 2.43 KB
/
qparser.min.js
File metadata and controls
2 lines (2 loc) · 2.43 KB
1
2
/*! qparser 0.0.7 // 11.11.2013 // Vladimir Neverov <sanguini@gmail.com> // https://github.com/vne/qparser/wiki */
!function(){"use strict";function a(a){var b;a||(a={}),this.options=a;for(b in a)["quotes","spaces","flags","screen","group_open","group_close","or","prefix","range","or_open","or_close"].indexOf(b)>=0&&(a[b].constructor===RegExp?this[b.toUpperCase()]=a[b]:a[b].constructor===String&&(this[b.toUpperCase()]=new RegExp("["+a[b]+"]")));return a.instance?void 0:this.parse.bind(this)}a.prototype.QUOTES=/['"`]/,a.prototype.SPACES=/[ \t\r\n]/,a.prototype.FLAGS=/[~\+#!\*\/]/,a.prototype.SCREEN=/[\\]/,a.prototype.GROUP_OPEN=/\(/,a.prototype.GROUP_CLOSE=/\)/,a.prototype.OR=/\|/,a.prototype.PREFIX=/:/,a.prototype.RANGE=/-/,a.prototype.OR_OPEN=/\[/,a.prototype.OR_CLOSE=/]/,a.prototype.STATES={DATA:0,APPEND:1,QUOTE:2},a.prototype.parse=function(a,b){var c,d,e,f,g,h,i=[],j={},k="",l=!1,m=!1,n=!1,o=0,p=!1,q=this.STATES.DATA,r=function(){n&&(["range","prange"].indexOf(j.type)>=0?j.to=k:k&&k.length&&(j.query=k),j.type||(j.type=j.prefix?"prefix":"string"),i.push(j),o&&o+1===i.length&&(f=i.pop(),e=i.pop(),i.push({type:"or",queries:[e,f]}),o=0)),(n||!j.flags)&&(j={},k="",m=!1,n=!1)};if(!a||!a.length||"string"!=typeof a)return i;for(d=b&&b.pos>=0?b.pos:0;d<a.length;)if(l||(c=a.charAt(d++)),l=!1,q===this.STATES.DATA)if(p)k+=c,m=!0,n=!0,p=!1;else if(this.SCREEN.test(c))p=!0;else if(this.OR_OPEN.test(c))n?k+=c:(j.type="or",g={pos:d},j.queries=this.parse(a,g,this.OR_CLOSE),d=g.pos,j.queries&&j.queries.length&&(n=!0,q=this.STATES.APPEND,l=!0));else{if(this.OR_CLOSE.test(c)){b&&(b.pos=d);break}if(this.GROUP_OPEN.test(c))n?k+=c:(j.type="and",g={pos:d},j.queries=this.parse(a,g,this.GROUP_CLOSE),d=g.pos,j.queries&&j.queries.length&&(n=!0,q=this.STATES.APPEND,l=!0));else{if(b&&b.pos&&this.GROUP_CLOSE.test(c)){b&&(b.pos=d);break}this.OR.test(c)?(o=i.length,n&&(q=this.STATES.APPEND,l=!0,o+=1)):this.PREFIX.test(c)?(j.prefix=k,j.type="prefix",k="",m=!1,n=!0):this.RANGE.test(c)?(j.type=j.type&&"prefix"===j.type?"prange":"range",j.from=k,k="",m=!1,n=!0):this.SPACES.test(c)?(q=this.STATES.APPEND,l=!0):this.QUOTES.test(c)?k.length?(k+=c,m=!0,n=!0):(q=this.STATES.QUOTE,h=c):this.FLAGS.test(c)?k.length?k+=c:(j.flags||(j.flags=[]),j.flags.push(c)):(k+=c,m=!0,n=!0)}}else q===this.STATES.QUOTE?c===h?(h=void 0,q=this.STATES.APPEND,l=!0):(k+=c,m=!0,n=!0):q===this.STATES.APPEND&&(r(),q=this.STATES.DATA);return b&&(b.pos=d),r(),i};try{module.exports=a}catch(b){window.QParser=a}}();