{"_id":"relative-url","_rev":"4665428","name":"relative-url","description":"convert a partial url into an absolute url from your current location.","dist-tags":{"latest":"1.0.2"},"maintainers":[{"name":"nopersonsmodules","email":"nopersonsmodules@gmail.com"}],"time":{"modified":"2026-04-10T22:38:02.000Z","created":"2016-06-01T21:29:14.450Z","1.0.2":"2016-06-08T23:08:43.512Z","1.0.1":"2016-06-01T22:41:13.023Z","1.0.0":"2016-06-01T21:29:14.450Z"},"users":{},"author":{"name":"'Dominic Tarr'","email":"dominic.tarr@gmail.com","url":"dominictarr.com"},"repository":{"type":"git","url":"git://github.com/dominictarr/relative-url.git"},"versions":{"1.0.2":{"name":"relative-url","description":"convert a partial url into an absolute url from your current location.","version":"1.0.2","homepage":"https://github.com/dominictarr/relative-url","repository":{"type":"git","url":"git://github.com/dominictarr/relative-url.git"},"dependencies":{},"devDependencies":{"tape":"^4.5.1"},"scripts":{"test":"set -e; for t in test/*.js; do node $t; done"},"author":{"name":"'Dominic Tarr'","email":"dominic.tarr@gmail.com","url":"dominictarr.com"},"license":"MIT","gitHead":"1650c32adfd987a4edba68eb3748b55a83695981","bugs":{"url":"https://github.com/dominictarr/relative-url/issues"},"_id":"relative-url@1.0.2","_shasum":"d21c52a72d6061018bcee9f9c9fc106bf7d65287","_from":".","_npmVersion":"3.8.6","_nodeVersion":"5.11.1","_npmUser":{"name":"dominictarr","email":"dominic.tarr@gmail.com"},"dist":{"shasum":"d21c52a72d6061018bcee9f9c9fc106bf7d65287","size":3332,"noattachment":false,"key":"/relative-url/-/relative-url-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/relative-url/download/relative-url-1.0.2.tgz"},"maintainers":[{"name":"nopersonsmodules","email":"nopersonsmodules@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/relative-url-1.0.2.tgz_1465427322998_0.9249375476501882"},"directories":{},"publish_time":1465427323512,"_hasShrinkwrap":false,"_cnpm_publish_time":1465427323512,"_cnpmcore_publish_time":"2021-12-17T11:53:44.609Z"},"1.0.1":{"name":"relative-url","description":"convert a partial url into an absolute url from your current location.","version":"1.0.1","homepage":"https://github.com/dominictarr/relative-url","repository":{"type":"git","url":"git://github.com/dominictarr/relative-url.git"},"dependencies":{},"devDependencies":{"tape":"^4.5.1"},"scripts":{"test":"set -e; for t in test/*.js; do node $t; done"},"author":{"name":"'Dominic Tarr'","email":"dominic.tarr@gmail.com","url":"dominictarr.com"},"license":"MIT","gitHead":"4a1ad8e422bec6e3ebcacdefb665b1e9534a1d35","bugs":{"url":"https://github.com/dominictarr/relative-url/issues"},"_id":"relative-url@1.0.1","_shasum":"aacd618d6e149f9f327c34a6d2c7f3a1726e6bd9","_from":".","_npmVersion":"3.8.6","_nodeVersion":"5.11.1","_npmUser":{"name":"dominictarr","email":"dominic.tarr@gmail.com"},"dist":{"shasum":"aacd618d6e149f9f327c34a6d2c7f3a1726e6bd9","size":3303,"noattachment":false,"key":"/relative-url/-/relative-url-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/relative-url/download/relative-url-1.0.1.tgz"},"maintainers":[{"name":"nopersonsmodules","email":"nopersonsmodules@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/relative-url-1.0.1.tgz_1464820872553_0.9257475782651454"},"directories":{},"publish_time":1464820873023,"_hasShrinkwrap":false,"_cnpm_publish_time":1464820873023,"_cnpmcore_publish_time":"2021-12-17T11:53:44.831Z"},"1.0.0":{"name":"relative-url","description":"convert a partial url into an absolute url from your current location.","version":"1.0.0","homepage":"https://github.com/dominictarr/relative-url","repository":{"type":"git","url":"git://github.com/dominictarr/relative-url.git"},"dependencies":{},"devDependencies":{"tape":"^4.5.1"},"scripts":{"test":"set -e; for t in test/*.js; do node $t; done"},"author":{"name":"'Dominic Tarr'","email":"dominic.tarr@gmail.com","url":"dominictarr.com"},"license":"MIT","gitHead":"63089673c4b08c10dcd1aaedbe608e9c26d0fda4","bugs":{"url":"https://github.com/dominictarr/relative-url/issues"},"_id":"relative-url@1.0.0","_shasum":"68c680a090f1aaf8b700d9302bcdd0cfabf14013","_from":".","_npmVersion":"3.8.6","_nodeVersion":"5.11.1","_npmUser":{"name":"dominictarr","email":"dominic.tarr@gmail.com"},"dist":{"shasum":"68c680a090f1aaf8b700d9302bcdd0cfabf14013","size":3235,"noattachment":false,"key":"/relative-url/-/relative-url-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/relative-url/download/relative-url-1.0.0.tgz"},"maintainers":[{"name":"nopersonsmodules","email":"nopersonsmodules@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/relative-url-1.0.0.tgz_1464816554025_0.9791025393642485"},"directories":{},"publish_time":1464816554450,"_hasShrinkwrap":false,"_cnpm_publish_time":1464816554450,"_cnpmcore_publish_time":"2021-12-17T11:53:45.055Z"}},"readme":"# relative-url\n\nconvert a partial url into an absolute url from your current\nlocation.\n\nIn the WebSocket api, it expects a fully qualified url,\nbut this is awkward because we want to develop on localhost,\nand then deploy to a server with a proper domain,\nwith a different port.\n\nWe want to create a WebSocket at a path, and get whatever domain\nwe are on.\n\nThis module generalized [wsurl](https://www.npmjs.com/package/wsurl)\n\n## api: rurl(url, location, protocolMap, defaultProtocol)\n\n`url` is your partial url, it will be described below.\n`location` should be your is `window.location` or the output\nof `require('url').parse(absoluteUrl)`\n\nif you want to change the protocol, protocol map is a object\nmapping current to desired protocol.\n\nfor websockets, you'll probably want: `{http: 'ws', https: 'wss'}`\n\n`defaultProtocol` is what to set the protocol to otherwise.\nfor example, `'ws'` if `defaultProtocol` is not provided\nthe output protocol will the the same as `location.protocol`\n\n## examples\n\nfor the following location:\n``` js\nvar location = {\n  protocol: 'http',\n  host: 'server.com',\n  pathname '/foo'\n} //OR get this from window.location\n\nvar protocolMap = {http: 'ws', https: 'wss'}\n\nvar defaultProtocol : 'ws'\n\nvar rurl = require('relative-url')\nfunction relative (url) {\n  return rurl(url, location, protocolMap, defaultProtocol) \n}\n\n\n```\nand the above mentioned settings (suitable for websockets)\noutput will be as following.\n``` js\n\nrelative('/')            // => ws://server.com/\nrelative('/bar')         // => ws://server.com/bar\nrelative('//client.com') // => ws://client.com/\nrelative('//:9999')      // => ws://server.com:9999/\nrelative('?q=search'     // => ws://server.com/foo?q=search\n```\n\nnote that // denotes the start of the host.\nif you want to set the port without changing the domain,\nyou must still use // otherwise the url module will\nthink it's a path. I considered detecting that,\nbut then i saw [this comment](https://github.com/nodejs/node/blob/master/lib/url.js#L207-L220)\nand got scared of learning too much about urls.\n\n## License\n\nMIT\n\n\n\n\n\n\n\n\n\n\n\n\n\n","_attachments":{},"homepage":"https://github.com/dominictarr/relative-url","bugs":{"url":"https://github.com/dominictarr/relative-url/issues"},"license":"MIT"}