vendor: 6,238 bytes, lines 1-179
1function parse_str(str, array) { 2 // discuss at: http://phpjs.org/functions/parse_str/ 3 // original by: Cagri Ekin 4 // improved by: Michael White (http://getsprink.com) 5 // improved by: Jack 6 // improved by: Brett Zamir (http://brett-zamir.me) 7 // bugfixed by: Onno Marsman 8 // bugfixed by: Brett Zamir (http://brett-zamir.me) 9 // bugfixed by: stag019 10 // bugfixed by: Brett Zamir (http://brett-zamir.me) 11 // bugfixed by: MIO_KODUKI (http://mio-koduki.blogspot.com/) 12 // reimplemented by: stag019 13 // input by: Dreamer 14 // input by: Zaide (http://zaidesthings.com/) 15 // input by: David Pesta (http://davidpesta.com/) 16 // input by: jeicquest 17 // note: When no argument is specified, will put variables in global scope. 18 // note: When a particular argument has been passed, and the returned value is different parse_str of PHP. For example, a=b=c&d====c 19 // test: skip 20 // example 1: var arr = {}; 21 // example 1: parse_str('first=foo&second=bar', arr); 22 // example 1: $result = arr 23 // returns 1: { first: 'foo', second: 'bar' } 24 // example 2: var arr = {}; 25 // example 2: parse_str('str_a=Jack+and+Jill+didn%27t+see+the+well.', arr); 26 // example 2: $result = arr 27 // returns 2: { str_a: "Jack and Jill didn't see the well." } 28 // example 3: var abc = {3:'a'}; 29 // example 3: parse_str('abc[a][b]["c"]=def&abc[q]=t+5'); 30 // returns 3: {"3":"a","a":{"b":{"c":"def"}},"q":"t 5"} 31 32 var strArr = String(str) 33 .replace(/^&/, '') 34 .replace(/&$/, '') 35 .split('&'), 36 sal = strArr.length, 37 i, j, ct, p, lastObj, obj, lastIter, undef, chr, tmp, key, value, 38 postLeftBracketPos, keys, keysLen, 39 fixStr = function(str) { 40 return decodeURIComponent(str.replace(/\+/g, '%20')); 41 }; 42 43 if (!array) { 44 array = this.window; 45 } 46 47 for (i = 0; i < sal; i++) { 48 tmp = strArr[i].split('='); 49 key = fixStr(tmp[0]); 50 value = (tmp.length < 2) ? '' : fixStr(tmp[1]); 51 52 while (key.charAt(0) === ' ') { 53 key = key.slice(1); 54 } 55 if (key.indexOf('\x00') > -1) { 56 key = key.slice(0, key.indexOf('\x00')); 57 } 58 if (key && key.charAt(0) !== '[') { 59 keys = []; 60 postLeftBracketPos = 0; 61 for (j = 0; j < key.length; j++) { 62 if (key.charAt(j) === '[' && !postLeftBracketPos) { 63 postLeftBracketPos = j + 1; 64 } else if (key.charAt(j) === ']') { 65 if (postLeftBracketPos) { 66 if (!keys.length) { 67 keys.push(key.slice(0, postLeftBracketPos - 1)); 68 } 69 keys.push(key.substr(postLeftBracketPos, j - postLeftBracketPos)); 70 postLeftBracketPos = 0; 71 if (key.charAt(j + 1) !== '[') { 72 break; 73 } 74 } 75 } 76 } 77 if (!keys.length) { 78 keys = [key]; 79 } 80 for (j = 0; j < keys[0].length; j++) { 81 chr = keys[0].charAt(j); 82 if (chr === ' ' || chr === '.' || chr === '[') { 83 keys[0] = keys[0].substr(0, j) + '_' + keys[0].substr(j + 1); 84 } 85 if (chr === '[') { 86 break; 87 } 88 } 89 90 obj = array; 91 for (j = 0, keysLen = keys.length; j < keysLen; j++) { 92 key = keys[j].replace(/^['"]/, '') 93 .replace(/['"]$/, ''); 94 lastIter = j !== keys.length - 1; 95 lastObj = obj; 96 if ((key !== '' && key !== ' ') || j === 0) { 97 if (obj[key] === undef) { 98 obj[key] = {}; 99 } 100 obj = obj[key]; 101 } else { // To insert new dimension 102 ct = -1; 103 for (p in obj) { 104 if (obj.hasOwnProperty(p)) { 105 if (+p > ct && p.match(/^\d+$/g)) { 106 ct = +p; 107 } 108 } 109 } 110 key = ct + 1; 111 } 112 } 113 lastObj[key] = value; 114 } 115 } 116} 117 118function http_build_query(formdata, numeric_prefix, arg_separator) { 119 // discuss at: http://phpjs.org/functions/http_build_query/ 120 // original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 121 // improved by: Legaev Andrey 122 // improved by: Michael White (http://getsprink.com) 123 // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 124 // improved by: Brett Zamir (http://brett-zamir.me) 125 // revised by: stag019 126 // input by: Dreamer 127 // bugfixed by: Brett Zamir (http://brett-zamir.me) 128 // bugfixed by: MIO_KODUKI (http://mio-koduki.blogspot.com/) 129 // note: If the value is null, key and value are skipped in the http_build_query of PHP while in phpjs they are not. 130 // depends on: urlencode 131 // example 1: http_build_query({foo: 'bar', php: 'hypertext processor', baz: 'boom', cow: 'milk'}, '', '&'); 132 // returns 1: 'foo=bar&php=hypertext+processor&baz=boom&cow=milk' 133 // example 2: http_build_query({'php': 'hypertext processor', 0: 'foo', 1: 'bar', 2: 'baz', 3: 'boom', 'cow': 'milk'}, 'myvar_'); 134 // returns 2: 'myvar_0=foo&myvar_1=bar&myvar_2=baz&myvar_3=boom&php=hypertext+processor&cow=milk' 135 136 var value, key, tmp = [], 137 that = this; 138 139 var _http_build_query_helper = function(key, val, arg_separator) { 140 var k, tmp = []; 141 if (val === true) { 142 val = '1'; 143 } else if (val === false) { 144 val = '0'; 145 } 146 if (val != null) { 147 if (typeof val === 'object') { 148 for (k in val) { 149 if (val[k] != null) { 150 tmp.push(_http_build_query_helper(key + '[' + k + ']', val[k], arg_separator)); 151 } 152 } 153 return tmp.join(arg_separator); 154 } else if (typeof val !== 'function') { 155 return that.urlencode(key) + '=' + that.urlencode(val); 156 } else { 157 throw new Error('There was an error processing for http_build_query().'); 158 } 159 } else { 160 return ''; 161 } 162 }; 163 164 if (!arg_separator) { 165 arg_separator = '&'; 166 } 167 for (key in formdata) { 168 value = formdata[key]; 169 if (numeric_prefix && !isNaN(key)) { 170 key = String(numeric_prefix) + key; 171 } 172 var query = _http_build_query_helper(key, value, arg_separator); 173 if (query !== '') { 174 tmp.push(query); 175 } 176 } 177 178 return tmp.join(arg_separator); 179}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.