Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parse-url

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-url - npm Package Compare versions

Comparing version 0.2.0 to 1.0.0

.npmignore

46

example/index.js

@@ -5,2 +5,46 @@ // Dependencies

console.log(ParseUrl("http://ionicabizau.net/blog"));
console.log(ParseUrl("http://ionicabizau.net/blog"));
// => {
// protocols: [ "http" ]
// , port: null
// , resource: "ionicabizau.net"
// , user: ""
// , pathname: "/blog"
// , hash: ""
// , search: ""
// , href: "http://ionicabizau.net/blog"
// }
console.log(ParseUrl("http://domain.com/path/name?foo=bar&bar=42#some-hash"));
// => {
// protocols: ["http"]
// , port: null
// , resource: "domain.com"
// , user: ""
// , pathname: "/path/name"
// , hash: "some-hash"
// , search: "foo=bar&bar=42"
// , href: "http://domain.com/path/name?foo=bar&bar=42#some-hash"
// }
console.log(ParseUrl("git+ssh://git@host.xz/path/name.git"));
// => {
// protocols: ["git", "ssh"]
// , port: null
// , resource: "host.xz"
// , user: "git"
// , pathname: "/path/name.git"
// , hash: ""
// , search: ""
// }
console.log(ParseUrl("git@github.com:IonicaBizau/git-stats.git"));
// => {
// protocols: []
// , port: null
// , resource: "github.com"
// , user: "git"
// , pathname: "/IonicaBizau/git-stats.git"
// , hash: ""
// , search: ""
// , href: "git@github.com:IonicaBizau/git-stats.git"
// }

@@ -12,2 +12,11 @@ // Dependencies

* @return {Object} An object containing the following fields:
*
* - `protocols` (Array): An array with the url protocols (usually it has one element).
* - `port` (null|Number): The domain port.
* - `resource` (String): The url domain (including subdomains).
* - `user` (String): The authentication user (usually for ssh urls).
* - `pathname` (String): The url pathname.
* - `hash` (String): The url hash.
* - `search` (String): The url querystring value.
* - `href` (String): The input url.
*/

@@ -21,3 +30,5 @@ function ParseUrl(url) {

, pathname: ""
, token: ""
, hash: ""
, search: ""
, href: url
}

@@ -37,2 +48,3 @@ , protocolIndex = url.indexOf("://")

// user@domain
splits = output.resource.split("@");

@@ -43,18 +55,38 @@ if (splits.length === 2) {

}
// domain.com:port
splits = output.resource.split(":");
if (splits.length === 2 && splits[1]) {
if (splits.length === 2) {
output.resource = splits[0];
output.port = isNaN(splits[1]) ? splits[1] : parseInt(splits[1]);
output.port = parseInt(splits[1]);
if (isNaN(output.port)) {
output.port = null;
parts.unshift(splits[1]);
}
}
splits = output.user.split(":");
if (splits.length === 2 && splits[1] === "x-oauth-basic") {
output.token = splits[0];
}
// Remove empty elements
parts = parts.filter(Boolean);
parts = parts.filter(Boolean);
// Stringify the pathname
output.pathname = "/" + parts.join("/");
// #some-hash
splits = output.pathname.split("#");
if (splits.length === 2) {
output.pathname = splits[0];
output.hash = splits[1];
}
// ?foo=bar
splits = output.pathname.split("?");
if (splits.length === 2) {
output.pathname = splits[0];
output.search = splits[1];
}
return output;
}
module.exports = ParseUrl;

15

package.json
{
"name": "parse-url",
"version": "0.2.0",
"version": "1.0.0",
"description": "An advanced url parser supporting git urls too.",
"main": "lib/index.js",
"directories": {
"example": "example"
"example": "example",
"test": "test"
},

@@ -28,3 +29,9 @@ "scripts": {

},
"homepage": "https://github.com/IonicaBizau/node-parse-url"
}
"homepage": "https://github.com/IonicaBizau/node-parse-url",
"dependencies": {
"protocols": "^1.1.0"
},
"devDependencies": {
"mocha": "^2.2.5"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc