"use strict";var TOKEN=/([!#\$%&'\*\+\-\.\^_`\|~0-9A-Za-z]+)/,NOTOKEN=/([^!#\$%&'\*\+\-\.\^_`\|~0-9A-Za-z])/g,QUOTED=/"((?:\\[\x00-\x7f]|[^\x00-\x08\x0a-\x1f\x7f"])*)"/,PARAM=new RegExp(TOKEN.source+"(?:=(?:"+TOKEN.source+"|"+QUOTED.source+"))?"),EXT=new RegExp(TOKEN.source+"(?: *; *"+PARAM.source+")*","g"),EXT_LIST=new RegExp("^"+EXT.source+"(?: *, *"+EXT.source+")*$"),NUMBER=/^-?(0|[1-9][0-9]*)(\.[0-9]+)?$/,hasOwnProperty=Object.prototype.hasOwnProperty,Parser={parseHeader:function(r){var e=new Offers;if(""===r||void 0===r)return e;if(!EXT_LIST.test(r))throw new SyntaxError("Invalid Sec-WebSocket-Extensions header: "+r);return r.match(EXT).forEach(function(r){var t=r.match(new RegExp(PARAM.source,"g")),s=t.shift(),a={};t.forEach(function(r){var e,t=r.match(PARAM),s=t[1];e=void 0!==t[2]?t[2]:void 0===t[3]||t[3].replace(/\\/g,""),NUMBER.test(e)&&(e=parseFloat(e)),hasOwnProperty.call(a,s)?(a[s]=[].concat(a[s]),a[s].push(e)):a[s]=e},this),e.push(s,a)},this),e},serializeParams:function(r,e){var t=[],s=function(r,e){e instanceof Array?e.forEach(function(e){s(r,e)}):!0===e?t.push(r):"number"==typeof e?t.push(r+"="+e):NOTOKEN.test(e)?t.push(r+'="'+e.replace(/"/g,'\\"')+'"'):t.push(r+"="+e)};for(var a in e)s(a,e[a]);return[r].concat(t).join("; ")}},Offers=function(){this._byName={},this._inOrder=[]};Offers.prototype.push=function(r,e){hasOwnProperty.call(this._byName,r)||(this._byName[r]=[]),this._byName[r].push(e),this._inOrder.push({name:r,params:e})},Offers.prototype.eachOffer=function(r,e){for(var t=this._inOrder,s=0,a=t.length;s<a;s++)r.call(e,t[s].name,t[s].params)},Offers.prototype.byName=function(r){return this._byName[r]||[]},Offers.prototype.toArray=function(){return this._inOrder.slice()},module.exports=Parser;