source: imaps-frontend/node_modules/relateurl/lib/parse/query.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 878 bytes
Line 
1"use strict";
2var hasOwnProperty = Object.prototype.hasOwnProperty;
3
4
5
6function parseQuery(urlObj, options)
7{
8 urlObj.query.string.full = stringify(urlObj.query.object, false);
9
10 // TWEAK :: condition only for speed optimization
11 if (options.removeEmptyQueries)
12 {
13 urlObj.query.string.stripped = stringify(urlObj.query.object, true);
14 }
15}
16
17
18
19function stringify(queryObj, removeEmptyQueries)
20{
21 var count = 0;
22 var str = "";
23
24 for (var i in queryObj)
25 {
26 if ( i!=="" && hasOwnProperty.call(queryObj, i)===true )
27 {
28 var value = queryObj[i];
29
30 if (value !== "" || !removeEmptyQueries)
31 {
32 str += (++count===1) ? "?" : "&";
33
34 i = encodeURIComponent(i);
35
36 if (value !== "")
37 {
38 str += i +"="+ encodeURIComponent(value).replace(/%20/g,"+");
39 }
40 else
41 {
42 str += i;
43 }
44 }
45 }
46 }
47
48 return str;
49}
50
51
52
53module.exports = parseQuery;
Note: See TracBrowser for help on using the repository browser.