vendor: 1,054 bytes, lines 1-28
1/** 2 * jquery-deparam: https://github.com/AceMetrix/jquery-deparam 3 * License: MIT 4 */ 5(function(deparam){ 6 if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') { 7 try { 8 var jquery = require('jquery'); 9 } catch (e) { 10 } 11 module.exports = deparam(jquery); 12 } else if (typeof define === 'function' && define.amd){ 13 define(['jquery'], function(jquery){ 14 return deparam(jquery); 15 }); 16 } else { 17 var global; 18 try { 19 global = (false || eval)('this'); // best cross-browser way to determine global for < ES5 20 } catch (e) { 21 global = window; // fails only if browser (https://developer.mozilla.org/en-US/docs/Web/Security/CSP/CSP_policy_directives) 22 } 23 global.deparam = deparam(global.jQuery); // assume jQuery is in global namespace 24 } 25})(function ($) { 26 var deparam = function( params, coerce ) { 27 var obj = {}, 28 coerce_types = { 'true': !0, 'false': !1, 'null': null };
vendor: 3,936 bytes, lines 28-121
28 29 30 // Iterate over all name=value pairs. 31 params.replace(/\+/g, ' ').split('&').forEach(function(v){ 32 var param = v.split( '=' ), 33 key = decodeURIComponent( param[0] ), 34 val, 35 cur = obj, 36 i = 0, 37 38 // If key is more complex than 'foo', like 'a[]' or 'a[b][c]', split it 39 // into its component parts. 40 keys = key.split( '][' ), 41 keys_last = keys.length - 1; 42 43 // If the first keys part contains [ and the last ends with ], then [] 44 // are correctly balanced. 45 if ( /\[/.test( keys[0] ) && /\]$/.test( keys[ keys_last ] ) ) { 46 // Remove the trailing ] from the last keys part. 47 keys[ keys_last ] = keys[ keys_last ].replace( /\]$/, '' ); 48 49 // Split first keys part into two parts on the [ and add them back onto 50 // the beginning of the keys array. 51 keys = keys.shift().split('[').concat( keys ); 52 53 keys_last = keys.length - 1; 54 } else { 55 // Basic 'foo' style key. 56 keys_last = 0; 57 } 58 59 // Are we dealing with a name=value pair, or just a name? 60 if ( param.length === 2 ) { 61 val = decodeURIComponent( param[1] ); 62 63 // Coerce values. 64 if ( coerce ) { 65 val = val && !isNaN(val) && ((+val + '') === val) ? +val // number 66 : val === 'undefined' ? undefined // undefined 67 : coerce_types[val] !== undefined ? coerce_types[val] // true, false, null 68 : val; // string 69 } 70 71 if ( keys_last ) { 72 // Complex key, build deep object structure based on a few rules: 73 // * The 'cur' pointer starts at the object top-level. 74 // * [] = array push (n is set to array length), [n] = array if n is 75 // numeric, otherwise object. 76 // * If at the last keys part, set the value. 77 // * For each keys part, if the current level is undefined create an 78 // object or array based on the type of the next keys part. 79 // * Move the 'cur' pointer to the next level. 80 // * Rinse & repeat. 81 for ( ; i <= keys_last; i++ ) { 82 key = keys[i] === '' ? cur.length : keys[i]; 83 cur = cur[key] = i < keys_last 84 ? cur[key] || ( keys[i+1] && isNaN( keys[i+1] ) ? {} : [] ) 85 : val; 86 } 87 88 } else { 89 // Simple key, even simpler rules, since only scalars and shallow 90 // arrays are allowed. 91 92 if ( Object.prototype.toString.call( obj[key] ) === '[object Array]' ) { 93 // val is already an array, so push on the next value. 94 obj[key].push( val ); 95 96 } else if ( {}.hasOwnProperty.call(obj, key) ) { 97 // val isn't an array, but since a second value has been specified, 98 // convert val into an array. 99 obj[key] = [ obj[key], val ]; 100 101 } else { 102 // val is a scalar. 103 obj[key] = val; 104 } 105 } 106 107 } else if ( key ) { 108 // No value was defined, so set something meaningful. 109 obj[key] = coerce 110 ? undefined 111 : ''; 112 } 113 }); 114 115 return obj; 116 }; 117 if ($) { 118 $.prototype.deparam = $.deparam = deparam; 119 } 120 return deparam; 121});
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.