1// qcode-ui v1.0.53 2import urlDecode from '/static/js/qcode-ui/urlDecode-ab9ee7c7.js' 3 4/** 5 * @module urlDataSet 6 * 7 * @description Update a parameter value or append a new parameter to the given 8 * query string. 9 * 10 * @property {string} queryString - The query string to set the value in 11 * @property {string} parameterName - The URL parameter name to search for in the 12 * query string 13 * @property {string} parameterValue - The URL parameter value to set in the query 14 * string 15 * @returns {string} The updated query string 16 * 17 * @example 18 * 19 * let queryString = "sort=date&limit=25&offset=0" 20 * let newQueryString = urlDataSet(queryString, "sort", "name" 21 * // => "sort=name&limit=25&offset=0" 22 */ 23 24function urlDataSet (queryString, parameterName, parameterValue) { 25 let urlParameters = [] 26 27 if (queryString) { 28 urlParameters = queryString.split('&') 29 } 30 31 const data = {} 32 33 for (const urlParameter of urlParameters) { 34 const pair = urlParameter.split('=') 35 const name = urlDecode(pair[0]) 36 const value = urlDecode(pair[1] || '') 37 38 if (name in data) { 39 if (Array.isArray(data[name])) { 40 data[name].push(value) 41 } else { 42 const values = [] 43 values.push(data[name]) 44 values.push(value) 45 data[name] = values 46 } 47 } else { 48 data[name] = value 49 } 50 } 51 const resultUrlParameters = [] 52 data[parameterName] = parameterValue 53 for (const name in data) { 54 if (Array.isArray(data[name])) { 55 for (let i = 0; i < data[name].length; i++) { 56 resultUrlParameters.push(encodeURIComponent(name) + '=' + encodeURIComponent(data[name][i])) 57 } 58 } else { 59 resultUrlParameters.push(encodeURIComponent(name) + '=' + encodeURIComponent(data[name])) 60 } 61 } 62 63 queryString = resultUrlParameters.join('&') 64 return queryString 65} 66 67export default urlDataSet
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.