PageSourceSearch

https://guendlischwand.ch/js/worldsoft/URLPathInfo.js?ts=1783871606

js guendlischwand.ch collected 2026-10-02 13:09:34 UTC 2,471 bytes, 73 lines download raw bytes

1// This snippet came from http://stackoverflow.com/questions/6941533/get-protocol-domain-and-port-from-url
2// If was converted into a class to make sure that there is no conflicts with other functions.
3
4var URLPathInfo = {
5	
6	
7
8/**
9 *  Break apart any path into parts
10 *  'http://example.com:12345/blog/foo/bar?startIndex=1&pageSize=10' ->
11 *    {
12 *      "host": "example.com",
13 *      "port": "12345",
14 *      "search": {
15 *        "startIndex": "1",
16 *        "pageSize": "10"
17 *      },
18 *      "path": "/blog/foo/bar",
19 *      "protocol": "http:"
20 *    }
21 */
22	getPathInfo: function (path) {
23	    //  create a link in the DOM and set its href
24	    var link = document.createElement('a');
25	    link.setAttribute('href', path);
26
27	    //  return an easy-to-use object that breaks apart the path
28	    return {
29	        host:     link.hostname,  //  'example.com'
30	        port:     link.port,      //  12345
31	        search:   URLPathInfo.processSearchParams(link.search),  //  {startIndex: 1, pageSize: 10}
32	        path:     link.pathname,  //  '/blog/foo/bar'
33	        protocol: link.protocol   //  'http:'
34	    }
35	},
36
37
38/**
39 *  Convert search param string into an object or array
40 *  '?startIndex=1&pageSize=10' -> {startIndex: 1, pageSize: 10}
41 */
42	processSearchParams: function (search, preserveDuplicates) {
43		// return blank if nothing is in the search 
44		if(!search) return '';
45		
46	    //  option to preserve duplicate keys (e.g. 'sort=name&sort=age')
47	    preserveDuplicates = preserveDuplicates || false;  //  disabled by default
48
49	    var outputNoDupes = {};
50	    var outputWithDupes = [];  //  optional output array to preserve duplicate keys
51
52	    //  sanity check
53	    if(!search) throw new Error('processSearchParams: expecting "search" input parameter');
54
55	    //  remove ? separator (?foo=1&bar=2 -> 'foo=1&bar=2')
56	    search = search.split('?')[1];
57
58	    //  split apart keys into an array ('foo=1&bar=2' -> ['foo=1', 'bar=2'])
59	    search = search.split('&');
60
61	    //  separate keys from values (['foo=1', 'bar=2'] -> [{foo:1}, {bar:2}])
62	    //  also construct simplified outputObj
63	    outputWithDupes = search.map(function(keyval){
64	        var out = {};
65	        keyval = keyval.split('=');
66	        out[keyval[0]] = keyval[1];
67	        outputNoDupes[keyval[0]] = keyval[1]; //  might as well do the no-dupe work too while we're in the loop
68	        return out;
69	    });
70
71	    return (preserveDuplicates) ? outputWithDupes : outputNoDupes;
72	}
73};

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.